SafeDispatch/SipComponent/SipClientClassLinx.cs

359 lines
11 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Net;
using System.Net.Sockets;
using SipComponent.Linx;
namespace SipComponent
{
/// <summary>
/// A implementation of the abstract SipClientClass, for Linx (as opose to Simoco)
/// </summary>
public class SipClientClassLinx : SipClientClass
{
#region Fields
private LinxSipMessageGenerator _sipMessageGenerator = new LinxSipMessageGenerator();
#endregion
/// <summary>
/// Gets or sets a value indicating if the Asterisk server confirms sms
/// <para>Default value is false</para>
/// </summary>
public bool SmsConfirmationFromServer
{
get { return base._smsConfirmationFromServer; }
set { base._smsConfirmationFromServer = value; }
}
// constructor
/// <summary>
/// Constructor for the SipClientClassLinx
/// </summary>
/// <param name="asteriskIP">domain name, name or IP address of sip server</param>
/// <param name="asteriskSipPort">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="password">password 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 SipClientClassLinx(string asteriskIP, int asteriskSipPort, int localSipPort, string userName, string password, int registrationInterval,
int bufferMiliseconds, int requestTimeout, string localIpAddress = null) :
base(asteriskIP, asteriskSipPort, localSipPort, userName, password, registrationInterval, bufferMiliseconds, requestTimeout, localIpAddress, false)
{
}
#region Public Methods
/// <summary>
/// Sends a Sip Invite command to an user
/// </summary>
/// <param name="idToInvite">The sip id of the user</param>
/// <param name="typeOfCall">Type of call: full duplex or half duplex</param>
public void SendInvite(string idToInvite, TypeOfCall typeOfCall)
{
base.Invite(idToInvite, typeOfCall);
}
/// <summary>
/// Method used to send Gps Request to a Linx device
/// </summary>
/// <param name="idToRequestGps">The sip id to send the gps request</param>
/// <param name="seqID">The sequence id</param>
public void SendGPSRequest(string idToRequestGps, string seqID)
{
base.SendLinxGpsRequest(idToRequestGps, seqID);
}
/// <summary>
/// Method used to acknowledge an emergency alarm sent by a Linx device
/// </summary>
/// <param name="linxID">The sip id of the Linx device</param>
public void AcknowledgeEmergencyAlarm(string linxID)
{
base.AcknowledgeLinxEmergencyAlarm(linxID);
}
/// <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 startAliveTimer, int bufferMiliseconds,
int sipIDinDialogWith, bool isGroupCall, TypeOfCall typeOfCall)
{
return new RTPListener2(udpClient, startAliveTimer, 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);
}
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 Linx device
/// </summary>
public event EventHandler<LinxGpsDataEventArgs> GpsReportReceived
{
add
{
lock (lockerGpsReportReceived)
{
base.LinxGpsReportReceived += value;
}
}
remove
{
lock (lockerGpsReportReceived)
{
base.LinxGpsReportReceived -= value;
}
}
}
private object lockerAlarmReceived = new object();
/// <summary>
/// Occurs when an emergency alarm is received from a Linx device
/// </summary>
public event EventHandler<LinxEmergencyAlarmReceivedEventArgs> EmergencyAlarmReceived
{
add
{
lock (lockerAlarmReceived)
{
base.LinxEmergencyAlarmReceived += value;
}
}
remove
{
lock (lockerAlarmReceived)
{
base.LinxEmergencyAlarmReceived -= 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;
}
}
}
private object lockerArsReceived = new object();
/// <summary>
/// Occurs when an Ars command is received from a Linx device
/// </summary>
public event EventHandler<Linx.ArsReceivedEventArgs> ArsReceived
{
add
{
lock (lockerArsReceived)
{
base.LinxArsReceived += value;
}
}
remove
{
lock (lockerArsReceived)
{
base.LinxArsReceived -= value;
}
}
}
#endregion
}
}