Monday, February 4, 2013

On_connect and on_disconnect in 0.9.6

Two new HTTP notifications were added in version 0.9.6 of nginx-rtmp-module: on_connect and on_disconnect.

The first one is called when client issues connect command. It receives all arguments coming with that command, namely app, flashver, swfurl, tcurl, pageurl, addr. In addition to that on_connect receives connection arguments which have never been available in previous versions if nginx-rtmp. Any HTTP result code different from 2xx is considered an error and client connection is closed. This notification can be used for user authorization.

Here's an example of passing connection argument with JWPlayer.


jwplayer("container").setup({
modes: [
{ type: "flash",
src: "/jwplayer/player.swf",
config: {
bufferlength: 1,
file: "mystream",
streamer: "rtmp://localhost/myapp?arg1=v1&arg2=v2",
provider: "rtmp",
autostart: "1"
}
}
]
});




Several Flash players can only pass connection arguments to server and never pass play/publish arguments. OSMF passes the same arguments to all calls.

The second notification on_disconnect is called when the connection is closed. It receives exactly the same set of arguments as on_connect. Note however on_dicsonnect is called on every disconnect event whether connect command was issued or not. The result code of this callback is not analyzed.

Both new callbacks should be added to server{} scope of nginx.conf and never to application{} scope. That's because client is still not connected to any application at the moment of on_connect and might have no application at the moment of on_disconnect. HTTP method is tuned with the previously introduced notify_method directive.


rtmp {
server {
listen 1935;
notify_method get;

on_connect http://localhost:8080/on_connect;
on_disconnect http://localhost:8080/on_disconnect;

application myapp {
live on;
}
}
}

1 comment:

  1. hi,i wonder how to pass arg1 and arg2 to http://localhost:8080/on_disconnect when run the on_connect directive?

    ReplyDelete