演示平台 文档中心 开发接口 官方网站

本文详细讲解licode与客户端之间的发布订阅协议。

licode提供的客户端例子是web的,如果需要开发移动端,需要弄清楚底层的信令协议。

本文详细讲解licode与客户端之间的发布订阅协议。


发布流程:
1,  通过http往https://webrtc.serverip.com:3004/createToken,
发送加入room json串{“username”: “test”, “role”: “presenter”, “room”:”test”}
返回一个base64字符串,base64解码后为如下json串:
{"tokenId":"57fb05f861cc9d45ff93adb0","host":"webrtc.serverip.com:8080","secure":true,"signature":"YmU4OTBmYzBlYTQ5MmY1OWE1MGMwY2I5ZjljZjdiNTE3ZDg0MThjMw=="}
从这个json串中解析出tokenid、host、secure。后面socketio连接要用到这些信息


2,  通过socketio库连接host。
通过socketio发送认证json串:
{"name":"token","args":[{"tokenId":"57fb05f861cc9d45ff93adb0","host":"webrtc.serverip.com:8080","secure":true,"signature":"YmU4OTBmYzBlYTQ5MmY1OWE1MGMwY2I5ZjljZjdiNTE3ZDg0MThjMw=="}]},其中args中为第1步返回的json串。
返回json串:
["success",{"streams":[{"id":754199833790274200,"audio":true,"video":true,"data":true}],"id":"57f9e353ac42a9604255018c","defaultVideoBW":300,"maxVideoBW":300,"iceServers":[{"url":"stun:stun.l.google.com:19302"}]}]
解析出iceServers,如果返回success,继续第3步


3,  通过socketio发送publish json串:
{"name":"publish","args":[{"state":"erizo","data":true,"audio":true,"video":true,"minVideoBW":0,"attributes":{"name":"myStream"}},null]}
返回json串:
[381303566740825800]
保存该串数字,该值为本次在会议中的session值


4,  初始化peerconnection,获取本地sdp值(offer)
通过socketio发送offer json串:
{"name":"signaling_message","args":[{"streamId":381303566740825800,"msg":{"type":"offer","sdp":<offer>}},null]},其中的streamId为上一步返回的数字串

 

5,从socketio收到服务端的answer事件json串:
{"name":"signaling_message_erizo","args":[{"mess":{"type":"answer","sdp":<answer>},"streamId":381303566740825800}]}
将<answer>设置到peerconnection中(setRemoteDescription)


从socketio收到服务端的candidate json串:将<candidate>添加到peerconnection中(addIceCandidate)



peerconnection中收集地址回调(didGenerateIceCandidate)
通过socketio发送candidate json串:
{"name":"signaling_message","args":[{"streamId":381303566740825800,"msg":{"type":"candidate","candidate":{"sdpMLineIndex":0,"sdpMid":"audio","candidate":"a=candidate:36924727061 udp 2122260223 192.168.10.112 49867 typ host generation 0 ufrag 5Ll1QmAw6Xy4Go4/network-id 1"}}},null]}


订阅流程:
(1)从socketio收到服务端的onAddStream事件json串:
{"name":"onAddStream","args":[{"id":381303566740825800,"audio":true,"video":true,"data":true,"attributes":{"name":"myStream"}}]}

通过socketio发送订阅json串:
{"name":"subscribe","args":[{"streamId":381303566740825800,"slideShowMode":false,audio: true, video: true},null]}
返回json串:
[true]
如果收到true,继续第(2)步

(2)新建一个peerconnection[streamId],获取本地sdp值(offer)
通过socketio发送json串:
{"name":"signaling_message","args":[{"streamId":381303566740825800,"msg":{"type":"offer","sdp":<offer>}},null]}



(3) 从socketio收到服务端的answer事件json串:
{"name":"signaling_message_erizo","args":[{"mess":{"type":"answer","sdp":<answer>},"peerId":381303566740825800}]}
将<answer>设置到peerconnection[peerId]中(setRemoteDescription)


peerconnection[peerId]中收集地址回调(didGenerateIceCandidate)
通过socketio发送json串:
{"name":"signaling_message","args":[{"streamId":381303566740825800,"msg":{"type":"candidate","candidate":{"sdpMLineIndex":0,"sdpMid":"audio","candidate":"a=candidate:36924727061 udp 2122260223 192.168.10.112 57084 typ host generation 0 ufrag ELEtGh4wCq/d1SPinetwork-id 1"}}},null]}


ios客户端代码参考:https://github.com/webrtc-video/licode-client-ios


收藏

共0条 1

登录 后发表评论。没有帐号? 注册 一个。

2019-07-18 04:16:51 36 次浏览 0 个评论