Try Live Demo

Hello Friends, It’s always very exciting to see a calling application like (Skype, Telegram, WhatsApp, etc.) where people get connected over the internet. Just find the person who is online and with a click you get connected with them.

As we know that AMS provides ultra-low latency streaming solutions. So can we have such a calling feature in AMS? Yes, we can have such a feature and today I am going to introduce how we can achieve this on top of AMS.

What is a Call To Peer Application? 

In the existing system of AMS, peers can communicate with each other with WebRTC but there is no authentication between peers. I mean there is no interaction between peers before the WebRTC connection establishment. So any peer can connect to a call initialized by a peer without authentication in AMS.

Call to Peer application adds such an authentication mechanism on top of AMS in peer-to-peer connection.

In this mechanism, Call To Peer Application uses Socket.io and Node.js to achieve authentication between peers before the WebRTC connection.

Socket.Io

socket.io is a javascript library that facilitates real-time, event-based bi-directional communication. It supports almost every platform and device. This library is having two separate parts i.e client side and the server side.

In the suggested solution, we will use node.js in the same server on which AMS is already running.

We also provide a war file in which all resources like socket.io and WebRTC implementations are available.

How does this call feature work?

  • The First peer (let’s say Rahul) joins the room as usual by clicking on the join button and waits for the second peer (let’s say, Burak).
  • When Burak clicks to join button, an authentication to call request message is sent to Rahul over the socket.
  • Rahul gets the request from Burak (a ringing sound gets played in the background as well). He accepts or declines the request and sends his decision to Burak over the socket.
  • Burak gets Rahul’s response and if he is granted the acceptance permission then the WebRTC connection is established. Otherwise, in case of a call decline response, Burak is alerted with a declined message.
CallToPeerApp

Call To Peer App

Installing Call to Peer Application on AMS

Step 1. Download the application war file from here.

Step 2. Connect to AMS Console.

Step 3. On the Dashboard page click the New Application button, click Choose File button browse to the downloaded war file. Give a name (lets write CallToPeer) to your application and click Create button.

Step 4. Go to the app installation directory

cd /usr/local/antmedia/webapps/CallToPeer/node

Step 5. Run the command to install dependencies:
npm install

Step 6. Start node (Keep the terminal running).

node index.js

How to use Call to Peer Application

Step 1. Open the Call to Peer Application index.html page:

https://AMS_URL:5443/CallToPeer/index.html

You will see the page below

webRTC-peer-to-peer

Step 2. Join the room by clicking on the Join button.

Step 3. Now open index.html as the second peer from another device or another tab in the (same) browser.

Step 4. Now try to join the same room “stream1” by clicking on Join button. Here a request is made from peer2 to peer1 requesting room join.

incoming-call

Step 5. Go to the first peer page and Accept the request, you will see the WebRTC connection is established.

Conclusion

You can try different approaches to achieve your application goal. Socket.io can be used in any application where event-based communication is required.

You can also try socket.io with AMS for such application development like :

  • Applications like skype.
  • Game development.
  • Private, Group messaging while on a conference call.
  • Notification system.

You can read more about socket.io for its advantage and implementation

In this post, I tried to introduce the Call To Peer Application with this call feature as a prototype solution. You can get the complete source code and the implementation details from my repository.

If you liked the post, please do share, or in case of any questions/feedback, write a comment. Will be happy to revert back.

Categories: Tutorial

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.