[SOLVED] addMessageListener and Multiple Rooms

All Union Platform questions, comments, feature requests, and bug reports.

addMessageListener and Multiple Rooms  

Postby Anatta » Sat 12 Nov 2011 22:23

When we define the addMessageListener function we must specify which roomID to listen to. However, when we change rooms, how can we redefine the function to listen to the new roomID instead?
Last edited by Anatta on Tue 29 Nov 2011 14:35, edited 1 time in total.
Anatta
 
Posts: 2
Joined: Thu 20 Oct 2011 13:28

Re: chatMessageListener and Multiple Rooms

Postby Anatta » Tue 29 Nov 2011 14:35

Ah nevermind, I figured it out. It had to list all the rooms I wanted to listen for in the addMessageListener as an array.
Anatta
 
Posts: 2
Joined: Thu 20 Oct 2011 13:28

Re: addMessageListener and Multiple Rooms

Postby colin » Wed 30 Nov 2011 02:53

hi anatta,
yes, you're correct, MessageManager's addMessageListener() method lets you specify a central listener for messages targeted at any number of rooms via the forRoomIDs parameter. for example, the following code registers someListener() to be invoked whenever "SOME_MESSAGE" is received by either room1 or room2:

Code: Select all
messageManager().addMessageListener("SOME_MESSAGE",
                                   someListener,
                                   ["room1", "room2"]);


alternatively, if you want to migrate a listener as the current client joins and leaves rooms, you could do:

Code: Select all
room1.addMessageListener("SOME_MESSAGE", someListener);


then later:

Code: Select all
room1.removeMessageListener("SOME_MESSAGE", someListener);
room2.addMessageListener("SOME_MESSAGE", someListener);


you might be interested to know that:
Code: Select all
room1.addMessageListener("SOME_MESSAGE", someListener);


is just a convenient version of:
Code: Select all
messageManager().addMessageListener("SOME_MESSAGE",
                                   someListener,
                                   ["room1"]);


interally, Room's addMessageListener() actually invokes MessageManager's addMessageListener().

thanks for following up on your own post!

colin
colin
 
Posts: 232
Joined: Mon 17 Oct 2011 18:47


Return to Union Platform

Online

Users browsing this forum: No registered users and 6 guests