In this article we are going to create a video calling app with Janus WebRTC server and SFU
We are also going to learn about Metered.ca SFU and why it is a better option than Janus Server
Janus is an Open source, general purpose WebRTC SFU server. It is a modular gateway that facilitates real time communication apps by handling the complex WebRTC protocols and provide a stable server for the purposes of media exhange
Modular architecture: Janus has a plugin based system where each plugin has some specific functionality. This modularity allows for customization and extention
Protocol handling: Janus manages signaling and negotiation that is required for establishing webrtc connections.
Interoperability: Janus supports media codecs and is compatible with different clients and browsers thus Janus has broad compatibility
Scalability: Designed to handle multiple connections efficiently, Janus is scalable within a specific geographical zone. (that is it will work fine if all the users that are using Janus are within a small geographic zone)
A SFU or a Selective Forwarding Unit is a media server architecture that is used in WebRTC apps to efficiently route media streams between different media participants
The SFU receives incoming video streams from each participant and then selectively forwards the streams to other participants as requested.
That is each participant receives the streams that the participant request while all the participants push their streams to the SFU
Scalability: SFU can handle a large number of connections because the SFU does not involve in computational intensive tasks such as encoding and decoding, instead just forwards the streams to the users
Low Latency: The SFU forwards the streams without processing thus leading to low latency. But if your users are all over the world you need a global distributed SFU service such as metered.ca cloud sou
Bandwidth Optimization
Flexibility and Control: Participants have a greater flexibility over what they want to receive, for example if they want to receive just audio or receive video streams of select participants then they have the option to do that
Cost Efficiency: Since SFU require less processing as compared to MCU a smaller instance on the cloud can work for you
Preservation of the quality of media: SFU preserve media quality because they do not do any processing on the media streams just forwards the streams to requested participants.
Easier implementation of Advanced features
Improved Reliability: With no processing of media on the server, there are fewer points of failure . SFU can also be clustered for redundancy, thus making sure that the services remain live even if one server encounters any issue.
Integrating Janus SFU in your app involves these steps. Here is step by step process to implement Janus in your application.
System Preparation
GLib zlib pkg-config Jansson libconfig libnice (at least v0.1.16 suggested, v0.1.18 recommended) OpenSSL (at least v1.0.1e) libsrtp (at least v2.x suggested)
you can easily install these dependencies on ubuntu or Debian like
apt install libmicrohttpd-dev libjansson-dev \ libssl-dev libsofia-sip-ua-dev libglib2.0-dev \ libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev \ libconfig-dev pkg-config libtool automake
Download and Build Janus
GLib zlib pkg-config Jansson libconfig libnice (at least v0.1.16 suggested, v0.1.18 recommended) OpenSSL (at least v1.0.1e) libsrtp (at least v2.x suggested)
apt install libmicrohttpd-dev libjansson-dev \ libssl-dev libsofia-sip-ua-dev libglib2.0-dev \ libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev \ libconfig-dev pkg-config libtool automake
git clone https://github.com/meetecho/janus-gateway.git
cd janus-gateway
sh autogen.sh
Configure Janus
Edit the config files
Enable the needed plugins
Setup SSL Certificate
Generate SSL certificate
Update configuration
Start the Janus Server
./configure --prefix=/opt/janus
Verify Operation
Set Up the Development Environment
Choose a front end framework
Include WebRTC libraries
Establish Signalling Server
Create or Join a video room
Handle local media streams
make sudo make install sudo make configs
Attach the local stream to the video element in the HTML to play the stream to the user
5. Publish to Janus
Use the RTCPeerConnection to create an SDP offer
Send the offer to Janus using the API
Receive the SDP answer from the Janus and set it as remote description
6. Subscribe to remote streams
Handle the joined and event messages to listen to notifications from other meeting participants
Create the Peer connections for subscribers, that is for each remote participant you need to create a new RTCPeerConnection
Handling remote streams, get the remote streams and attach them to HTML video elements to play to video on the users web browser
Implement event listener and Handlers
Metered Global Cloud SFU is a cloud based Selective Forwarding Unit by Metered.ca
With Metered SFU developers can build any type of application including video, audio and data transmission
The Metered SFU runs using native WebRTC API and HTTP without the need for any proprietary SDKs.
Users are also automatically routed to the nearest SFU based on their geographical location
Multiple SFU are connected globally with each other using high speed interconnect, ensuring lowest possible latency
Global Distribution:
Platform Independence
Flexible Publish-Subscribe Model:
Scalability
Cost Efficiency:
Establishing a Connection
GLib zlib pkg-config Jansson libconfig libnice (at least v0.1.16 suggested, v0.1.18 recommended) OpenSSL (at least v1.0.1e) libsrtp (at least v2.x suggested)
b. Send Local SDP offer
c. Receive SFU remote SDP
d. Connection Established
GLib zlib pkg-config Jansson libconfig libnice (at least v0.1.16 suggested, v0.1.18 recommended) OpenSSL (at least v1.0.1e) libsrtp (at least v2.x suggested)
Publishing a Track
apt install libmicrohttpd-dev libjansson-dev \ libssl-dev libsofia-sip-ua-dev libglib2.0-dev \ libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev \ libconfig-dev pkg-config libtool automake
b. Generate and Send SDP offer
Send the updated SDP offer to the SFU
Receive and set the SFU response to the SDP
Subscribing to a Track
Request the track subscription from the SFU
Scalability
Media distribution
Large Scale streaming
Platform Independence
Flexible Publish Subscribe model
Cost Efficiency
Global SFU Network:
Deployment and Maintenance
Metered SFU:
Janus
Scalability and Performance
Metered SFU
Janus
Cost Structure
Metered SFU
Janus
Flexibility and Features
Metered SFU
Janus
Ease of Integration
Metered SFU
Metered TURN servers
API: TURN server management with powerful API. You can do things like Add/ Remove credentials via the API, Retrieve Per User / Credentials and User metrics via the API, Enable/ Disable credentials via the API, Retrive Usage data by date via the API.
Global Geo-Location targeting: Automatically directs traffic to the nearest servers, for lowest possible latency and highest quality performance. less than 50 ms latency anywhere around the world
Servers in all the Regions of the world: Toronto, Miami, San Francisco, Amsterdam, London, Frankfurt, Bangalore, Singapore,Sydney, Seoul, Dallas, New York
Low Latency: less than 50 ms latency, anywhere across the world.
Cost-Effective: pay-as-you-go pricing with bandwidth and volume discounts available.
Easy Administration: Get usage logs, emails when accounts reach threshold limits, billing records and email and phone support.
Standards Compliant: Conforms to RFCs 5389, 5769, 5780, 5766, 6062, 6156, 5245, 5768, 6336, 6544, 5928 over UDP, TCP, TLS, and DTLS.
Multi‑Tenancy: Create multiple credentials and separate the usage by customer, or different apps. Get Usage logs, billing records and threshold alerts.
Enterprise Reliability: 99.999% Uptime with SLA.
Enterprise Scale: With no limit on concurrent traffic or total traffic. Metered TURN Servers provide Enterprise Scalability
5 GB/mo Free: Get 5 GB every month free TURN server usage with the Free Plan
Runs on port 80 and 443
Support TURNS SSL to allow connections through deep packet inspection firewalls.
Supports both TCP and UDP
Free Unlimited STUN
The above is the detailed content of Janus WebRTC server and SFU: a real time video calling app. For more information, please follow other related articles on the PHP Chinese website!