当前位置:网站首页>One development skill a day: how to establish P2P communication based on webrtc?
One development skill a day: how to establish P2P communication based on webrtc?
2022-06-24 08:38:00 【Tsingsee green rhino video】
at present EasyGBS The platform has been supported Webrtc The video stream of the protocol is output , It's a great progress for us .webrtc timeliness 、 The advantage of low delay can make the video output industry reach a new height , In this article, we mainly share with you the development process webrtc establish P2P The process of , The process is mainly divided into two parts , One is the initiator , One is the receiver , Let's explain the operation of these two parts in detail .
Originator
a、 The initiator creates websocket A long connection .
b、 establish PeerConnection object , And mainly monitor onicecandiate、addstream and onconnectionstatechange Method .onicecandiate The method is data collection , Through websocket Send it to the receiving end for processing PeerConnection Of addIceCandiate Method to save and set ;addstream The method is to get the remote stream and play it ;onconnectionstatechange The way is PeerConnetion Remote connection status (connectioned Represents a successful connection ,disconnected Represents disconnection ).
c、 Turn on the local audio and video device , And add audio and video to PeerConnection On the object , What is used is addStream or addTrack( This method can only add a single stream , You can use this method twice to add multiple streams ) Method .
d、 Use PeerConnection Of createOffer Method to get SDP Information ,SDP Including various audio and video codec, encryption and other related parameters .
e、PeerConnection Of setLocalDescription Method change SDP Save the settings , Through websocket The server sends it to the receiver .
f、 The initiator receives the message sent by the receiver SDP Information , And pass PeerConnection Of setRemoteDescription Method to save the settings .
g、 In this way, we can communicate with each other .
The receiver
a、 The receiver creates websocket A long connection .
b、 establish PeerConnection object , And mainly monitor onicecandiate、addstream and onconnectionstatechange Method .onicecandiate The method is data collection , Re pass websocket Send it to the receiving end for processing PeerConnection Of addIceCandiate Method to save and set ;addstream The method is to get the remote stream and play it ;onconnectionstatechange The way is PeerConnetion Remote connection status (connectioned Represents a successful connection ,disconnected Represents disconnection ).
c、 Turn on the local audio and video device , And add audio and video to PeerConnection On the object , What is used is addStream or addTrack( This method can only add a single stream , You can use this method twice to add multiple streams ) Method .
d、 Receive the... Sent by the sender offer SDP Information , Re pass PeerConnection Of setRemoteDescription Method to save the settings .
e、 In the use of PeerConnection Of createAnswer Method to get SDP Information ,SDP It also contains various audio and video related parameters . And pass websocket The server sends it to the initiator .
f、 Receive the... Sent by the initiator SDP Information , And pass PeerConnection Of setRemoteDescription Method to save the settings .
So you can communicate with each other .
summary
1、a~c The steps are the same ;
2、 Set each other's SDP and ICE Information ;
3、 monitor PeerConnection Of addstream To get the remote stream ;
4、 The following is my summary of the main flow chart .
边栏推荐
- pyQt 常用系统的事件
- LabVIEW finds prime numbers in an array of n elements
- 新技术实战,一步步用Activity Results API封装权限申请库
- lombok 使用
- Qt导出PDF文件的两种方法
- Three ways to uninstall Symantec Endpoint Protection Symantec
- leetcode 1268. Search Suggestions System(搜索推荐系统)
- 普通token
- Five level classification of loans
- Common CVM transcribes audio using virtual sound card
猜你喜欢

Markdown 实现文内链接跳转

Understanding of the concept of "quality"
![[untitled]](/img/94/792e8363dbfe67770e93b0dcdc8e72.png)
[untitled]

ZUCC_编译语言原理与编译_实验03 编译器入门

12--合并两个有序链表

一文带你了解Windows操作系统安全,保护自己的电脑不受侵害

ZUCC_ Principles of compiling language and compilation_ Experiment 08 parsing LR parsing

问题4 — DatePicker日期选择器,2个日期选择器(开始、结束日期)的禁用

PAT 1157:校庆

A preliminary study of IO model
随机推荐
Variable declaration and some special variables in shell
【关于运维和网工的差别,一文说透】
[acnoi2022] I have done it, but I can't
[graduation season] Hello stranger, this is a pink letter
JS merge multiple objects and remove duplicates
分布式 | 如何与 DBLE 进行“秘密通话”
[explain the difference between operation and maintenance and network engineering]
orb slam build bug: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv‘
[real estate opening online house selection, WiFi coverage temporary network] 500 people are connected to WiFi at the same time
[acnoi2022] not a structure, more like a structure
5 minutes, excellent customer service chat handling skills
JS scroll div scroll bar to bottom
05-ubuntu安装mysql8
How to configure networkpolicy for nodeport in kubernetes
成为IEEE学生会员
Blue screen error UNMOUNTABLE boot volume of the solution
Tencent cloud ASR product PHP realizes real-time voice authentication request
5分钟,客服聊天处理技巧,炉火纯青
Pyqt common system events
Introduction to NC machine tool programming [G-code]