You may have heard of WebSockets and how powerful they can be. What are they? Essentially WebSockets allow you to open an interactive connection between the server and the client in HTML5 apps. This allows you to make API calls without everything having to go through the server. Quite useful! Especially since this is a low-latency technique that can be used in conjunction with the very low-latency video streaming on Red5 Server. Here are few tips for using WebSockets on Red5.

  1. The WebSocket chat is a great example that you can use to bridge Flash clients and WebSocket clients. Notice how router context is used to route messages between SharedObjects and WebSocket clients.

  2. Remember that in Java these are just 2 objects ApplicationAdapter <=> WebSocketDataListener (see chat example). They exist in the same context governed by red5-web.xml. You can easily setup message passing communication link between then with some programming. Just see the chat example and see how web.handler and WebSocket listener are registered in spring. Then think how to connect them.

  3. You can create a proxy to help each site execute a method on the other side which may conform to a common interface (deal).

  4. Unlike Red5 scopes WebSockets do not really have ws://localhost:8081/chat/room1/room2 (wont work)

  5. Think of it as a Single level application where there is no depth and create scopes yourself using query params. See this for example.

  6. Instead of thinking of scopes as /room/room2 think like ?room=myroom or ?room=myroom&room=room2 (the later is an array of 2 items defining depth in order as the names appear)

  7. Now use shared objects wisely to spawn as many rooms you want at a single level. name = so+room1, name = so+room1+room2 etc:

  8. WebSockets will also be able to give you the room params as discussed before. (6)

  9. Finally, create your own logic to join both worlds using the unique string that identifies the same room from flash and webSockets. Then make use of the Router concept (as shown in chat example) to relay messaged between the two types of clients for the same room.

Now this is useful with Flash based streaming apps and all, but just imagine all you can do with the Red5Pro WebRTC release coming later this summer! If you are interested in getting early access to the WebRTC beta, then send us an email.

Happy Coding!

  • Share: