This project shows how to use Web-RTC technology and create a live video chat room based on the new tomcat 7 Websockets API and HTML5 Web-RTC. The server runs a single page where many users can login and chat with one another. Each user sees the same page with the videos of all other participants.
THIS IS NOT A FULL DIY TUTORIAL, IF YOU NEED HELP CONTACT ME
WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs.
I can’t really remember the exact version.
The Client Side Code
ASSUMING YOU HAVE A TOMCAT SERVER UP AND RUNNING
Setting up a websocket server on the client side – this is the websocket which handles all the messaging between the users. I’ll use a separate websocket server for the video streams.
- Create new WebSocket instance
- Bind a message receive handler which executes each time a message arrives from the server
- Define a send message function to send messages from the client
- Define a close connection function – should be called when the user closes the window or exits
The video streams socket works almost the same with a few adjustments
I defined two websockets. One is for controlling the messaging between clients (chat messages, join room requests etc) and one for streaming the video between the peers. I could have done it with only one socket, but due to performance issues I chose to separate them so each socket is doing less job.
The Server Side Code
This code is in charge of the chat room creation and users management. Each user sends a join request to the room admin, the admin send an approve or decline answer back to the user. The Server holds an Object with all the rooms and for each room, a list of the current participants. Video streams are passed from a client to a client directly, where all other messages are passed from a client to a client through the server.
In this tutorial I tried to show the basic concepts and ideas for creating a live video chat rooms, those chat rooms can be extended to many other purposes (online games, chats, online help etc). I chose to publish only the major key classes and functionality so don’t expect to just Ctrl-C Ctrl-V (:
However, I’m always available for questions and clarifications.