Janus源码分析(4)——信令交互过程

1. Janus插件交互流程

Janus中所有插件都遵循以下基本数据流程:

  1. 客户端发送create创建一个Janus会话;
  2. Janus回复success返回Janus会话句柄;
  3. 客户端发送attach命令在Janus会话上attach指定插件;
  4. Janus回复success返回插件的句柄;
  5. 客户端给指定的插件发送message进行信令控制;
  6. Janus上的插件发送event通知事件给客户端;
  7. 客户端收集candidate并通过trickle消息发送给插件绑定的ICE通道;
  8. Janus发送webrtcup通知ICE通道建立;
  9. 客户端发送媒体数据;
  10. Janus发送media消息通知媒体数据的第一次到达;
  11. Janus进行媒体数据转发。

2. Janus信令交互过程

2.1 客户端与Janus信令交互

Janus客户端 Janus网关 Janus客户端发送create请求创建会话 Janus网关创建会话,并返回会话ID Janus客户端发送attach请求使用插件 Janus网关查找插件,并返回插件ID Janus客户端给指定插件发送message(Join) Janus网关返回ack消息 Janus网关处理message,并将结果通过event事件发送给客户端 Janus客户端给指定插件发送message(Configure & offer) Janus客户端给指定插件发送trickle(Candidate) ...【有多个trickl e(Candidate)】 ...【有多个trickl e(Candidate)】 Janus客户端给指定插件发送trickle(Candidate) Janus网关返回message(Configure & offer)的ack消息 Janus网关处理message(Configure & offer),并将answer通过event事件发送给客户端 Janus网关返回ack消息 ...【有多个tri ckle(Candi date)的ack】) ...【有多个tri ckle(Candi date)的ack】) Janus网关返回ack消息 Janus客户端给指定插件发送trickle(Candidate Complete) Janus网关返回trickle(Candidate Complete)的ack消息 Janus网关返回webrtcup消息 Janus网关返回media(video)消息 Janus网关返回media(audio)消息 发送媒体数据(video、audio) Janus客户端 Janus网关
  • Janus客户端->Janus网关: Janus客户端发送create请求创建会话
{
	"janus": "create",
	"transaction": "XoldN2OmUa3r
}
  • Janus网关–>>Janus客户端: Janus网关创建会话,并返回会话ID
{
	"janus": "success",
	"transaction": "XoldN2OmUa3r,
	"data": {
		"id": 7147844471131709
	}
}
  • Janus客户端->Janus网关: Janus客户端发送attach请求使用插件
{
	"janus": "attach",
	"plugin": "janus.plugin.videoroom",
	"session_id": 7147844471131709,
	"transaction": "zZxl_ZT7tFwTU"
}
  • Janus网关–>>Janus客户端: Janus网关查找插件,并返回插件ID
{
	"janus": "success",
	"session_id": 7147844471131709,
	"transaction": "zZxl_ZT7tFwTU",
	"data": {
		"id": 7668325947218508
	}
}
  • Janus客户端->Janus网关: Janus客户端给指定插件发送message(Join)
{
	"janus": "message",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508
	"transaction": "AblncRsrMM3T",
	"body": {
		"request": "join",
		"room": 1234,
		"ptype": "publisher",
		"display": "ban"
	}
}
  • Janus网关–>>Janus客户端: Janus网关返回ack消息
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "AblncRsrMM3T"
}
  • Janus网关–>>Janus客户端: Janus网关处理message,并将结果通过event事件发送给客户端
{
	"janus": "event",
	"session_id": 7147844471131709,
	"transaction": "AblncRsrMM3T",
	"sender": 7668325947218508,
	"plugindata": {
		"plugin": "janus.plugin.videoroom",
		"data": {
			"videoroom": "joined",
			"room": 1234,
			"description": "Demo Room",
			"id": 8177683424697792,
			"private_id": 1508384900,
			"publishers":[]
		}
	}
}
  • Janus客户端->Janus网关: Janus客户端给指定插件发送message(Configure & offer)
{
	"janus": "message",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508,
	"transaction": "QvOYptHlhVOl",
	"body": {
		"request": "configure",
		"audio": true,
		"video": true
	},
	"jsep": {
		"sdp": "......",
		"type": "offer"
	}
}
  • Janus客户端->Janus网关: Janus客户端给指定插件发送trickle(Candidate)
{
	"candidate": {
		"candidate": "candidate:2202484529 1 udp 2122262783 2409:8805:85e3:2dd9:l:l:al91:925c 55527 typ host generation 0",
		"sdpMid": "audio",
		"sdpMLinelndex": 0
	},
	"janus": "trickle",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508,
	"transaction": "A39mtuEYv9cR"
}
{
	"candidate": {
		"candidate": "candidate:2530088836 1 udp 2122194687 192.168.1.106 33864 typ host generation 0",
		"sdpMid": "audio",
		"sdpMLinelndex": 0
	}
	"janus": "trickle",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508,
	"transaction": "qFvztALbkXUG"
}
{
	"candidate": {
		"candidate": "candidate:2202484529 2 udp 2122262782 2409:8805:85e3:2dd9:l:l:al91:925c 42873 typ host generation 0",
		"sdpMid": "audio",
		"sdpMLinelndex": 0
	},
	"janus": "trickle",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508,
	"transaction": "VOzahdOJx6pn"
}
{
	"candidate": {
		"candidate": "candidate:2530088836 2 udp 2122194686 192.168.1.106 44575 typ host generation 0",
		"sdpMid": "audio",
		"sdpMLinelndex": 0
	},
	"janus": "trickle",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508,
	"transaction": "spupMHelabw8"
}
  • Janus网关–>>Janus客户端: Janus网关返回message(Configure & offer)的ack消息
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "QvOYptHlhVOl"
}
  • Janus网关–>>Janus客户端: Janus网关处理message(Configure & offer),并将answer通过event事件发送给客户端
{
	"janus": "event",
	"session_id": 7147844471131709,
	"transaction": "Qv0YptHlhVOl"
	"sender": 7668325947218508,
	"plugindata": {
		"plugin": "janus.plugin.videoroom",
		"data": {
			"videoroom": "event",
			"room": 1234,
			"configured": "ok"
			"audio_codec": "opus",
			"video_codec": "h264"
		}
	},
	"jsep":{
		"type": "answer",
		"sdp": "......"
	}
}
  • Janus网关–>>Janus客户端: Janus网关返回ack消息
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "A39mtuEYv9cR"
}
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "qFvztALbkXUG"
}
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "VOzahdOJx6pn"
}
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "spupMHelabw8"
}
  • Janus客户端->Janus网关: Janus客户端给指定插件发送trickle(Candidate Complete)
{
	"candidate": {
		"completed": true
	}
	"janus": "trickle",
	"session_id": 7147844471131709,
	"handle_id": 7668325947218508,
	"transaction": "43XefXDPTPMX"
}
  • Janus网关–>>Janus客户端: Janus网关返回trickle(Candidate Complete)的ack消息
{
	"janus": "ack",
	"session_id": 7147844471131709
	"transaction": "43XefXDPTPMX"
}
  • Janus网关–>>Janus客户端: Janus网关返回webrtcup消息
{
	"janus": "webrtcup",
	"session_id": 7147844471131709,
	"sender": 7668325947218508
}
  • Janus网关–>>Janus客户端: Janus网关返回media(video)消息
{
	"janus": "media",
	"session_id": 7147844471131709,
	"sender": 7668325947218508,
	"type": "video",
	"receiving": true
}
  • Janus网关–>>Janus客户端: Janus网关返回media(audio)消息
{
	"janus": "media",
	"session_id": 7147844471131709,
	"sender": 7668325947218508,
	"type": "audio",
	"receiving": true
}

2.2 客户端之间的交互

Janus客户端A Janus网关 Janus客户端B 建立连接 过程参考【客户端与 Janus信令交互】 连接建立成功 建立连接 过程参考【客户端与 Janus信令交互】 连接建立成功 发送媒体数据(video、audio) 处理媒体数据分层(video、audio) 转发媒体数据分层(video、audio) 发送媒体数据(video、audio) 处理媒体数据分层(video、audio) 转发媒体数据分层(video、audio) Janus客户端A Janus网关 Janus客户端B

2.3 客户端keepalive

Janus客户端 Janus网关 Janus客户端发送keepalive Janus网关返回ack消息 Janus客户端 Janus网关
  • Janus客户端->Janus网关: Janus客户端发送keepalive
{
	"janus": "keepalive",
	"session_id": 7147844471131709,
	"transaction": "WZqW7GMauQpS"
}
  • Janus网关–>>Janus客户端: Janus网关返回ack消息
{
	"janus": "ack",
	"session_id": 7147844471131709,
	"transaction": "WZqW7GMauQpS"
}

3. 完整信令交互时序图

4. 参考资料

基于Webrtc和Janus的多人视频会议系统开发4 - 改造信令交互系统完成sdp交换过程
https://blog.csdn.net/u011382962/article/details/81708519

你可能感兴趣的:(WebRTC)