首页 > 解决方案 > 如何在 sipJS 中更改 STUN 服务器

问题描述

我在这里陷入困境,我搜索了 API 参考、谷歌和 stackoverflow,但找不到我正在寻找的答案。

如何更改在 sipJS-0.19 中使用的 stun 服务器

在早期版本的 sipJS 和 JsSip 中,我可以这样做

var callOptions = {
    mediaConstraints: {
      audio: true,
      video: true
    },
    pcConfig: {
        iceServers: [
            { urls: ["stun:my.stun.server.com"] }
        ],
        iceTransportPolicy: "all"
    }
  };

我已经在最新的 sipJS 中尝试过这个

sessionDescriptionHandlerOptions: {
            constraints: { audio: true, video: false },
                peerConnectionConfiguration: {
                    iceServers: [{
                        urls:"stun:my.stun.server.com"
                    }],
                    'iceTransportPolicy': "all"
                }
            }
        });

这仍然在控制台中显示默认的眩晕。

iceServers:[{urls:"stun:stun.l.google.com:19302"}],iceTransportPolicy:"all"

我尝试将peerConnectionConfiguration更改为rtcConfiguration

或者把它加到userAgentOptions,还是一样的结果。

标签: javascriptwebrtcsipstun

解决方案


根据当前 sip.js 的当前版本(0.20.0),这可以通过UserAgentOptions.sessionDescriptionHandlerFactoryOptions.peerConnectionConfiguration选项来实现。

选项的完整架构是:

bundlePolicy: "balanced", // Note: max-bundle is not supported by the demo backend currently (5/15/17)
certificates: undefined,
iceCandidatePoolSize: 0,
iceServers: [{ urls: "stun:stun.l.google.com:19302" }], // TURN URL example: "turn:88.88.88.0:3478", "test", "test"
iceTransportPolicy: "all",
peerIdentity: undefined,
rtcpMuxPolicy: "require"

因此,要为您的 UserAgent 关闭 ice 服务器,只需添加

var agent = new UserAgent({
   //... other options
   sessionDescriptionHandlerFactoryOptions: {
      iceGatheringTimeout: 500, //currently, the smallest allowed value
      peerConnectionConfiguration: {
        iceServers: []
      }
    }
});

要确认这一点,请获取一个“已建立”(Invitation.state) 邀请对象(来自来电),然后查看该sessionDescriptionHandler.sessionDescriptionHandlerConfiguration.peerConnectionConfiguration.iceServers值,您应该会看到上面设置的空列表。


推荐阅读