如何使用 coturn (stun/turn) 服务器在 Web 应用程序中建立对等连接 [英] How to establish peer connection in web app using coturn (stun/turn) server

查看:71
本文介绍了如何使用 coturn (stun/turn) 服务器在 Web 应用程序中建立对等连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个用于摄像头广播的网络应用程序.我将 Django 用于 Web 应用程序,并将 coturn 作为 (STUN/TURN) 信号服务器.我的目标是使用 WebRTC.

I'm building a web app for cam broadcasting. I'm using Django for web app and coturn as (STUN/TURN) signalling server. My goal is to do it with WebRTC.

我不知道如何将一个对等点连接到信令服务器以便其他对等点可以访问.所以我需要知道的是如何建立PeerConnection".在 web 应用程序中,我拥有我需要的一切(我认为):user.id、共享密钥、信令服务器 IP 和端口,......但我不知道如何将它混合在 HTML JS 脚本中以连接 coturn 服务器.

I don't know how to connect a peer to the signalling server in order to be reachable by other peer. So what I need to know is how to stablish "PeerConnection". In web application, I have all I need (I think): user.id, shared secret, signalling server IP and port, ... But I don't know how to mix it in HTML JS scripts to connect with coturn server.

我已经阅读了 coturn 服务器文档并搜索了一些示例,但找不到这部分的示例.

I've read coturn server docs and searched for some examples but can't find examples for this part.

谁能给我举个例子?

推荐答案

我觉得你有点糊涂了,coturn 不是信令服务器,它是一个 TURN/STUN 服务器.

I think you are bit confused, coturn is not a signalling server, it is a TURN/ STUN server.

信令服务器是一种在对等方获得直接对等连接之前在对等方之间交换 sdp、ice 候选和其他数据的东西,coturn 不这样做.

Signalling server is something though which you exchange sdp, ice candidates and other data between the peers before they get a direct peer to peer connection, coturn does not do that.

我无法解释所有的位,但要点是 STUN 用于提供对等方的公共 IP,而 TURN 用作代理点,用于在无法直接访问的对等方发送和接收数据时,在大多数情况下如果您需要的只是一个 STUN 服务器.他们参与您的 WebRTC 应用程序的唯一时间是当您创建 PeerConnection 对象时,您在配置对象中传递 STUN/TURN 服务器详细信息,例如:

I cannot explain all the bits, but gist is STUN is used for providing public IP of a peer, and TURN is used for a proxy point for transmitting and receving data from a peer when it cannot be directly accessed, and in most cases all you require is a STUN server. The only time they get involved in your WebRTC application is when you create the PeerConnection object, you pass the STUN/TURN server details in the config object, example:

let pc = new RTCPeerConnection({
  "iceServers": [
    {"urls": "stun:example.com"},  // STUN Server address
    {"urls": "turn:example.com", "credential": "test", "username": "test"}  // TURN Server address
  ] 
}); 

这篇关于如何使用 coturn (stun/turn) 服务器在 Web 应用程序中建立对等连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆