在Unity端使用SIPSorcery进行通讯的总结

这里写自定义目录标题

业务需求

业务需求是与一款安全帽设备进行SIP连接,搭建语音通道。

SIPSorcery SDK

可以在GitHub上找到,里面有案例和文档

流程和代码

流程如下:
UserClientAgent发起会话,等待目标设备Answer。收到OK后,通道建立。按服务端要求,定期回复心跳协议,发送心跳消息。

发起绘画需要构造request消息,要点如下:
1、构造URI
sip:目标设备ID@SIP服务器地址:SIP服务器端口;其他信息
session-expires用来保活sip连接,服务器会默认session-expires这个参数为120s,我们web端采用的是3600s

 SIPURI callUri = SIPURI.ParseSIPURI("sip:" + phoneNum + "@" +sipServer + ":" + sipPort + ";transport=tcp;session-expires=3600");

2、构造SIPTransport

      var sipTransport = new SIPTransport();
        sipTransport.PreferIPv6NameResolution = true;
        sipTransport.EnableTraceLogs();

3、构造MediaSession用来处理音视频流数据

        var audioSession = new WindowsAudioEndPoint(new AudioEncoder());
        audioSession.RestrictFormats(x => x.Codec == AudioCodecsEnum.PCMA || x.Codec == AudioCodecsEnum.PCMU);
        //audioSession.RestrictFormats(x => x.Codec == AudioCodecsEnum.G722);
        rtpSession = new VoIPMediaSession(audioSession.ToMediaEndPoints());

        var offerSDP = rtpSession.CreateOffer(IPAddress.Any);

4、构造请求描述

        // Start the thread that places the call.
        SIPCallDescriptor callDescriptor = new SIPCallDescriptor(
            sipAccount,
            sipPwd,
            callUri.ToString(),
            "sip:" + sipAccount + "@" + sipServer + ";transport=tcp",
            callUri.ToString(),
            sipServer, null,
             sipAccount,
            SIPCallDirection.Out,
            SDP.SDP_MIME_CONTENTTYPE,
            offerSDP.ToString(),
            null
          )

        {
    AccountCode = HelmetMgr.Instance().sipAccount };

5、构造UserClientAgent并发起Call

        //ManualResetEvent exitMre = new ManualResetEvent(false);
        bool isCallHungup = false;
        bool hasCallFailed 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值