webrtc通信流程图

 

webrtc通话过程:

webrtc通信流程图_第1张图片

  1. 如果是语音通话,首先通过配置信息,判断是否开启webrtc功能。
  2. 如果开启了或者是视频通话,拨号方会通过本地数据库获取接听方应用平台类型、版本号信息。现在只有在应用是Android 以及Android版本号是大于等于241才能够使用webrtc功能。如果本地没有保存对方版本信息等,通过接口获取并以json格式包存到本地。
  3. 拨号方首先以cmd命令的形式通过sip 发送call_request 命令去获取对方是否空闲 。
  4. 服务器会返回消息成功,失败回执,如果失败:被叫方是ios就继续等待,如果被叫方是Android 就挂断电话,告知用户”对方不在线”。如果成功不做处理
  5. 拨号方收到对方空闲的命令后发送webrtc通话请求,以cmd命令的形式通过sip发送message_type_call,如果这个时候拨打方已经收集到了SDP数据就将sdp数据一并带过去,如果这个时候本地还没收集到sdp就继续等待,等sdp收集了在发送message_type_call。
  6. 接收方收到message_type_call命令的通话请求后弹出接听电话界面,并且将收到的sdp设置到本地,做接听或者挂断操作,如果点击接听:跳转到通话界面,显示’正在连接中’,并且以cmd的形式通过sip发送message_type_answer,如果这个时候接听方收集到了sdp、 将sdp带上发送给拨打方,如果这个时候接听方还没收集到sdp就等待,等收集到了在跟message_type_answer命令一起发送给拨打方,并且把收集到的ice单独以sip 信令发送message_type_iceCandidat给拨打方。
  7. 拨打方收到对方接听电话的命令,发送收集到的ice信息以sip 信令发送message_type_iceCandidat命令给接听方。界面跳转到通话界面,并显示”正在连接中...”
  8. 接听方收到对方发送来的ice命令后将相关信息设置进webrtc的相关方法。并将自己接收到的ice信息发送给拨打方
  9. 相互设置了sdp跟ice后,webrtc会建立两端的连接,并将连接状态通个ice的状态返回,如果收到ice的状态IceConnectionState.CONNECTED说明这时两端才真正建立了通话,如果拨打的是视频通话,这个时候拨打方需要发送一个开启视频通话的cmd命令switchvideo_request

注意事项:在发送webrtc_call的时候可能拨号方sdp还没收集到,必须要等到sdp收集到过后才能真正的发送webrtc_call命令,在接听方接听电话发送webrtc_answer 命令的时候,接听方还没收集到本地的SDP,也必须等待sdp收集好了过后才能发送webrtc_answer命令

Ice是单独的命令将ice收集完了以集合的形式发送,在已经接通的过程中,收集到的ICE也要及时的发送给对方。

 

  1. 相关命令示例:

4、通话请求:message_type_call  -->webrtc_call

{"event_type":"p2p","message":"{\"activeHangUp\":false,\"isVideo\":false,\"sdp\":\"Xh0bWFwOjMgdXJuOmlldGY6cGFyYW1zOnJ0cC1oZHJleHQ6c2RlczptaWQNCmE9ZXh0bWFwOjQgdXJuOmlldGY6cGFyYW1zOnJ0cC1oZHJleHQ6c2RlczpydHAtc3RyZWFtLWlkDQphPWV4dG1hcDo1IHVybjppZXRmOnBhcmFtczpydHAtaGRyZXh0OnNkZXM6cmVwYWlyZWQtcnRwLXN0cmVhbS1pZA0KYT1zZW5kcmVjdg0KYT1tc2lkOkFSREFNUyBBUkRBTVNhMA0KYT1ydGNwLW11eA0KYT1ydHBtYXA6MTExIG9wdXMvNDgwMDAvMg0KYT1ydGNwLWZiOjExMSB0cmFuc3BvcnQtY2MNCmE9Zm10cDoxMTEgbWlucHRpbWU9MTA7dXNlaW5iYW5kZmVjPTENCmE9cnRwbWFwOjEwMyBJU0FDLzE2MDAwDQphPXJ0cG1hcDo5IEc3MjIvODAwMA0KYT1ydHBtYXA6MTAyIElMQkMvODAwMA0KYT1ydHBtYXA6MCBQQ01VLzgwMDANCmE9cnRwbWFwOjggUENNQS84MDAwDQphPXJ0cG1hcDoxMDUgQ04vMTYwMDANCmE9cnRwbWFwOjEzIENOLzgwMDANCmE9cnRwbWFwOjExMCB0ZWxlcGhvbmUtZXZlbnQvNDgwMDANCmE9cnRwbWFwOjExMyB0ZWxlcGhvbmUtZXZlbnQvMTYwMDANCmE9cnRwbWFwOjEyNiB0ZWxlcGhvbmUtZXZlbnQvODAwMA0KYT1zc3JjOjE2NjM4MTg5MTEgY25hbWU6Njh4SzVDS0xIUkZJN0xXag0KYT1zc3JjOjE2NjM4MTg5MTEgbXNpZDpBUkRBTVMgQVJEQU1TYTANCmE9c3NyYzoxNjYzODE4OTExIG1zbGFiZWw6QVJEQU1TDQphPXNzcmM6MTY2MzgxODkxMSBsYWJlbDpBUkRBTVNhMA0K\",\"type\":\"webrtc_call\,\"versionCode\":\"241\",\"versionType\":\"android\""}","msg_content":"message_type_call","msg_id":"be79981c-ef53-4412-acfd-2d31a12a9a06-5a33c","msg_type":11,"offline":0,"remote":"500055"}

 

5、挂断命令:message_type_call  -->webrtc_end

{"event_type":"p2p","message":"{\"activeHangUp\":true,\"isVideo\":false,\"type\":\"webrtc_end\",\"versionCode\":\"241\",\"versionType\":\"android\"}","msg_content":"message_type_call","msg_id":"1cdfd2e1-8d70-4c8c-bcdc-d221188fec01-2bef7","msg_type":11,"offline":0,"remote":"500055"}

 

6接听命令:message_type_call  -->webrtc_answer {"event_type":"p2p","message":"{\"activeHangUp\":true,\"isVideo\":false,\"sdp\":\"dj0wDQpvPS0gNTY3NzQzNjY4MTAxMDk4MTEzNCAyIElOIElQNCAxMjcuMC4wLjENCnM9LQ0KdD0wIDANCmE9Z3JvdXA6QlVORExFIDAgMQ0KYT1tc2lkLXNlbWFudGljOiBXTVMgQVJEQU1TDQptPXZpZGVvIDkgVURQL1RMUy9SVFAvU0FWUEYgOTYgOTcgOTggOTkgMTAwIDEwMSAxMjcNCmM9SU4gSVA0IDAuMC4wLjANCmE9cnRjcDo5IElOIElQNCAwLjAuMC4wDQphPWljZS11ZnJhZzpEbWlLDQphPWljZS1wd2Q6dFpYdXUxMDY2TTVuR1RUaVhrTE51SGRYDQphPWljZS1vcHRpb25zOnRyaWNrbGUgcmVub21pbmF0aW9uDQphPWZpbmdlcnByaW50OnNoYS0yNTYgNkI6ODg6NkE6QTQ6QTc6RjM6REI6Qzg6MUM6NDQ6MjI6Qzc6N0Q6MzU6NkE6MDI6RjY6RkY6RjA6Mzc6RTA6QTE6RTk6RTg6NEY6N0U6NTk6QTg6OUE6OEU6RTI6OTkNCmE9c2V0dXA6YWN0aXZlDQphPW1pZDowDQphPWV4dG1hcDoxNCB1cm46aWV0ZjpwYXJhbXM6cnRwLWhkcmV4dDp0b2Zmc2V0DQphPWV4dG1hcDoxMyBodH ODAwMA0KYT1ydHBtYXA6MTEzIHRlbGVwaG9uZS1ldmVudC8xNjAwMA0KYT1ydHBtYXA6MTI2IHRlbGVwaG9uZS1ldmVudC84MDAwDQphPXNzcmM6MjAxMTkzNjExIGNuYW1lOnBhNklJWkJmY21xTWZQSUQNCg\\u003d\\u003d\",\"type\":\"webrtc_answer\",\"versionCode\":\"241\",\"versionType\":\"android\"}","msg_timespan_server":1571653448000,"msg_content":"message_type_call","msg_id":"7bbe3b3c-1ef0-4a04-b41a-4c957522b58d-87077","msg_type":11,"offline":0,"remote":"500096"}

 

  1. ICE交互命令:message_type_iceCandidate {"event_type":"p2p","iceDataList":[],"message":"[{\"candidate\":\"candidate:1313467711 1 udp 2122260223 192.168.120.94 56049 typ host generation 0 ufrag DmiK network-id 3 network-cost 10\",\"id\":\"0\",\"label\":0},{\"candidate\":\"candidate:1386202964 1 udp 25108479 47.96.79.194 60875 typ relay raddr 171.221.137.133 rport 18159 generation 0 ufrag DmiK network-id 3 network-cost 10\",\"id\":\"0\",\"label\":0}]","msg_timespan_server":1571653448000,"msg_content":"message_type_iceCandidate","msg_id":"df153720-6d07-4117-99d4-f9990e1e8d80-87078","msg_type":11,"offline":0,"remote":"500096","type":"candidate"}

8、当前忙命令:message_type_call  -->webrtc_busy

{"event_type":"p2p","message":"{\"activeHangUp\":true,\"isVideo\":false,\"type\":\"webrtc_busy\",\"versionCode\":\"241\",\"versionType\":\"android\"}","msg_content":"message_type_call","msg_id":"1cdfd2e1-8d70-4c8c-bcdc-d221188fec01-2bef7","msg_type":11,"offline":0,"remote":"500055"}

 

你可能感兴趣的:(android相关)