简体   繁体   English

在WEBRTC中使用用户ID

[英]Using user ID with WEBRTC

I'm trying to develop a WEBRTC videochat on a website. 我正在尝试在网站上开发WEBRTC视频聊天。 I've already create my database with users and their unique ID but I'm a little confused to how I can use this ID to connect clients with PeerConnection. 我已经用用户及其唯一的ID创建了数据库,但是我对如何使用此ID连接与PeerConnection的客户端有些困惑。 I've already read this http://www.html5rocks.com/en/tutorials/webrtc/basics/ and other documentation but I'm not understanding if i can use users' Id in some way in the remote/local description or I have to use other solutions like PeerJs? 我已经阅读了此http://www.html5rocks.com/zh-CN/tutorials/webrtc/basics/和其他文档,但是我不确定我是否可以在远程/本地描述中以某种方式使用用户ID或我必须使用其他解决方案,例如PeerJs?

Thanks. 谢谢。

You need to set up signalling yourself. 您需要自行设置信号 That means, you will need to provide a means for exchanging messages between both users. 这意味着,您将需要提供一种在两个用户之间交换消息的方法。 Just having an id doesn't help anyone in establishing a connection. 拥有ID并不能帮助任何人建立连接。 Both users need to be able to send a message to your server and the server needs to relay that message to the other user they're trying to connect to. 两个用户都必须能够将消息发送到您的服务器,并且服务器需要将该消息转发给他们尝试连接的其他用户。 You'll probably use the ids in some ways to decide whom to relay to exactly; 您可能会以某种方式使用ID来确定要准确中继给谁。 but that's a secondary implementation detail. 但这是次要的实现细节。

In practice a web socket connection between each user and your server works well. 实际上,每个用户与服务器之间的Web套接字连接都可以正常工作。 User A sends a message via web socket to your server, your server passes this message on to user B via web socket; 用户A通过Web套接字向您的服务器发送消息,您的服务器通过Web套接字将该消息传递给用户B; repeat that a couple of times until a direct connection has been negotiated. 重复几次,直到协商了直接连接。

In short, WebRTC does not specify the signalling channel (it is up to the developer), ie how users discover and know about each other. 简而言之,WebRTC不指定信令通道(取决于开发人员),即用户如何发现和了解彼此。

Some tutorials tend to skip the signalling entirely, which is a shame. 一些教程倾向于完全跳过信号,这很可惜。 It might be better to set up your signalling first, verify that it works using your ID method of discovery, and then add WebRTC on top of that. 最好先设置您的信令,使用发现的ID方法验证其是否有效,然后在其上添加WebRTC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM