application.onAppStart = function() { trace("Application name: " + application.name); trace("Server: " + application.server); _clientId = 0; application.s = new Array(); } application.onStatus = function() { /*trace("There is an error in the code or functionality.");*/ } application.onConnect = function(clientObj) { this.acceptConnection(clientObj); } application.onPublish = function(clientObj, streamName) { var queryString = streamName.publishQueryString; var liveEventName = streamName.name; if (queryString == undefined || (queryString.localeCompare("") == 0)) { /* Did not find query string so use the streamname as the event id */ trace( "Query string not specified. Using StreamName[" + streamName.name + "] as eventname" ); } else { /* Looking for name value pair event in the query string. If specified, use event name based on it. Otherwise, it is a single stream so you don't need to configure Event.xml and Manifest.xml */ var nvpairs = new LoadVars(); nvpairs.decode(queryString); for (var nv in nvpairs) { var nval = nvpairs[nv]; if (nv.localeCompare("event")==0) { liveEventName = nval; break; } } } var s = Stream.get("f4f:" + streamName.name); if (s == undefined ) { return; } if( ( s.liveEvent != undefined ) && ( s.liveEvent != "" ) && ( s.liveEvent != liveEventName ) ) { trace( "Rejecting publish from client: " + clientObj.ip + " as stream: " + streamName.name + " is already assigned to event: ["+s.liveEvent +"]" ); application.disconnect(clientObj); return; } s.liveEvent = liveEventName; trace("Stream name is: " + streamName.name + " and live event is: "+s.liveEvent); s.play(streamName.name,-1,-1); s.onStatus = function(info) { //trace("info.code is: " + info.code); } s.record("append"); application.s[streamName.name] = s; } application.onUnpublish = function(clientObj, streamObj) { var s = application.s[streamObj.name]; if (s && s!= undefined) { s.record(false); s.play(false); } } /* * FCPublish : * FMLE calls FCPublish with the name of the stream whenever a new stream * is published. This notification can be used by server-side action script * to maintain list of all streams or to force FMLE to stop publishing. * To stop publishing, call "onFCPublish" with an info object with status * code set to "NetStream.Publish.BadName". */ Client.prototype.FCPublish = function( streamname ) { // setup your stream and check if you want to allow this stream to be published if ( true) // do some validation here { // this is optional. this.call("onFCPublish", null, {code:"NetStream.Publish.Start", description:streamname}); } else { this.call("onFCPublish", null, {code:"NetStream.Publish.BadName", description:streamname}); } } /* * FCUnpublish : * FMLE notifies the server script when a stream is unpublished. */ Client.prototype.FCUnpublish = function( streamname ) { // perform your clean up this.call("onFCUnpublish", null, {code:"NetStream.Unpublish.Success", description:streamname}); } /* * releaseStream : * When an FMLE connection to FMS drops during a publishing session it * tries to republish the stream when the connection is restored. On certain * occasions, FMS rejects the new stream because the server is still * unaware of the connection drop, sometimes this can take a few minutes. * FMLE calls the "releaseStream" method with the stream name and this can be * used to forcibly clear the stream. */ Client.prototype.releaseStream = function(streamname) { var s = Stream.get(streamname); if (s) { s.play(false); } }