State manager behavior

Ask questions about the JavaScript API here

State manager behavior

Postby Guest-xtzkkzfpij » Sat Nov 10, 2012 10:39 am

I am trying to use the state manager object in my project, but I notice an unexpected behavior.

First of all, this is my code:
In my sessionConnectedHandler, I have this:
stateManager = session.getStateManager();
stateManager.addEventListener("changed:foo", testStateManagerHandler);

I have another function that does:
stateManager.set("foo", "bar");

And finally:
function testStateManagerHandler(event){
alert("success");
}


The behavior that I'm experiencing is that the testStateManagerHandler is called when I am adding the event listener to the state manager in the sessionConnectedHandler, before I even get to set the new state.

Any thoughts on this? I appreciate your help.
Was this post helpful? (0)
Guest-xtzkkzfpij
 
Posts: 2
Joined: Sat Nov 10, 2012 10:31 am
Thumbs Up: 0

Re: State manager behavior

Postby jtsai » Mon Nov 12, 2012 11:41 am

The handler is called when you first add the event listener for "foo" in order to get the state of the key "foo". This is so you know the initial value of "foo" (in case someone else has set a value for it before you joined)

John
Was this post helpful? (1)
Very helpful resource: Devs Checklist
Examples with OpenTok: Examples
User avatar
jtsai
 
Posts: 1954
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 157

Re: State manager behavior

Postby Guest-xtzkkzfpij » Thu Nov 15, 2012 2:51 pm

It makes sense. Thank you
Was this post helpful? (0)
Guest-xtzkkzfpij
 
Posts: 2
Joined: Sat Nov 10, 2012 10:31 am
Thumbs Up: 0


Return to JavaScript



Who is online

Users browsing this forum: No registered users and 1 guest

cron