WebRTC (Web Real-Time Communication) is an open network and it consists of a set of Application Program Interfaces (APIs) which provide us with real-time communication between web browsers. It supports voice, and video communication and generic data can be sent directly between peers, which doesn’t require any external applications or plug-ins to be installed. WebRTC is used in many apps because these APIs are supported on both Mobile and Desktop.
WebSockets are used for audio, and video communication between the two browsers. If the transfer of data is possible by using websockets then why do we need webRTC?
- WebSocket uses TCP (Transmission Control Protocol) and webRTC uses UDP (User Datagram Protocol) communication for transmission of data.
- The data sent through TCP is more reliable whereas the data sent with UDP provides high speed, good effeciency and the connection between the peers is very smooth.
- For the data to be efficient and speed we prefer webRTC
How WebRTC works?
When the users in two different browsers need to communicate with each other they require an exchange of information. So, the Signalling Server is used for processing information. Peer1 sends a request to the server and the required metadata to connect with Peer2. The server sends the request to Peer2 and gets the response from it and sends the response to Peer1.Here the direct connection is established between Peer1 and Peer2. If the peers are in different IP (Internet Protocol) networks and has NAT (Network Address Translation) firewalls it prevents RTC.
This Interactive Connectivity Establishment (ICE) framework tries to make connections and finds the best path to connect with peers by using the host IP address. If the ICE doesn’t make it then uses Session Traversal Utilities for NAT (STUN) and Traversal Using Relays around NAT(TURN) servers. STUN allows users to find the type of NAT and the public IP address they are behind. This STUN enables the given IP address to translate into a public IP address and the connection will be established between the peers. But there are some networks that are restrictive to STUN Server and the IP addresses cannot be translated. In such cases, we use TURN servers to relay the traffic between the peers and establish a direct connection.
APIs used by WebRTC
getUserMedia: Access the device's camera and microphone.
RTCPeerConnection: Creates audio and video communication between the peers.
RTCDataChannel: It helps in transferring data between the peers bi-directional.
What we did at PracticeVantage
Customer WebRTC is a community page that consists of the Start button to initiate the call. When the call is initiated the customer sends the Customer Connection Info (Customer SDP, ICE Candidates) and a record will be created under the AudioVideoRequest object on the salesforce page.
The Agent on the Salesforce side accepts the request that was initiated by the customer. When the request was accepted it creates an Agent Connection Info (Agent SDP, ICE Candidates) and it was sent to the customer.
The connection will be established and audio, video, and data can be transferred between the peers. When the connection is established screensharing, file transfer and recording of media can also be done between the peers.