Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (40 sloc) 2.89 kb
@author Max Lapshin <max@maxidoors.ru> [http://maxidoors.ru]
@copyright 2009 Max Lapshin
@reference See <a href="http://github.com/maxlapshin/erlyvideo" target="_top">http://github.com/maxlapshin/erlyvideo</a> for more information
@version
@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/erlmedia.app and default one is in src/erlmedia.app
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: http://gist.github.com/141303
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 push.as, 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
message=......
will be delivered to all flashes, subscribed to $channel_id
The same is for user:
HTTP POST /users/$channel_id/message
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.
@end
Jump to Line
Something went wrong with that request. Please try again.