在 owt 里面 webrtc-agent 负责 webrtc 连接的生命周期管理,提供 webrtc 接入服务。
webrtc 入会流程

入会

MCU混屏
1. 申请入会
-
【获取token】client 通过 management-api rest 接口得到入会 token
-
POST ${host}/v1/rooms/{roomId}/tokens
-
【接入信令服务】client 分析 token 得到 portal 的地址(ip和端口),通过 socket.io(底层是 websocket) 发起连接
(refs: https://github.com/open-webrtc-toolkit/owt-client-javascript/blob/0f1099dbfffca40466826ba5af879ac07cea6e16/src/sdk/conference/client.js#L390)
-
-
【发送 publish 消息】socket.io 接入后,先发送 login (附带token)登录,然后通过 socket.io 发送 publish 消息请求 webrtc 接入
(refs: https://github.com/open-webrtc-toolkit/owt-client-javascript/blob/0f1099dbfffca40466826ba5af879ac07cea6e16/src/sdk/conference/channel.js#L362)
-
2. 建立 webrtc 连接
-
【做一些会议业务逻辑】portal 转发 publish 消息到 conference-agent,conference-agent 生成一个 streamId,并转发到对应的 webrtc-agent
client 携带 transportId 则使用该 id 对应的 webrtc-agent(例如 publish 之前进行 subscribe,则会有一个 transportId),否则使用 streamId 来作为 trasportId 并向 clusterManager 申请一个可用的 webrtc-agent
(refs: https://github.com/open-webrtc-toolkit/owt-server/blob/5b7dda5c098f7803ab8934ec66a1dd1b48856e9f/source/agent/conference/conference.js#L1113)
-
-
【生成 RTCPeerConnection】webrtc-agent 的 publish 方法以 streamId 为标识创建一个 erizo::WebRtcConnection(licode 里面对 webrtc 协议里的 RTCPeerConnection 的近似实现) 对象
(refs: https://github.com/open-webrtc-toolkit/owt-server/blob/5b7dda5c098f7803ab8934ec66a1dd1b48856e9f/source/agent/webrtc/index.js#L238)
-
-
【信令交换,连接建立】client 通过 socket.io 发送/接收 soac/progress 事件来交互 sdp 与 candidate,至此 webrtc 数据连接已经连通
WebRtcConnection 会使用构造函数里面传来的端口范围检测并生成 candidate。
(refs: https://github.com/open-webrtc-toolkit/owt-server/blob/5b7dda5c098f7803ab8934ec66a1dd1b48856e9f/source/agent/webrtc/wrtcConnection.js#L297 - 服务端发送信令)
(refs: https://github.com/open-webrtc-toolkit/owt-server/blob/5b7dda5c098f7803ab8934ec66a1dd1b48856e9f/source/agent/webrtc/wrtcConnection.js#L592 - 处理客户端信令)
-
-
【收发数据】erizo:WebRtcConnection 会根据 SDP/candidate 信息创建 erizo::DtlsTransport 收发数据,并通过 erizo::MediaStream - [Video/Audio]FrameConstructor - [Video/Audio]FramePacketizer 来收发到 OWT 层
erizo:WebRtcConnection 接收数据流程
-
3. MCU 混屏
如果开启了 video-agent 节点,则服务端具备 MCU 混屏能力
-
【API请求】client 调用 management-api rest 发送混屏请求
-
PATCH ${host}/v1.1/rooms/{roomId}/streams/{streamId}
{
op: "add",
path: "/info/inViews",
value: string(viewLabel)
}
-
-
【转发 RTP数据】management-api 转发请求到 conference-agent.controlStream,稍作整理后告诉 webrtc 转发 streamId 对应的 rtp 数据(webrtc 使用 rtp 格式传输媒体数据)到相应的 video-agent
具体流程:
- 通知对应的 webrtc-agent 创建一个 InternalOut 对象(owt 节点间收发数据的机制),并调用 webrtc-agent.subscribe 订阅 streamId 流到 该 InternalOut
- 通知对应的 video-agent 创建一个 InternalIn 对象,并调用 video-agent.publish 从该 InternalIn 接收数据
- 调用对应的 webrtc-agent.linkup 让 InternalOut 的数据流向 InternalIn
- 至此 webrtc-agent 的 rtp 数据将会转发到 video-agent
(refs: https://github.com/open-webrtc-toolkit/owt-server/blob/5b7dda5c098f7803ab8934ec66a1dd1b48856e9f/source/agent/conference/roomController.js#L537)
(注:5.x 使用 InternalIO 点对点方式传输 Internal 数据,之后修改了 InternalIO 的连接流程,改用 Server-Client 方式)
-
4. 播放
client 可以选择订阅服务端的 RTP 数据流(例如,混屏流和 webrtc publish 上来的流)
-
【发送 subscribe 消息】client 通过 socket.io 发送 subscribe 消息,附带 streamId 参数来请求订阅对应的流,subscribe 消息会转发到 conference-agent
streamId 列表可以通过 management-api rest 接口获取
-
-
【混屏流转发到 webrtc-agent】conference-agent 收到 subscribe 消息后,如果 streamId 是混屏流,则通知 video-agent 转发 rtp 数据到 webrtc-agent
使用 video-agent.generate 生成一个输出流,并使用 InternalIn,InternalOut,linkup的操作转发数据,类似 webrtc-agent 转发数据到 video-agent的流程
-
-
【webrtc 流程】整个订阅流程与 publish 类似,最后 webrtc-agent 会收到 subscribe 消息并生成 erizo::WebRtcConnection 对象与客户端建立连接
-
