-
Notifications
You must be signed in to change notification settings - Fork 637
How to Create WebRTC Peer To Peer Communication
Attention: We have migrated our documentation to our new platform, Ant Media Resources. Please follow this link for the latest and up-to-date documentation.
NOTE: We have updated our documentation. This page is outdated. You can access updated version from the sidebar menu.
Let’s have look at WebRTC Peer-to-Peer Communication procedure.
For WebRTC Peer-To-Peer Communication, two clients create a direct connection between each other after completing signaling operations. First, both clients get media sources. Then one of them starts signaling procedures. As stated in the below figure, Browser 1 creates an SDP offer and sends to another side. Browser 2 gets that offer and creates an SDP answer and sends to Browser 1. After the SDP change phase, Browser 1 sends Ice Candidate to its peer then Browsers send Ice Candidate also. These sendings are performed several times until they get the required network information of another part. Finally, they create direct WebRTC communication between them.
(* Retrieved from https://developer.mozilla.org/en-US/docs/Web/Guide/API/WebRTC/Peer-to-peer_communications_with_WebRTC)
Ant Media Server supports WebRTC Peer-To-Peer communication in addition to 1-N and N-N communication. Mobile (Android, IOS ) and Web (JS) SDKs provide P2P communication functionalities to developers. The steps of WebSocket messaging mechanism to create WebRTC P2P connections are described below;
1. Peers connect to Ant Media Server through WebSocket.
ws://SERVER_NAME:5080/WebRTCAppEE/websocket
2. The client sends join JSON command to the server with stream name parameter.
{ command : "join", streamId : "stream1", }
3. When the second peer joins the stream, the server sends start JSON command to the first peer
{ command : "start", streamId : "stream1", }
4. The first peer create offer SDP and send to the server with takeConfiguration command,
{ command : "takeConfiguration", streamId : "stream1", type : "offer",
sdp : "${SDP_PARAMETER}" }
5. The second peer creates answer SDP and sends to the server with takeConfiguration command
{ command : "takeConfiguration", streamId : "stream1", type : "answer",
sdp : "${SDP_PARAMETER}" }
6. Each peer gets ice candidates several times and sends to each other with takeCandidate command through the server.
{ command : "takeCandidate", streamId : "stream1", label : "${CANDIDATE.SDP_MLINE_INDEX}", id : "${CANDIDATE.SDP_MID}", candidate : "${CANDIDATE.CANDIDATE}" }
7. Clients send leave JSON command to leave the room
{ command : "leave", streamId: "stream1" }
- Introduction
- Quick Start
- Installation
- Publishing Live Streams
- Playing Live Streams
- Conference Call
- Peer to Peer Call
- Adaptive Bitrate(Multi-Bitrate) Streaming
- Data Channel
- Video on Demand Streaming
- Simulcasting to Social Media Channels
- Clustering & Scaling
- Monitor Ant Media Servers with Apache Kafka and Grafana
- WebRTC SDKs
- Security
- Integration with your Project
- Advanced
- WebRTC Load Testing
- TURN Servers
- AWS Wavelength Deployment
- Multi-Tenancy Support
- Monitor Ant Media Server with Datadog
- Clustering in Alibaba
- Playlist
- Kubernetes
- Time based One Time Password
- Kubernetes Autoscaling
- Kubernetes Ingress
- How to Install Ant Media Server on EKS
- Release Tests
- Spaceport Volumetric Video
- WebRTC Viewers Info
- Webhook Authentication for Publishing Streams
- Recording Streams
- How to Update Ant Media Server with Cloudformation
- How to Install Ant Media Server on GKE
- Ant Media Server on Docker Swarm
- Developer Quick Start
- Recording HLS, MP4 and how to recover
- Re-streaming update
- Git Branching
- UML Diagrams