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
{
///
/// An implementation of the abstract class SipClientClass, used for Simoco
///
public class SipClientClassSimoco : SipClientClass
{
#region Private Fields
private SimocoSipMessageGenerator _sipMessageGenerator = new SimocoSipMessageGenerator();
#endregion
// constructor
///
/// Constructor for the SipClientClassSimoco
///
/// domain name, name or IP address of sip server
/// port number of the sip server
/// port number of the local computer used for sip protocol
/// user name on the sip server
/// interval to send sip registration requests. Value is in seconds
/// Miliseconds for the buffer that stores the received voice packets
/// Number of ms to wait before the sip request times out
/// Local Ip adress. If not specified, the class will search for a local ip on the same network with the sip server ip
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
///
/// Sends a Sip Invite command to a Simoco radio
///
/// The sip id of the user
public void Invite(string idToInvite)
{
base.Invite(idToInvite, TypeOfCall.HALF_DUPLEX);
}
///
/// Sends a Sip Invite command to a Simoco Group
///
/// The sip id of the group
public new void InviteGroup(string groupIDtoInvite)
{
base.InviteGroup(groupIDtoInvite);
}
///
/// Method used to send a Ping command to a Simoco radio
///
/// The Simoco ID of the radio
public virtual void SendPing(string idToSendPing)
{
base.SendSimocoPing(idToSendPing);
}
///
/// Method used to acknowledge a Simoco emergency status report
///
/// The id of the Simoco radio
public void AcknowledgeEmergencyStatusReport(string simocoID)
{
base.AcknowledgeSimocoEmergencyStatusReport(simocoID);
}
///
/// Register the Sip class to a simoco group id
///
/// id of the simoco group
public void RegisterToGroup(string simocoGroupID)
{
base.RegisterToSimocoGroup(simocoGroupID);
}
///
/// Method used to start sending PTT Requests to a sip id
///
/// The sip ID to send PTT Requests
public new void RequestPTT(string sipID)
{
base.RequestPTT(sipID);
}
///
/// Method used to check if you received PTT Grant from the specified user
///
/// The sip id of the user
/// True if you received ptt Grant, else false
public new bool PTTGrantReceived(string sipIDinDialogWith)
{
return base.PTTGrantReceived(sipIDinDialogWith);
}
///
/// Method used to send End PTT to a sip id
///
/// The sip id to send End PTT
public new void EndPTT(string sipID)
{
base.EndPTT(sipID);
}
///
/// Accepts a PTT Request from an user
///
/// The sip ID of the user
public new void GrantPTT(string idToGrantPTT)
{
base.GrantPTT(idToGrantPTT);
}
///
/// Method used to send Deny when you receive a PTT Request
///
/// The sip ID sending PTT Request
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();
///
/// Occurs when a GPS report is received from a Simoco radio
///
public event EventHandler GpsReportReceived
{
add
{
lock (_lockerGpsReportReceived)
{
base.SimocoGpsReportReceived += value;
}
}
remove
{
lock (_lockerGpsReportReceived)
{
base.SimocoGpsReportReceived -= value;
}
}
}
private object _lockerPingResponseReceived = new object();
///
/// Occurs when a Simoco radio responds to a ping request
///
public event EventHandler PingResponseReceived
{
add
{
lock (_lockerPingResponseReceived)
{
base.SimocoPingResponseReceived += value;
}
}
remove
{
lock (_lockerPingResponseReceived)
{
base.SimocoPingResponseReceived -= value;
}
}
}
private object _lockerPingRequestFailed = new object();
///
/// Occurs when a Simoco radio fails to respond to a ping request
///
public event EventHandler PingRequestFailed
{
add
{
lock (_lockerPingRequestFailed)
{
base.SimocoPingRequestFailed += value;
}
}
remove
{
lock (_lockerPingRequestFailed)
{
base.SimocoPingRequestFailed -= value;
}
}
}
private object _lockerStatusReportReceived = new object();
///
/// Occurs when a Simoco radio sends a status report
///
public event EventHandler StatusReportReceived
{
add
{
lock (_lockerStatusReportReceived)
{
base.SimocoStatusReportReceived += value;
}
}
remove
{
lock (_lockerStatusReportReceived)
{
base.SimocoStatusReportReceived -= value;
}
}
}
private object lockerPttRequestReceived = new object();
///
/// Occurs when you receive a PTT request
///
public new event EventHandler PTTrequestReceived
{
add
{
lock (lockerPttRequestReceived)
{
base.PTTrequestReceived += value;
}
}
remove
{
lock (lockerPttRequestReceived)
{
base.PTTrequestReceived -= value;
}
}
}
private object lockerPTTrequestFailed = new object();
///
/// Ocurs when you send the maximum number of PTT requests and you do not receive an answer
///
public new event EventHandler PTTrequestFailed
{
add
{
lock (lockerPTTrequestFailed)
{
base.PTTrequestFailed += value;
}
}
remove
{
lock (lockerPTTrequestFailed)
{
base.PTTrequestFailed -= value;
}
}
}
private object lockerPTTrequestGranted = new object();
///
/// Occurs when your PTT request is accepted
///
public new event EventHandler PTTrequestGranted
{
add
{
lock (lockerPTTrequestGranted)
{
base.PTTrequestGranted += value;
}
}
remove
{
lock (lockerPTTrequestGranted)
{
base.PTTrequestGranted -= value;
}
}
}
private object lockerPTTrequestDenied = new object();
///
/// Ocurs when your PTT request is denied
///
public new event EventHandler PTTrequestDenied
{
add
{
lock (lockerPTTrequestDenied)
{
base.PTTrequestDenied += value;
}
}
remove
{
lock (lockerPTTrequestDenied)
{
base.PTTrequestDenied -= value;
}
}
}
private object lockerPTTStartReceived = new object();
///
/// Occurs when you receive a PTT Start packet
///
public new event EventHandler PTTStartReceived
{
add
{
lock (lockerPTTStartReceived)
{
base.PTTStartReceived += value;
}
}
remove
{
lock (lockerPTTStartReceived)
{
base.PTTStartReceived -= value;
}
}
}
private object lockerPTTEndReceived = new object();
///
/// Occurs when you receive a PTT End packet
///
public new event EventHandler PTTEndReceived
{
add
{
lock (lockerPTTEndReceived)
{
base.PTTEndReceived += value;
}
}
remove
{
lock (lockerPTTEndReceived)
{
base.PTTEndReceived -= value;
}
}
}
#endregion
}
}