sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.39k stars 424 forks source link

Call SipServer with sipsorcery and answered call but automatically hungup. #1091

Open orhanyk opened 4 months ago

orhanyk commented 4 months ago

Using the Sip Sorcery library, I create a voice call on the sip server and answer this call. After a while, the call closes automatically. What could be the reason for this? Do I need any extra configuration?

`var rtpSession = CreateRtpSession(userAgent, null); var callResult = await userAgent.Call(DESTINATION, null, null, rtpSession);

if (callResult) { await rtpSession.Start(); //_calls.TryAdd(ua.Dialogue.CallId, ua); }`

`private static VoIPMediaSession CreateRtpSession(SIPUserAgent ua, string dst) { List codecs = new List { AudioCodecsEnum.PCMU, AudioCodecsEnum.PCMA };

var audioSource = AudioSourcesEnum.SineWave;
if (string.IsNullOrEmpty(dst) || !Enum.TryParse(dst, out audioSource))
{
    audioSource = AudioSourcesEnum.Music;
}

_log.Info($"RTP audio session source set to {audioSource}.");

AudioExtrasSource audioExtrasSource = new AudioExtrasSource(new AudioEncoder(), new AudioSourceOptions { AudioSource = audioSource });
audioExtrasSource.RestrictFormats(formats => codecs.Contains(formats.Codec));
var rtpAudioSession = new VoIPMediaSession(new MediaEndPoints { AudioSource = audioExtrasSource });
rtpAudioSession.AcceptRtpFromAny = true;

// 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.Info($"RTP timeout on call with {ua.Dialogue.RemoteTarget}, hanging up.");
    }
    else
    {
        _log.Info($"RTP timeout on incomplete call, closing RTP session.");
    }

    ua.Hangup();
};

return rtpAudioSession;

}`