Skip to main content
Known Participant
February 16, 2012
Question

SharedObject - setProperty/getProperty no change?

  • February 16, 2012
  • 1 reply
  • 1474 views

Hi,

I can't seem to get setProperty to affect any change detectable by getProperty, or any other means.

* Can you please help me find and fix the problems in my code?

Also, it would be great if you could provide a snippet of code to both

1) read/write to the SO from the Flash swf client, and

2) suggest any changes required in the FMS server-side code to receive events onSync from another FMS server (also sending to another FMS server.. I know it should be very similar in theory).

Thanks!

// BEGINING OF CODE (applications/ic_live/main.asc)

var debug = 5;

var myRtmpUrlToThisApp = "rtmp://127.0.0.1/"+application.name;

var myNcToThisApp;

var myStream;

/*

* application.onAppStart:

*                                                  is called when application load. It contains Live (out of the box)

* application specific initializations.

*/

application.onAppStart = function()

{

          // Logging

          trace("onAppStart: Starting Live Service... v.gb.0.0.0.010");

 

     //...

          // FOR SHARED OBJECTS

          makeNcToThisApp();

          if(debug>1) trace("- application.onAppStart function exits -- other events will continue to happen at start and afterwards");

 

}

// FOR SO TO CONNECT TO THIS APP/INSTANCE

makeNcToThisApp = function() {

          if(debug>=1) trace("- makeNcToThisApp: myRtmpUrlToThisApp="+myRtmpUrlToThisApp);

          myNcToThisApp = new NetConnection();

          myNcToThisApp.connect(myRtmpUrlToThisApp);

          myNcToThisApp.onStatus = function(info) {

                    if(debug>=2) trace("-- makeNcToThisApp: info.code="+info.code);

                    if(info.code == "NetConnection.Connect.Success") {

                              updateRoomsSo();

                    }

          }

}

// MANAGE STREAMS LIST IN AN SO

updateRoomsSo = function () {

          if(debug>=1) trace("- updateRoomsSo");

 

          if(myNcToThisApp == undefined) {

                    trace("updateRoomsSo: myNcToThisApp == undefined (not yet established during model connect), exit function");

                    return;

          }

          // GET SO

          var so_allUsers = SharedObject.get("so_allUsers", true, myNcToThisApp);

          // EVENT HANDLERS - SO FAR NEVER CALLED

          so_allUsers.onSync = function(list){

                    trace("*** soStreamsList.onSync");

          }

 

          so_allUsers.onStatus = function(infoObj){

                    trace("*** so_allUsers.onStatus: " + infoObj.level + "; " + infoObj.code);

          };

          // GET PROPERTY

          var  origVal = so_allUsers.getProperty("propStreamsList");

          if(debug>=3) trace("--- updateRoomsSo: origVal="+origVal);

          // ADD THIS ROOM TO SO PROPERTY

          var valToAdd = "<stream server="+application.server+" appinstance="+application.name+" stream="+myStream+"/>";

 

          if(origVal != null) {

                    so_allUsers.setProperty("propStreamsList", valToAdd + origVal);

          } else {

                    so_allUsers.setProperty("propStreamsList", valToAdd);

          }

          // ADD MORE TO PROPERTY

          //so_allUsers.lock()

          so_allUsers.setProperty("propStreamsList", " +VAL1 ");

          //so_allUsers.unlock();

 

          // ATTEMPT TO FORCE CHANGES

          so_allUsers.send();

          so_allUsers.flush();

          // READ OUT (SHOULD BE, BUT IS NOT) CHANGED VALUES -- WHY?

          var  newVal = so_allUsers.getProperty("propStreamsList");

          if(debug>=3) trace("--- updateRoomsSo: newVal="+newVal);

          // PRINT OUT MORE INFO ABOUT SO SIZE ETC -- NO INDICATION OF ANY DATA

          trace("updateRoomsSo: so_allUsers.size()="+so_allUsers.size());

          if(so_allUsers.size() > 0) {

                    var names = so_allUsers.getPropertyNames();

                    trace("updateRoomsSo: names.length="+names.length);

          }

          for (x in names){

                    var propVal = myInfo.getProperty(names);

                    if(debug>=3) trace("--- updateRoomsSo: Value of property " + names + " = " + propVal);

          }

 

 

}

/*

******************

onConnect

******************

*/

application.onConnect = function( p_client, xmlArgs ) {

          trace("onConnect 2 args handler: p_client xmlArgs="+xmlArgs);

          // SET AS UNDEFINED FOR NOW, WILL PARSE FROM XML LATER

          var p_un = undefined;

          var p_pw = undefined;

          var type = undefined;

          //trace("onConnect: p_client NC, p_un="+p_un+" p_pw="+p_pw+" type="+type);

 

          if (type == "viewer" && p_un!= undefined && p_pw !=undefined) {

                    // issue the external call (3 examples below)

                    LoadVars.send("http://private.amsterdamlivexxx.com/dmw/Gary/auth.cfm?un="+pUsername+"&pw="+pPassword);

          }

 

          // VALIDATE THEN ACCEPT

          // ...

          this.acceptConnection(p_client);

 

          //updateRoomsSo();

 

          // JUST TESTING FOR NOW

          p_client.calledFromClient = function(calledFromClientXML)

          {

                    if(debug>=1) trace("*- p_client.calledFromClient ***: xmlUrlEncoded="+xmlUrlEncoded);

                    //p_client.call("getNumber", new randHandler());

                    //var result = p_client.call("calledFromFMS");

                    return xmlUrlEncoded;

          }

 

}

// CF GATEWAY, NOT IN USE

gatewayReady = function() {

          trace("liveGB: gatewayReady but not in use.");

}

application.onPublish = function (clientObj, streamObj)

{

          trace("onPublish 2 args starts: streamObj.name="+streamObj.name);

          streamObj.setBufferTime(0);

          myStream = streamObj.name;

          // FOR SHARED OBJECTS

          updateRoomsSo();

 

}

...

This topic has been closed for replies.

1 reply

February 20, 2012

The following line of code:

// GET SO 

          var so_allUsers = SharedObject.get("so_allUsers", true, myNcToThisApp);

Since you are passing NetConnection object as 3rd parameter to get() method, it means its an Proxied SharedObject. Also, when you get a reference to a Proxied SharedObject, any changes made to the object are sent to the instance that owns the object. And because of it, the onSync() event is not getting triggered here.

If you want onSync() event to get triggered here, remove the 3rd parameter i.e. NetConnection object from get() method.

Also the SharedObject.lock() and SharedObject.unlock() methods cannot lock or unlock proxied shared objects.

Known Participant
February 20, 2012

Thanks for your response.

I used the 3rd arg (for proxied SO), because the concept of the version of code there (ic_live v1.1) was to update a "master" application (eg, ic_live_master) about this room being available, and then the SO's on all other rooms (also on other servers) would be updated. The clients of each of those rooms would also be updated.

Currently, I'm polling FMS's web api for the list of rooms upon room start, and sending that when a client connects. If the poll detects a change, it broadcastMsg that change.

One thing I'd like to impove on though is this:

When a new room starts up, there is some lag in getting the rooms list from FMS.. actually, this should be in the milliseconds and not noticeable, and i'm looking into that.. but, this makes me think:

It would be nice if there was a way that application instances could share information.

What are the ways this can be done? I'm new to ECMA/AS1/JavaScript etc, but I thought I might be able to do application.prototype.myStreamsList, at worst, but it didn't compile/run properly, and I haven't looked into why yet.

What are the good options for this?