Upload
mohamed-amr
View
257
Download
0
Embed Size (px)
DESCRIPTION
how to make a peer to peer video conference system using webRTC APIS
Citation preview
Video Conference Our goal is to make a Video Conference system in our solution such that developers can communicate with each other. Therefore, we first try the most common solution which is using flash player at the client side and streaming server at the server side.
OpenTokOne of the famous platforms that implement
this architecture is OpenTok which allows developers to integrate live, face-to-face video directly into their own website.
However, OpenTok is not free and very expensive to use it inside a social network that may contain thousands of users.
Streaming server vs peer to peerTherefore, we think about building our own
system but the problem was that streaming server is very expensive too.
We try to found a peer-to-peer solution without a streaming server so that each browser can send and receive stream from other browser peer to peer so we can save the cost of using expensive streaming server.
WebRTC (Real Time communication)WebRTC has implemented three APIs
◦ 1. MediaStream API (getUserMedia) ◦ 2. RTCPeerConnection ◦ 3. RTCDataChanal
MediaStream API (getUserMedia)
getUserMedia is available in Chrome, Opera and Firefox Nightly/Aurora and can be used in Internet Explorer using Chromo Frame plugin.
the getuserMedia API is responsible for access the camera and microphone .presents synchronized streams of media.
For example, a stream taken from camera and microphone input has synchronized
video and audio tracks.
The getUserMedia() method takes three parameters: ◦ 1. Constraints object. ◦ 2. A success callback which, if called, is
passed a LocalMediaStream. ◦ 3. A failure callback which, if called, is
passed an error object.
Here is some sample code
Signaling: Session Control, Network and Media Information
WebRTC uses RTCPeerConnection to communicate streaming data between browsers (peers), but also needs a mechanism to coordinate communication and to send control messages, a process known as signaling.
1-First choice is to use XHR and the Channel
API as the signaling mechanism (google app engine) and this is the easy way and most common used but it is not free and you have to pay to use this service.
2-Second choice is to implement signaling mechanism on your server using websockets
WebSockets using node.jsNode.js is a platform built on Chrome's
JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Node.js is used to run JavaScript without a browser so you can use it to create a server
side application and create WebSockets.
Implemetation of WebSockets
java Node.js
pro - A multi-threaded language. - It is an old language, have a good community and there are many resources on the internet. - It is a strong typed language with can save a lot of error and java good IDEs.
- It is built completely on asynchronous callback architecture when it receive a request it execute it in a callback function asynchronous on another thread so we create thread only when we execute callback function not for every connection like java.
con It is a multithread language and every connection to a WebSocket will need a thread this will need a high performance server.
- Node.js use JavaScript which is not strong typed language which can cause a lot of errors. - Very difficult to debug.
Our decisionWe decided to use node.js platform because
it is very efficient and doesn’t need a high performance server so we can save the costs.
ScenarioStep 1: Each user connect to a socket on the
server using socket.io API.
Step 2: We need to add some data in sockets
at the server side so we can identify who is connected on the server, who is online, and busy.
Socket is JSON object we add the following data to it
1-Socket.devos.username=null; 2-Socket.devos.reciever=null; 3-Socket.devos.status=0;
Step 3: 1. If we want to send a message to a user you
have to add some header data which are the sender user_id and the receiver user_id so at the server read the message and search to the reciever socket by user_id and forward the message to the receiving user.
2. assume that browser 1 is Alice and browser 2 is Bob .Alice want to make a video call with Bob so she first send a message that contain her user_id as a sender and Bob user_id as a receiver and type of the message is call_request.
3. Then Bob response with a message contain his user_id as a sender and Alice user_id as a receiver and message type call_response and action is accept
Step 4: After Alice receive Bob response 1. she create a peer connection and create and offer and send
it to Bob as session description which contain information about the video format and other data.
2. Bob receive the session description offer and create a peer connection and add the remote session description to the peer connection and then create and answer as session description and send it back to Alice.
3. Bob use the ice server framework, which used in webRTC peer connection API to get the shortest path to Alice and send here his IP and port number as message called candidate message.
4. Alice receive the answer session description and add it as a remote session on her peer connection.
5. Alice use the ice server framework which used in webRTC peer connection API to get the shortest path to Bob and send here his IP and port number as message called candidate message.
6. Peer connection complete setup after both of them receive the candidate message the a stream flow peer to peer between them.