@[TOC](WebRTC Research (ii) Example Demo)
1. Introduction of WebRTC
Webrtc official website WeBRTC’s instructions for iOS use
2.WebRTC obtains the video stream Demo
2.1 the WEBRTC structure
2.1.1 The complete WebRTC framework is divided into two parts: Server side and Client side.
- Server side:
The Stun server
: The server obtains the external network address of the deviceTurn the server
: The server is used to relay communications after a point-to-point failureSignaling server
: Is responsible for end-to-end connections. At the beginning of connection, both ends need to exchange signaling, such as SDP and candidate, through signaling server. - Client has four applications: Android
iOS
PC Broswer
2.1.2 Introduce WebRTC’s three main apis and the process of implementing point-to-point connection.
MediaStream
: The MediaStream API provides synchronous streaming of video and audio through the device’s camera and microphoneRTCPeerConnection
: RTCPeerConnection is WebRTC’s component for building stable, efficient flow between pointsRTCDataChannel
: RTCDataChannel enables browsers (point-to-point) to establish a high-throughput, low-latency channel for transmitting arbitrary data. Among themRTCPeerConnection
Is the core component of our WebRTC.
##WEBRTC connection flow chart
2.1.3 WeBRTC connection process description
The main process is shown in the figure above, and the specific process is described as follows:
- The client establishes a TCP long connection with the server through the socket, which I used here
CocoaAsyncSocket
Third-party frameworks connect to socketsGithub.com/robbiehanso… - The client sends an OFFER SDP handshake through the signaling server
The SDP (Session Description Protocol) : SDP is created by PeerConnection in weBRTC framework. For details, please refer to my demo.
3. The client uses the signaling server to initiate the Candidate handshake
Candidate: Mainly contains IP information of related parties, including IP of local area network, public network, TURN server, STUN server, etc. Candidate is created through PeerConnection in weBRTC framework. For details, please refer to my demo.
- After the client successfully shakes hands with the Candidate in SDP, it establishes a P2P end-to-end link, and the video stream can be directly transmitted without going through the server.
2.1.4 THE SDP handshake process is similar to the Candidate handshake process, but a little complicated. The following is a brief description of the SDP handshake process:
2.1.5 A demo can help you to sort out the whole set of WEBRTC audio and video communication:
A comprehensive analysis of several relatively good domestic and foreign demo, absorb their advantages, now share with you. (* Many domestic demo code quality is relatively poor and many of them can not run, most of them developed with OC, foreign relatively good)