391 lines
12 KiB
C#
391 lines
12 KiB
C#
using SipComponent.Simoco;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SipComponent
|
|
{
|
|
/// <summary>
|
|
/// An implementation of the abstract class SipClientClass, used for Simoco
|
|
/// </summary>
|
|
public class SipClientClassSimoco : SipClientClass
|
|
{
|
|
|
|
#region Private Fields
|
|
|
|
private SimocoSipMessageGenerator _sipMessageGenerator = new SimocoSipMessageGenerator();
|
|
|
|
#endregion
|
|
|
|
// constructor
|
|
|
|
/// <summary>
|
|
/// Constructor for the SipClientClassSimoco
|
|
/// </summary>
|
|
/// <param name="aisGatewayIP">domain name, name or IP address of sip server</param>
|
|
/// <param name="aisGatewaySipPort">port number of the sip server</param>
|
|
/// <param name="localSipPort">port number of the local computer used for sip protocol</param>
|
|
/// <param name="userName">user name on the sip server</param>
|
|
/// <param name="registrationInterval">interval to send sip registration requests. Value is in seconds</param>
|
|
/// <param name="bufferMiliseconds">Miliseconds for the buffer that stores the received voice packets</param>
|
|
/// <param name="requestTimeout">Number of ms to wait before the sip request times out</param>
|
|
/// <param name="localIPAddress">Local Ip adress. If not specified, the class will search for a local ip on the same network with the sip server ip</param>
|
|
public SipClientClassSimoco(string aisGatewayIP, int aisGatewaySipPort, int localSipPort,
|
|
string userName, int registrationInterval, int bufferMiliseconds, int requestTimeout, string localIPAddress = null )
|
|
: base(aisGatewayIP, aisGatewaySipPort, localSipPort, userName, "", registrationInterval, bufferMiliseconds, requestTimeout, localIPAddress, true)
|
|
{
|
|
|
|
}
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Sends a Sip Invite command to a Simoco radio
|
|
/// </summary>
|
|
/// <param name="idToInvite">The sip id of the user</param>
|
|
public void Invite(string idToInvite)
|
|
{
|
|
base.Invite(idToInvite, TypeOfCall.HALF_DUPLEX);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a Sip Invite command to a Simoco Group
|
|
/// </summary>
|
|
/// <param name="groupIDtoInvite">The sip id of the group</param>
|
|
public new void InviteGroup(string groupIDtoInvite)
|
|
{
|
|
base.InviteGroup(groupIDtoInvite);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method used to send a Ping command to a Simoco radio
|
|
/// </summary>
|
|
/// <param name="idToSendPing">The Simoco ID of the radio</param>
|
|
public virtual void SendPing(string idToSendPing)
|
|
{
|
|
base.SendSimocoPing(idToSendPing);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method used to acknowledge a Simoco emergency status report
|
|
/// </summary>
|
|
/// <param name="simocoID">The id of the Simoco radio</param>
|
|
public void AcknowledgeEmergencyStatusReport(string simocoID)
|
|
{
|
|
base.AcknowledgeSimocoEmergencyStatusReport(simocoID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register the Sip class to a simoco group id
|
|
/// </summary>
|
|
/// <param name="simocoGroupID">id of the simoco group</param>
|
|
public void RegisterToGroup(string simocoGroupID)
|
|
{
|
|
base.RegisterToSimocoGroup(simocoGroupID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method used to start sending PTT Requests to a sip id
|
|
/// </summary>
|
|
/// <param name="sipID">The sip ID to send PTT Requests</param>
|
|
public new void RequestPTT(string sipID)
|
|
{
|
|
base.RequestPTT(sipID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method used to check if you received PTT Grant from the specified user
|
|
/// </summary>
|
|
/// <param name="sipIDinDialogWith">The sip id of the user</param>
|
|
/// <returns>True if you received ptt Grant, else false</returns>
|
|
public new bool PTTGrantReceived(string sipIDinDialogWith)
|
|
{
|
|
return base.PTTGrantReceived(sipIDinDialogWith);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method used to send End PTT to a sip id
|
|
/// </summary>
|
|
/// <param name="sipID">The sip id to send End PTT</param>
|
|
public new void EndPTT(string sipID)
|
|
{
|
|
base.EndPTT(sipID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Accepts a PTT Request from an user
|
|
/// </summary>
|
|
/// <param name="idToGrantPTT">The sip ID of the user</param>
|
|
public new void GrantPTT(string idToGrantPTT)
|
|
{
|
|
base.GrantPTT(idToGrantPTT);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method used to send Deny when you receive a PTT Request
|
|
/// </summary>
|
|
/// <param name="idToDenyPTT">The sip ID sending PTT Request</param>
|
|
public new void DenyPTT(string idToDenyPTT)
|
|
{
|
|
base.DenyPTT(idToDenyPTT);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Abstract Implementation
|
|
|
|
internal override RTPListener2 CreateRTPListener(UdpClient udpClient, bool initiatedByMe, int _bufferMiliseconds, int sipIdInDialogWith,
|
|
bool isGroupCall, TypeOfCall typeOfCall)
|
|
{
|
|
return new RTPListenerSimoco(udpClient, initiatedByMe, _bufferMiliseconds, sipIdInDialogWith, isGroupCall, typeOfCall);
|
|
}
|
|
|
|
internal override RTPSender2 CreateRTPSender(UdpClient udpClient, int audioBitrate, IPEndPoint iPEndPoint, int v1, int v2, bool initiatedByMe, TypeOfCall typeOfCall,
|
|
RtpCallType halfDuplexCallType = RtpCallType.Private)
|
|
{
|
|
return new RTPSender2(udpClient, audioBitrate, iPEndPoint, v1, v2, initiatedByMe, typeOfCall, halfDuplexCallType);
|
|
}
|
|
|
|
internal override SipMessageGenerator SipMessageGenerator
|
|
{
|
|
get
|
|
{
|
|
return _sipMessageGenerator;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
private object _lockerGpsReportReceived = new object();
|
|
/// <summary>
|
|
/// Occurs when a GPS report is received from a Simoco radio
|
|
/// </summary>
|
|
public event EventHandler<GpsDataEventArgs> GpsReportReceived
|
|
{
|
|
add
|
|
{
|
|
lock (_lockerGpsReportReceived)
|
|
{
|
|
base.SimocoGpsReportReceived += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (_lockerGpsReportReceived)
|
|
{
|
|
base.SimocoGpsReportReceived -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object _lockerPingResponseReceived = new object();
|
|
/// <summary>
|
|
/// Occurs when a Simoco radio responds to a ping request
|
|
/// </summary>
|
|
public event EventHandler<SipEventArgs> PingResponseReceived
|
|
{
|
|
add
|
|
{
|
|
lock (_lockerPingResponseReceived)
|
|
{
|
|
base.SimocoPingResponseReceived += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (_lockerPingResponseReceived)
|
|
{
|
|
base.SimocoPingResponseReceived -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object _lockerPingRequestFailed = new object();
|
|
/// <summary>
|
|
/// Occurs when a Simoco radio fails to respond to a ping request
|
|
/// </summary>
|
|
public event EventHandler<SipEventArgs> PingRequestFailed
|
|
{
|
|
add
|
|
{
|
|
lock (_lockerPingRequestFailed)
|
|
{
|
|
base.SimocoPingRequestFailed += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (_lockerPingRequestFailed)
|
|
{
|
|
base.SimocoPingRequestFailed -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private object _lockerStatusReportReceived = new object();
|
|
/// <summary>
|
|
/// Occurs when a Simoco radio sends a status report
|
|
/// </summary>
|
|
public event EventHandler<SimocoDeviceStatusReportEventArgs> StatusReportReceived
|
|
{
|
|
add
|
|
{
|
|
lock (_lockerStatusReportReceived)
|
|
{
|
|
base.SimocoStatusReportReceived += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (_lockerStatusReportReceived)
|
|
{
|
|
base.SimocoStatusReportReceived -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object lockerPttRequestReceived = new object();
|
|
/// <summary>
|
|
/// Occurs when you receive a PTT request
|
|
/// </summary>
|
|
public new event EventHandler<PTTrequestEventArgs> PTTrequestReceived
|
|
{
|
|
add
|
|
{
|
|
lock (lockerPttRequestReceived)
|
|
{
|
|
base.PTTrequestReceived += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (lockerPttRequestReceived)
|
|
{
|
|
base.PTTrequestReceived -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private object lockerPTTrequestFailed = new object();
|
|
/// <summary>
|
|
/// Ocurs when you send the maximum number of PTT requests and you do not receive an answer
|
|
/// </summary>
|
|
public new event EventHandler<SipEventArgs> PTTrequestFailed
|
|
{
|
|
add
|
|
{
|
|
lock (lockerPTTrequestFailed)
|
|
{
|
|
base.PTTrequestFailed += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (lockerPTTrequestFailed)
|
|
{
|
|
base.PTTrequestFailed -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object lockerPTTrequestGranted = new object();
|
|
/// <summary>
|
|
/// Occurs when your PTT request is accepted
|
|
/// </summary>
|
|
public new event EventHandler<SipInfoEventArgs> PTTrequestGranted
|
|
{
|
|
add
|
|
{
|
|
lock (lockerPTTrequestGranted)
|
|
{
|
|
base.PTTrequestGranted += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (lockerPTTrequestGranted)
|
|
{
|
|
base.PTTrequestGranted -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object lockerPTTrequestDenied = new object();
|
|
/// <summary>
|
|
/// Ocurs when your PTT request is denied
|
|
/// </summary>
|
|
public new event EventHandler<SipEventArgs> PTTrequestDenied
|
|
{
|
|
add
|
|
{
|
|
lock (lockerPTTrequestDenied)
|
|
{
|
|
base.PTTrequestDenied += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (lockerPTTrequestDenied)
|
|
{
|
|
base.PTTrequestDenied -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object lockerPTTStartReceived = new object();
|
|
/// <summary>
|
|
/// Occurs when you receive a PTT Start packet
|
|
/// </summary>
|
|
public new event EventHandler<RtpEventArgs> PTTStartReceived
|
|
{
|
|
add
|
|
{
|
|
lock (lockerPTTStartReceived)
|
|
{
|
|
base.PTTStartReceived += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (lockerPTTStartReceived)
|
|
{
|
|
base.PTTStartReceived -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object lockerPTTEndReceived = new object();
|
|
/// <summary>
|
|
/// Occurs when you receive a PTT End packet
|
|
/// </summary>
|
|
public new event EventHandler<RtpEventArgs> PTTEndReceived
|
|
{
|
|
add
|
|
{
|
|
lock (lockerPTTEndReceived)
|
|
{
|
|
base.PTTEndReceived += value;
|
|
}
|
|
}
|
|
remove
|
|
{
|
|
lock (lockerPTTEndReceived)
|
|
{
|
|
base.PTTEndReceived -= value;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|