WebRTC Perfect Negotiation pattern: WebRTC 完美谈判模式; An basic video chat using the WebRTC Perfect negotiation pattern. a sprinkling of Hotwire (mainly Turbo Streams & Stimulus), and backed by ruby on rails.
杰瑞发布于2024-09-05
WebRTC Perfect Negotiation pattern: WebRTC 完美谈判模式; An basic video chat using the WebRTC Perfect negotiation pattern. a sprinkling of Hotwire (mainly Turbo Streams & Stimulus), and backed by ruby on rails.
The Stimulus room controller handles Enter button click.It gets the user's local audio and video and feeds them into the local video element. It also starts Action Cable subscriptions specific to the current room: one for communicating WebRTC messages: the Signaller; and one for clients to ping others: the RoomSubscription.Stimulus控制器处理Enter按钮的点击。它获取用户的本地音频和视频,并将其送到本地视频元素中。它也启动了在针对当前room的 Action Cable 订阅(signaling subscription and room subscription)分别处理webRTC消息和ping其他客户端。 It's important we do this first so that it's ready for incoming streams. The medium controller messages the room controller to notify that it has been added. This begins the WebRTC negotiation to form a connection between the two clients.重要的是,我们首先要这样做,以便为传入流做好准备。介质控制器向房间控制器发送消息,通知其已被添加。这将启动WebRTC协商,以在两个客户端之间建立连接。 The negotiation is "perfect" as it ensures that the RTCPeerConnection is in the correct state for setting descriptions, and avoids collision errors by having one client be "polite" and other "impolite"-the polite one backs down in the case of a collision.协商是“完美的”,因为它确保RTCPeerConnection处于设置描述的正确状态,并通过让一个客户端“礼貌”而另一个“不礼貌”来避免冲突错误——在发生冲突时,礼貌的客户端会退缩。 Anyway, the code for this has been mostly lifted from the spec and handled by the Signaller /WebrtcNegotiation. When creating the negotiation, the room controller listens for track events on the TRCPeerConnection, so it can start streaming from the remote client.无论如何,此代码大多是从规范中提取的,由Signaler/WebrtcNegotiation处理。创建协商时,房间控制器会监听TRCPeerConnection上的跟踪事件,以便它可以从远程客户端开始流式传输。 This kicks off the complex exchange of SDP descriptions and ICE candidates, and once either is received by the newcomer, it can start the streaming process from its own stream to the other client. Now all clients are streaming to and from each other.这启动了SDP描述和ICE候选者的复杂交换,一旦新来者收到其中任何一个,它就可以开始从自己的流到另一个客户端的流处理。现在,所有客户端都在相互之间进行流式传输。