欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

webrtc多人在线视频通讯

程序员文章站 2022-05-15 22:12:21
...

GitHub项目地址:https://github.com/lzming9511/webrtc

webrtc多人在线视频通讯项目,采用P2P点对点连接,后端服务只进行信令的交换,不参与音频流的交换,服务端的压力小

1.发起请求的客服端发送_offer到服务端,服务端群发给同房间的接收的客服端

2.发起请求的客服端发送_ice_candidate到服务端,服务端群发给同房间的接收的客服端

3.发起请求的客服端接收到_offer信令,给服务器回复_answer,服务器发送给发起请求的客服端

4.发起请求的客服端接收到_ice_candidate信令,给服务器回复_ice_candidate,服务器发送给发起请求的客服端

通过上面4个步骤实现信令的交换,webrtc知道要连接哪个地址,webrtc通过p2p进行点对点的连接

rev服务端收到 客服端1 消息:	{"event":"_offer","data":{"sdp":{"type":"offer","sdp":"v=0\r\no=- 4384462181796616779 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:Imys\r\na=ice-pwd:Ax+qGfBB82LoJRxTeEI8kH3k\r\na=ice-options:trickle\r\na=fingerprint:sha-256 E9:37:F9:56:C9:D6:0D:5A:C7:5E:11:3B:FF:99:91:C3:E0:25:F1:BA:2D:A6:45:4E:B5:B4:A3:B6:CD:A8:7B:B0\r\na=setup:actpass\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=sendrecv\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:757630844 cname:ykf1Sa1gQQw6svQF\r\na=ssrc:757630844 msid:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o 099b799e-7678-4eac-bd04-0934c32a8530\r\na=ssrc:757630844 mslabel:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\na=ssrc:757630844 label:099b799e-7678-4eac-bd04-0934c32a8530\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 124 127 123 125\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:Imys\r\na=ice-pwd:Ax+qGfBB82LoJRxTeEI8kH3k\r\na=ice-options:trickle\r\na=fingerprint:sha-256 E9:37:F9:56:C9:D6:0D:5A:C7:5E:11:3B:FF:99:91:C3:E0:25:F1:BA:2D:A6:45:4E:B5:B4:A3:B6:CD:A8:7B:B0\r\na=setup:actpass\r\na=mid:video\r\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:3gpp:video-orientation\r\na=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=sendrecv\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 H264/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:102 H264/90000\r\na=rtcp-fb:102 goog-remb\r\na=rtcp-fb:102 transport-cc\r\na=rtcp-fb:102 ccm fir\r\na=rtcp-fb:102 nack\r\na=rtcp-fb:102 nack pli\r\na=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:124 rtx/90000\r\na=fmtp:124 apt=102\r\na=rtpmap:127 red/90000\r\na=rtpmap:123 rtx/90000\r\na=fmtp:123 apt=127\r\na=rtpmap:125 ulpfec/90000\r\na=ssrc-group:FID 4154594995 2598090200\r\na=ssrc:4154594995 cname:ykf1Sa1gQQw6svQF\r\na=ssrc:4154594995 msid:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o 70d76e71-7726-4f52-ac28-95fca16cf228\r\na=ssrc:4154594995 mslabel:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\na=ssrc:4154594995 label:70d76e71-7726-4f52-ac28-95fca16cf228\r\na=ssrc:2598090200 cname:ykf1Sa1gQQw6svQF\r\na=ssrc:2598090200 msid:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o 70d76e71-7726-4f52-ac28-95fca16cf228\r\na=ssrc:2598090200 mslabel:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\na=ssrc:2598090200 label:70d76e71-7726-4f52-ac28-95fca16cf228\r\n"}}}
send服务器发送给 客服端0 消息:{"event":"_offer","data":{"sdp":{"type":"offer","sdp":"v=0\r\no=- 4384462181796616779 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:Imys\r\na=ice-pwd:Ax+qGfBB82LoJRxTeEI8kH3k\r\na=ice-options:trickle\r\na=fingerprint:sha-256 E9:37:F9:56:C9:D6:0D:5A:C7:5E:11:3B:FF:99:91:C3:E0:25:F1:BA:2D:A6:45:4E:B5:B4:A3:B6:CD:A8:7B:B0\r\na=setup:actpass\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=sendrecv\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:757630844 cname:ykf1Sa1gQQw6svQF\r\na=ssrc:757630844 msid:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o 099b799e-7678-4eac-bd04-0934c32a8530\r\na=ssrc:757630844 mslabel:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\na=ssrc:757630844 label:099b799e-7678-4eac-bd04-0934c32a8530\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 124 127 123 125\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:Imys\r\na=ice-pwd:Ax+qGfBB82LoJRxTeEI8kH3k\r\na=ice-options:trickle\r\na=fingerprint:sha-256 E9:37:F9:56:C9:D6:0D:5A:C7:5E:11:3B:FF:99:91:C3:E0:25:F1:BA:2D:A6:45:4E:B5:B4:A3:B6:CD:A8:7B:B0\r\na=setup:actpass\r\na=mid:video\r\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:3gpp:video-orientation\r\na=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=sendrecv\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 H264/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:102 H264/90000\r\na=rtcp-fb:102 goog-remb\r\na=rtcp-fb:102 transport-cc\r\na=rtcp-fb:102 ccm fir\r\na=rtcp-fb:102 nack\r\na=rtcp-fb:102 nack pli\r\na=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:124 rtx/90000\r\na=fmtp:124 apt=102\r\na=rtpmap:127 red/90000\r\na=rtpmap:123 rtx/90000\r\na=fmtp:123 apt=127\r\na=rtpmap:125 ulpfec/90000\r\na=ssrc-group:FID 4154594995 2598090200\r\na=ssrc:4154594995 cname:ykf1Sa1gQQw6svQF\r\na=ssrc:4154594995 msid:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o 70d76e71-7726-4f52-ac28-95fca16cf228\r\na=ssrc:4154594995 mslabel:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\na=ssrc:4154594995 label:70d76e71-7726-4f52-ac28-95fca16cf228\r\na=ssrc:2598090200 cname:ykf1Sa1gQQw6svQF\r\na=ssrc:2598090200 msid:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o 70d76e71-7726-4f52-ac28-95fca16cf228\r\na=ssrc:2598090200 mslabel:rQ2fkIWHNlMQMYCxNYUdr80O1riSyJ9O9k4o\r\na=ssrc:2598090200 label:70d76e71-7726-4f52-ac28-95fca16cf228\r\n"}}}
rev服务端收到 客服端1 消息:	{"event":"_ice_candidate","data":{"candidate":{"candidate":"candidate:2201212986 1 udp 2113937151 172.18.1.229 49631 typ host generation 0 ufrag Imys network-cost 50","sdpMid":"audio","sdpMLineIndex":0}}}
send服务器发送给 客服端0 消息:{"event":"_ice_candidate","data":{"candidate":{"candidate":"candidate:2201212986 1 udp 2113937151 172.18.1.229 49631 typ host generation 0 ufrag Imys network-cost 50","sdpMid":"audio","sdpMLineIndex":0}}}
rev服务端收到 客服端1 消息:	{"event":"_ice_candidate","data":{"candidate":{"candidate":"candidate:2201212986 1 udp 2113937151 172.18.1.229 49633 typ host generation 0 ufrag Imys network-cost 50","sdpMid":"video","sdpMLineIndex":1}}}
send服务器发送给 客服端0 消息:{"event":"_ice_candidate","data":{"candidate":{"candidate":"candidate:2201212986 1 udp 2113937151 172.18.1.229 49633 typ host generation 0 ufrag Imys network-cost 50","sdpMid":"video","sdpMLineIndex":1}}}
rev服务端收到 客服端0 消息:	{"event":"_answer","data":{"sdp":{"type":"answer","sdp":"v=0\r\no=- 2387596707289326636 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:vu+3\r\na=ice-pwd:aqMVjGj1Hz8ziy3PB+I1QY3y\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F3:66:9C:C3:2D:0B:90:17:47:BB:30:B3:6D:F5:24:5C:87:E8:71:56:D1:C0:00:7D:08:CB:AA:84:18:98:6E:71\r\na=setup:active\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=sendrecv\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3611041506 cname:reYQqYdSFjANuTK6\r\na=ssrc:3611041506 msid:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR 1f05dacf-9044-4f52-8823-6a48d5ac4e47\r\na=ssrc:3611041506 mslabel:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\na=ssrc:3611041506 label:1f05dacf-9044-4f52-8823-6a48d5ac4e47\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 124 127 123 125\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:vu+3\r\na=ice-pwd:aqMVjGj1Hz8ziy3PB+I1QY3y\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F3:66:9C:C3:2D:0B:90:17:47:BB:30:B3:6D:F5:24:5C:87:E8:71:56:D1:C0:00:7D:08:CB:AA:84:18:98:6E:71\r\na=setup:active\r\na=mid:video\r\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:3gpp:video-orientation\r\na=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=sendrecv\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 H264/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:102 H264/90000\r\na=rtcp-fb:102 goog-remb\r\na=rtcp-fb:102 transport-cc\r\na=rtcp-fb:102 ccm fir\r\na=rtcp-fb:102 nack\r\na=rtcp-fb:102 nack pli\r\na=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:124 rtx/90000\r\na=fmtp:124 apt=102\r\na=rtpmap:127 red/90000\r\na=rtpmap:123 rtx/90000\r\na=fmtp:123 apt=127\r\na=rtpmap:125 ulpfec/90000\r\na=ssrc-group:FID 4142159662 3050859437\r\na=ssrc:4142159662 cname:reYQqYdSFjANuTK6\r\na=ssrc:4142159662 msid:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR fe5233ce-203d-42e0-8e1a-19c2745781b8\r\na=ssrc:4142159662 mslabel:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\na=ssrc:4142159662 label:fe5233ce-203d-42e0-8e1a-19c2745781b8\r\na=ssrc:3050859437 cname:reYQqYdSFjANuTK6\r\na=ssrc:3050859437 msid:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR fe5233ce-203d-42e0-8e1a-19c2745781b8\r\na=ssrc:3050859437 mslabel:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\na=ssrc:3050859437 label:fe5233ce-203d-42e0-8e1a-19c2745781b8\r\n"}}}
send服务器发送给 客服端1 消息:{"event":"_answer","data":{"sdp":{"type":"answer","sdp":"v=0\r\no=- 2387596707289326636 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:vu+3\r\na=ice-pwd:aqMVjGj1Hz8ziy3PB+I1QY3y\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F3:66:9C:C3:2D:0B:90:17:47:BB:30:B3:6D:F5:24:5C:87:E8:71:56:D1:C0:00:7D:08:CB:AA:84:18:98:6E:71\r\na=setup:active\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=sendrecv\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3611041506 cname:reYQqYdSFjANuTK6\r\na=ssrc:3611041506 msid:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR 1f05dacf-9044-4f52-8823-6a48d5ac4e47\r\na=ssrc:3611041506 mslabel:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\na=ssrc:3611041506 label:1f05dacf-9044-4f52-8823-6a48d5ac4e47\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 124 127 123 125\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:vu+3\r\na=ice-pwd:aqMVjGj1Hz8ziy3PB+I1QY3y\r\na=ice-options:trickle\r\na=fingerprint:sha-256 F3:66:9C:C3:2D:0B:90:17:47:BB:30:B3:6D:F5:24:5C:87:E8:71:56:D1:C0:00:7D:08:CB:AA:84:18:98:6E:71\r\na=setup:active\r\na=mid:video\r\na=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:4 urn:3gpp:video-orientation\r\na=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=sendrecv\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 H264/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:102 H264/90000\r\na=rtcp-fb:102 goog-remb\r\na=rtcp-fb:102 transport-cc\r\na=rtcp-fb:102 ccm fir\r\na=rtcp-fb:102 nack\r\na=rtcp-fb:102 nack pli\r\na=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:124 rtx/90000\r\na=fmtp:124 apt=102\r\na=rtpmap:127 red/90000\r\na=rtpmap:123 rtx/90000\r\na=fmtp:123 apt=127\r\na=rtpmap:125 ulpfec/90000\r\na=ssrc-group:FID 4142159662 3050859437\r\na=ssrc:4142159662 cname:reYQqYdSFjANuTK6\r\na=ssrc:4142159662 msid:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR fe5233ce-203d-42e0-8e1a-19c2745781b8\r\na=ssrc:4142159662 mslabel:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\na=ssrc:4142159662 label:fe5233ce-203d-42e0-8e1a-19c2745781b8\r\na=ssrc:3050859437 cname:reYQqYdSFjANuTK6\r\na=ssrc:3050859437 msid:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR fe5233ce-203d-42e0-8e1a-19c2745781b8\r\na=ssrc:3050859437 mslabel:Q9o54prg6ybvH4j9gouzeNZhyxfEAvSFNuQR\r\na=ssrc:3050859437 label:fe5233ce-203d-42e0-8e1a-19c2745781b8\r\n"}}}
rev服务端收到 客服端0 消息:	{"event":"_ice_candidate","data":{"candidate":{"candidate":"candidate:2201212986 1 udp 2113937151 172.18.1.229 49635 typ host generation 0 ufrag vu+3 network-cost 50","sdpMid":"audio","sdpMLineIndex":0}}}
send服务器发送给 客服端1 消息:{"event":"_ice_candidate","data":{"candidate":{"candidate":"candidate:2201212986 1 udp 2113937151 172.18.1.229 49635 typ host generation 0 ufrag vu+3 network-cost 50","sdpMid":"audio","sdpMLineIndex":0}}}

 

 

webrtc多人在线视频通讯

服务端采用spootboot实现websocket

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <!-- webstock相关依赖包. -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.json/json -->
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180130</version>
        </dependency>

客服端webrtc

//兼容不同浏览器获取到用户媒体对象
    var getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.mediaDevices.getUserMedia);

var sessionList=[]
    var pcList=[];//建立多个PeerConnection实现相互之间的点对点
    function createPeerConnection(clientID) {
        //兼容不同浏览器客户端之间的连接
        pcList[clientID] = new (window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection || window.mozRTCPeerConnection);
        //兼容不同浏览器
        sessionList[clientID] = (window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription);

        pcList[clientID].addStream(localhostStream);
        // 发送ICE候选到其他客户端
        pcList[clientID].onicecandidate = function (event) {
            if (event.candidate !== null) {
                websocket.send(JSON.stringify({
                    "event" : "_ice_candidate",
                    "clientId" : myID,
                    "roomID" :roomID,
                    "respon" :clientID,
                    "data" : {
                        "candidate" : event.candidate
                    }
                }));
            }
        };
        // 如果检测到媒体流连接到本地,将其绑定到一个video标签上输出
        pcList[clientID].onaddstream = function (event) {
            var node=document.createElement("video");
            node.setAttribute("width",640);
            node.setAttribute("height",480);
            node.setAttribute("autoplay","autoplay");
            node.setAttribute("id","video"+clientID);
            node.setAttribute("src",URL.createObjectURL(event.stream));
            document.getElementById('videoList').appendChild(node);
        };
        //return pcList[clientID];
    }

 

相关标签: webRtc