如何使用Coturn和oAuth配置WebRTC

lef*_*loh 8 oauth stun webrtc rfc5766turnserver turn

我想和oAuth一起使用coturn.如果我理解正确,我需要做两件事:

  • 在数据库中存储oAuth令牌可以使用
  • 发送ACCESS-TOKENUSERNAMESTUN属性

第一点很清楚,但我如何更改我的WebRTC客户端以实现第二点?

没有oAuth,我会RTCPeerConnection像这样初始化我:

var configuration = {
  'iceServers': [{
    'url': 'turn:turn.example.org',
    'username': 'user',
    'credential': 'password'
  }]
};
var pc = new RTCPeerConnection(configuration)
Run Code Online (Sandbox Code Playgroud)

的WebRTC 1.0草案定义了一个RTCIceCredentialType枚举所以,我觉得我需要改变这样的我的配置:

var configuration = {
  'iceServers': [{
    'url': 'turn:turn.example.org',
    'username': 'kid',
    'credential': 'oAuthToken',
    'credentialType': 'token'
  }]
};
Run Code Online (Sandbox Code Playgroud)

使用Wireshark我看不到ACESS-TOKEN属性.任何想法或有谁知道一个工作的例子?

fir*_*iku 1

自从提出最初的问题以来,事情似乎发生了一些变化。webrtc -pc#1033 pull-request 改变了规范并引入了以下iceServers配置语法:

var configuration = {
    'iceServers': [{
        "urls": "turns:turn.example.net",
        "username": "username",
        "credential": {
            "macKey": "...",
            "accessToken": "..."
        },
        "credentialType": "oauth"
    }],
    ...
}
Run Code Online (Sandbox Code Playgroud)

有关更多配置示例,请参阅RTCIceServer文档页面。