Multiple Client instances

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

Post Reply
croftie
Posts: 49
Joined: 24 Jul 2013, 08:35
Location: Algarve Portugal
Contact:

Multiple Client instances

Post by croftie »

If a javascript client is running multiple instances of SFS to connect to multiple servers, is it possible to identify the specific instance from within the callback from an event listener.

By example if I have 2 instances:

Code: Select all

function someMethod()
{
sfs1 = new SFS2X.SmartFox(config1);
sfs1.addEventListener(SFS2X.SFSEvent.CONNECTION, someListener, this);
sfs2 = new SFS2X.SmartFox(config2);
sfs2.addEventListener(SFS2X.SFSEvent.CONNECTION, someListener, this);
}

function someListener(evtParams)
{
	// identify sfs1 or sfs2 connected
}
is it possible to identify whether it is sfs1 or sfs2 which has connected (or any other listener function) or does there have to be a specific listener function for each instance of SFS?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Multiple Client instances

Post by Bax »

There's no "identity" parameter passed to the listener because we never thought of this use case. Maybe we can add it in the future.
For the time being, I guess you could have an object with all the listeners and a property identifying it. You can then pass that object as the scope when adding the listener (instead of this), so that you can check the identity inside the listener. You will also need to a way to interact with your main scope from the listeners, for which you could have a that property on the listeners' scope object.
Paolo Bax
The SmartFoxServer Team
Post Reply