/// <summary> /// Example of how to create a basic RTP session object and hook up the event handlers. /// </summary> /// <param name="ua">The user agent the RTP session is being created for.</param> /// <param name="dst">THe destination specified on an incoming call. Can be used to /// set the audio source.</param> /// <returns>A new RTP session object.</returns> private static AudioSendOnlyMediaSession CreateRtpSession() { var rtpAudioSession = new AudioSendOnlyMediaSession(); // Wire up the event handler for RTP packets received from the remote party. //rtpAudioSession.OnRtpPacketReceived += OnRtpPacketReceived; rtpAudioSession.OnRtcpBye += (reason) => Log.LogDebug($"RTCP BYE received."); rtpAudioSession.OnRtpClosed += (reason) => Log.LogDebug("RTP session closed."); //rtpAudioSession.OnReceiveReport += RtpSession_OnReceiveReport; //rtpAudioSession.OnSendReport += RtpSession_OnSendReport; //rtpAudioSession.OnTimeout += (mediaType) => //{ // if (ua?.Dialogue != null) // { // Log.LogWarning($"RTP timeout on call with {ua.Dialogue.RemoteTarget}, hanging up."); // } // else // { // Log.LogWarning($"RTP timeout on incomplete call, closing RTP session."); // } // ua.Hangup(); //}; return(rtpAudioSession); }
/// <summary> /// Example of how to create a basic RTP session object and hook up the event handlers. /// </summary> /// <param name="ua">The user agent the RTP session is being created for.</param> /// <param name="dst">THe destination specified on an incoming call. Can be used to /// set the audio source.</param> /// <returns>A new RTP session object.</returns> private static AudioSendOnlyMediaSession CreateRtpSession(SIPUserAgent ua) { var rtpAudioSession = new AudioSendOnlyMediaSession(); // Wire up the event handler for RTP packets received from the remote party. rtpAudioSession.OnRtpPacketReceived += (ep, type, rtp) => OnRtpPacketReceived(ua, type, rtp); rtpAudioSession.OnTimeout += (mediaType) => { if (ua?.Dialogue != null) { Log.LogWarning($"RTP timeout on call with {ua.Dialogue.RemoteTarget}, hanging up."); } else { Log.LogWarning($"RTP timeout on incomplete call, closing RTP session."); } ua.Hangup(); }; return(rtpAudioSession); }
static void Main() { Console.WriteLine("SIPSorcery On Hold Demo: Callee"); Console.WriteLine("Waiting for incoming call from Caller."); Console.WriteLine("Press 'q' or ctrl-c to exit."); // Plumbing code to facilitate a graceful exit. CancellationTokenSource exitCts = new CancellationTokenSource(); // Cancellation token to stop the SIP transport and RTP stream. AddConsoleLogger(); // Set up a default SIP transport. _sipTransport = new SIPTransport(); _sipTransport.AddSIPChannel(new SIPUDPChannel(new IPEndPoint(IPAddress.Any, SIP_LISTEN_PORT))); EnableTraceLogs(_sipTransport); var userAgent = new SIPUserAgent(_sipTransport, null); userAgent.ServerCallCancelled += (uas) => Log.LogDebug("Incoming call cancelled by remote party."); userAgent.OnCallHungup += (dialog) => Log.LogDebug("Call hungup by remote party."); userAgent.RemotePutOnHold += () => Log.LogDebug("Remote party placed call on hold."); userAgent.RemoteTookOffHold += () => Log.LogDebug("Remote party took call off hold."); userAgent.OnIncomingCall += async(ua, req) => { var rtpAudioSession = new AudioSendOnlyMediaSession(null, _rtpPort); _rtpPort += 2; rtpAudioSession.OnReceiveReport += RtpSession_OnReceiveReport; //rtpAudioSession.OnSendReport += RtpSession_OnSendReport; var uas = ua.AcceptCall(req); bool answerResult = await ua.Answer(uas, rtpAudioSession); Log.LogDebug($"Answer incoming call result {answerResult}."); _ = Task.Run(async() => { await Task.Delay(1000); Log.LogDebug($"Sending DTMF sequence {string.Join("", DTMF_SEQUENCEFOR_TRANSFEROR.Select(x => x))}."); foreach (byte dtmf in DTMF_SEQUENCEFOR_TRANSFEROR) { Log.LogDebug($"Sending DTMF tone to transferor {dtmf}."); await ua.SendDtmf(dtmf); } }); }; Task.Run(() => OnKeyPress(userAgent, exitCts)); exitCts.Token.WaitHandle.WaitOne(); #region Cleanup. Log.LogInformation("Exiting..."); //userAgent?.Hangup(); // Give any BYE or CANCEL requests time to be transmitted. Log.LogInformation("Waiting 1s for calls to be cleaned up..."); Task.Delay(1000).Wait(); if (_sipTransport != null) { Log.LogInformation("Shutting down SIP transport..."); _sipTransport.Shutdown(); } #endregion }