Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (40 sloc) 2.82 KB
@author Max Lapshin <> []
@copyright 2009 Max Lapshin
@reference See <a href="" target="_top"></a> for more information
@title Push channel in ErlyVideo
@doc Erlyvideo provides push channel from server to connected clients.
Sometimes it is better to use comet-like solutions with long-poll for push channel, but sometimes it is impossible,
because long-poll sometimes hang browser and it is incompatible with video, playing in browser. Also, cross-domain
long-poll is very, very hard to implement correctly.
Erlyvideo has builtin support for this. It uses RTMP channel to push data back to client.
To enable it, you must do following:
1) Create signed session for flash player and include "user_id" and "channels" in it. Session must be constructed in the following way:
a) prepare JSON session
b) base64 this session
c) SHA1-MAC(base64(json_session), secret_key), secret_key is provided in ebin/ and default one is in src/
d) base64(json_session) + "--" + SHA1-MAC(base64(json_session), secret_key)
Reference example
a) {"channels" : [10, 12], "user_id" : 5}
b) eyJjaGFubmVscyI6WzEwLDEyXSwidXNlcl9pZCI6NX0=
c) 53a54957765ca65ee52ce727fdf70b95e6972f45
d) eyJjaGFubmVscyI6WzEwLDEyXSwidXNlcl9pZCI6NX0=--53a54957765ca65ee52ce727fdf70b95e6972f45
If you use Ruby on Rails, than you can take my code, that makes rails session interoperable between servers:
Mention, that you can create such session specially for erlyvideo, without affecting usual session. However, you must pass it to push flash.
This tricky technology is required for total separation of erlyvideo and your application. Just prepare this session for flash and erlyvideo
will subscribe this instance of connected flash player to required channels.
2) Use as an example push/push.swf and js/netconnection.js (look at wwwroot/chat.html)
This is client flash, that will connect to server and handle incoming events. It doesn't know anything about kind of messages.
Look at tricky hack in, when I call netconnection.message. This double quoting is required to bypass flash bug.
3) Use erlyvideo web-interface to push messages to channel.
HTTP POST /channels/$channel_id/message
will be delivered to all flashes, subscribed to $channel_id
The same is for user:
HTTP POST /users/$channel_id/message
You may protect this hook by means of firewall, or patching ems_http
4) Profit! Now you may send messages to all connected users via common http interface.
What You can do yourself? It would be much better, if you route posted messages to your application server, auth users there, sanitize input (htmlescape) and
only then forward xml- or json-packed message via erlyvideo back to users.