Saturday, February 8. 2014
RTC Data Channels
Today's entry is again about the Web Real Time Communication (WebRTC), the new API to enable P2P video and audio between browsers. In two previous entries the WebRTC demo application was presented (python web application developed by google and mozilla in order to test their respective implementation and the interoperability between them) and then the sample application was modified to use glassfish 4 instead of python as the server (glassfish 4 was chosen because it has the WebSocket implementation standardized by JavaEE 7). In this third entry of the series a new concept is going to be introduced: RTC Data Channels.
Obviously in a common WebRTC use (audio and video communication) there are specific data channels to send and receive the steaming audio and video information, but the specification provides a way to obtain a general purpose P2P bi-directional data channel to send whatever information. Obviously WebRTC tries to replace any previous communication application and this type of channels are absolutely necessary (sending files, chat applications,...). Here you have a very detailed link about data channels in bloggeek.me if further information is needed.
I started testing this feature using the following simple application. It is a simple html file which creates two RTCPeerConnection and establishes a data channel between them for sending text and files. The same page represents both ends (the sender and the receiver). The code is prepared to work with chrome but with minimal changes it can also be tested with firefox.
After testing with the previous and simple example, I decided to enhance my glassfish application in order to create a chat system. Now there is a new chat.xhtml page which creates the RTC data channels (the RTCPeerConnection is established in the same way as before). The channel is used to send the messages between the peers. The application works well inside my home network between two firefox browsers (iceweasel 24.2 or current firefox 26.0) and chromium (31.0.1650.63) but it does not work when the browsers are mixed. When the channel is opened in one side the callback at the other side is not triggered, so the connection is never established when the browsers are different. The little application can also exchange files between the peers but the file is transmitted as a single chunk, that produces errors when the file is big enough. If you recheck the previous link from bloggeek.me there is a maximum transmission data size in chrome and if the file is too big errors are displayed (it seems that firefox supports bigger chunks but problems are also reported).
Although the application is very simple and a bit sloppy, it is a good example of a RTC data channel. Here it is a video where two browsers inside the same laptop connect using the glassfish apprtc application and start chatting. The process is exactly the same than in the video example: one user connects to the page and remains there waiting for the other partner to join; the second user connects to the same URL (same room); the negotiation starts using the glassfish server as intermediary; when the peer connection is established a data channel between them is created; then chatting and exchanging files can proceed.
Some time ago I presented some entries about integrating VOIP in a portal (skype first and then an opensource pidgin solution), if you recheck the current series about WebRTC, now it is possible to replace the previous off-browser idea with a browser-only solution. The current implementation and the specification itself is not mature, WebRTC should be fully implemented by the major browsers and the interoperability should be assured, but the apprtc application, although simple and sloppy, is the perfect proof that all the required features are covered by the specification (video, audio, chat, exchanging files,...). The browser is the VOIP device and the server (glassfish in my example) is just a way of making the peers know each other. I suppose that sooner than later some JS projects will appear implementing a fully WebRTC device or, at least, making WebRTC easier to integrate in a final project. Here you have the modified apprtc project for glassfish with the chat page integrated.
Readapting an old slogan: the browser is the computer.
Comments