javascript - webRTC - 多房间视频 session

标签 javascript go websocket webrtc

我正在使用 Pion SFU-WS,基本上是一个基于 golang 的 webRTC 应用程序 Pion- SFU .

虽然一切都很顺利,但我对如何召开多个 session 一无所知(就像我们从 Microsoft Teams 或 Zoom 中了解到的那样)。这是我正在尝试做的一个例子:

房间 1: https://localhost:7676/?room-id=12345

房间 1 的参与者 = A、B、C、D

房间 2: https://localhost:7676/?room-id=67890

房间 2 的参与者 = E、F、G、H

我可以想象必须将一个static session-id传递给

peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{})

然而,我所有的努力/方法都失败了。

如有任何帮助,我们将不胜感激。

最佳答案

经过一些调试,我想出了以下“解决方案”。虽然我现在可以将同行隔离到一个特定的房间,但我不确定这是否是使用 webRTC 处理多个房间的正确方法。

因此,我还没有接受这个答案。特别是,我希望其中一位 Pion 专家能够对这种方法的性能问题发表评论。

想法是将对等连接列表绑定(bind)到特定房间 ID:

// make list of peer connections globally accessable
// example: peerconnections[1234][..]peerConnectionState{peerConnection, c}
var peerConnections map[string][]peerConnectionState

// Create new PeerConnection
// peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{})
peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig)


// the list of connections
// initialize connections list
if peerConnections == nil {
    peerConnections = make(map[string][]peerConnectionState, 0)
}

// push peer connection to the list of peer connections of a specific room
if peerConnections[roomId] == nil {
    peerConnections[roomId] = []peerConnectionState{peerConnectionState{peerConnection, c}}
}else{
    peerConnections[roomId] = append(peerConnections[roomId], peerConnectionState{peerConnection, c})
}

关于javascript - webRTC - 多房间视频 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70098206/

相关文章:

python - 如何阻止我的 websocket 连接关闭?

javascript - 隐藏下载链接 10 秒? js

c# - 带有 Javascript 客户端的 WCF 自托管 WebSocket 服务

json - 在 config.json 文件中输入自定义类型值

go - Gazelle 没有创建正确的依赖关系?

python - 使用 channel 2 向一位用户发送通知

Javascript 对象创建与 this 关键字和原型(prototype)属性的混淆

javascript - Wordpress自定义表单输入检查

golang 测试命令行参数

google-chrome - 指示 websocket 服务器不支持任何扩展的 header