Copy link to clipboard
Copied
Hi
I managed to get the basic of main.asc now i can see and get the info of the encouder connecting to livepkgr and do some validation...
The problem I'm having is when a user who comes to the site and loads the stream, can I capture the users info?
like page url, ip, page referrer?
Not the encouder but the end user who views the stream, tried many things but no luck so far.
any help would be appreciated...
here is my main.asc
application.onAppStart = function()
{
trace("Application name: " + application.name);
trace("Server: " + application.server);
_clientId = 0;
application.s = new Array();
application.a = new Array();
application.v = new Array();
application.toclear = new Array();
application.clearOnAppStop = false;
if(application.config["clearOnAppStop"] == "true" )
{
application.clearOnAppStop = true;
}
// trace("config for clear stream on app unload:" + application.clearOnAppStop);
}
application.onStatus = function()
{
/*trace("There is an error in the code or functionality.");*/
}
application.onConnect = function(clientObj)
{
this.acceptConnection(clientObj);
}
Stream.prototype.trace = function(msg)
{
trace(this.type + ":" + this.name + " - " + msg);
}
application.onPublish = function(clientObj, streamObj)
{
// a race can happen during republish. if onPublish is called
// before onUnpublish, we need to wait for onUnpublish to
// complete before calling onPublish for the new stream.
if (streamObj.publishing == true)
{
// onUnpublish has not been called yet
//trace("Unpublish pending...");
streamObj.publishingClient = clientObj; // save and call onPublish later
return;
}
streamObj.publishing = true;
trace("onPublish : " + streamObj.name);
var queryString = streamObj.publishQueryString;
var liveEventName = streamObj.name;
var audioStreamSrc = "";
var audioStreamName = "";
var videoStreamSrc = "";
var videoStreamName = "";
var recordMode = "append";
//trace("queryString["+queryString+"] stream["+streamObj.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["
+streamObj.name+"] as eventname");
} else {
/* Looking for name value pair adbe-live-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];
/*trace("nv["+nv+"]=val["+nval+"]");*/
if (nv.localeCompare("adbe-live-event")==0) {
liveEventName = nval;
/*trace("live event set to["+liveEventName+"]");*/
}
else if (nv.localeCompare("adbe-audio-stream-src") == 0)
{
audioStreamSrc = nval;
}
else if (nv.localeCompare("adbe-audio-stream-name") == 0)
{
audioStreamName = nval;
}
else if (nv.localeCompare("adbe-video-stream-src") == 0)
{
videoStreamSrc = nval;
}
else if (nv.localeCompare("adbe-video-stream-name") == 0)
{
videoStreamName = nval;
}
else if (nv.localeCompare("adbe-record-mode") == 0)
{
recordMode = nval;
}
}
}
var s = Stream.get("f4f:" + streamObj.name);
if (s == undefined )
return;
if ((s.liveEvent != undefined)&&(s.liveEvent != "")&&(s.liveEvent != liveEventName)) {
trace("Rejecting publish from client: "+clientObj.ip +" as stream: "+streamObj.name+
" is already assigned to event: ["+s.liveEvent +"]");
application.disconnect(clientObj);
return;
}
s.onStatus = function(info)
{
this.trace(info.code);
}
s.liveEvent = liveEventName;
trace("Stream name is: " + streamObj.name + " and live event is: "+s.liveEvent);
trace("the client's referrer is " + clientObj.referrer);
if (!s.record(recordMode))
{
s.trace("record failed.");
}
s.play(streamObj.name,-1,-1);
// my code
trace("new client connected and playing ........");
application.s[streamObj.name] = s;
// check if audio only stream is desired
if (audioStreamName != "")
{
// if no stream src specified, use this stream
if (audioStreamSrc == "")
{
audioStreamSrc = streamObj.name;
}
if (audioStreamSrc == streamObj.name)
{
//trace("Creating audio only stream " + audioStreamName + " from " + audioStreamSrc);
var a = Stream.get("f4f:" + audioStreamName);
a.onStatus = function(info)
{
this.trace(info.code);
}
a.receiveAudio = true;
a.receiveVideo = false;
a.liveEvent = liveEventName;
if (!a.record(recordMode))
{
a.trace("record failed.");
}
a.play(audioStreamSrc, -1, -1);
application.a[streamObj.name] = a;
}
}
// check if video only stream is desired
if (videoStreamName != "")
{
// if no stream src specified, use this stream
if (videoStreamSrc == "")
{
videoStreamSrc = streamObj.name;
}
if (videoStreamSrc == streamObj.name)
{
//trace("Creating video only stream " + videoStreamName + " from " + videoStreamSrc);
var v = Stream.get("f4f:" + videoStreamName);
v.onStatus = function(info)
{
this.trace(info.code);
}
v.receiveAudio = false;
v.receiveVideo = true;
v.liveEvent = liveEventName;
if (!v.record(recordMode))
{
v.trace("record failed.");
}
v.play(videoStreamSrc, -1, -1);
application.v[streamObj.name] = v;
}
}
}
application.onUnpublish = function(clientObj, streamObj)
{
trace("onUnpublish : " + streamObj.name);
var s = application.s[streamObj.name];
if (s && s!= undefined)
{
s.record(false);
s.play(false);
s.liveEvent = "";
application.s[streamObj.name] = null;
application.addToClear("f4f:" + streamObj.name);
}
// is this the source for audio only stream?
var a = application.a[streamObj.name];
if (a && a != undefined)
{
//trace("Removing audio only stream " + a.name + " : source = " + streamObj.name);
a.record(false);
a.play(false);
a.liveEvent = "";
application.a[streamObj.name] = null;
application.addToClear("f4f:" + streamObj.name);
}
// is this the source for video only stream?
var v = application.v[streamObj.name];
if (v && v != undefined)
{
//trace("Removing video only stream " + v.name + " : source = " + streamObj.name);
v.record(false);
v.play(false);
v.liveEvent = "";
application.v[streamObj.name] = null;
application.addToClear("f4f:" + streamObj.name);
}
streamObj.publishing = false;
if (streamObj.publishingClient != undefined &&
streamObj.publishingClient != null)
{
// onPublish was suspended pending completion of onUnpublish
// call it now.
application.onPublish(streamObj.publishingClient, streamObj);
streamObj.publishingClient = null;
}
}
application.addToClear = function(streamName)
{
if(application.clearOnAppStop)
{
application.toclear[streamName] = streamName;
}
}
application.onAppStop = function()
{
if(application.clearOnAppStop)
{
var i;
for (i in application.toclear)
{
var streamName = application.toclear;
var obj = Stream.get(streamName);
if(obj && obj != undefined)
{
trace("clearing the stream: " + streamName);
obj.clear();
}
}
}
}
/*
* 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( streamstr )
{
var streamParams = new Array();
streamParams = streamstr.split("?", 2);
var streamname = streamParams[0];
//trace("FCUnpublish: streamName " + 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( streamstr )
{
// perform your clean up
var streamParams = new Array();
streamParams = streamstr.split("?", 2);
var streamname = streamParams[0];
//trace("FCUnpublish: streamName " + streamname);
this.call("onFCUnpublish", null, {code:"NetStream.Unpublish.Success", description:streamname});
}
/*
* releaseStream :
* When an FMLE connection to AMS drops during a publishing session it
* tries to republish the stream when the connection is restored. On certain
* occasions, AMS 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(streamstr)
{
var streamParams = new Array();
streamParams = streamstr.split("?", 2);
var streamname = streamParams[0];
//trace("releaseStream: streamName " + streamname);
var s = Stream.get(streamname);
if (s) {
s.play(false);
}
}