How to send Message to the module.

Added by alex winx 985 days ago

Action Script:
chatRoom.sendModuleMessage("hiuser1", { text:"myData" } );
where chatRoom is the pointer to the room where module resides.
See the union.xml configuraton file part:
<rooms>
<room>
<id>defaultRoom</id>
<attributes>
<!--<attribute name="_CLIENT_TIMEOUT">12000</attribute> Errorous-->
<attribute name="_DIE_ON_EMPTY">false</attribute>
<attribute name="_MAX_CLIENTS">20</attribute>
<!--<attribute name="_PASSWORD">pass</attribute> join("pass") not work-->
</attributes>
<modules>
<module>
<source type="class">ChatBotRoomModule</source>
</module>
</modules>
</room>
</rooms>

Java:
In your module init() function add listener to RoomEvent.MODULE_MESSAGE
// --- for client to module(room) comunication
m_ctx.getRoom().addEventListener(RoomEvent.MODULE_MESSAGE,this,"onModuleMessage");

in the listner function respond to module message sent from client:
/** * This method is the callback for the event we specified in the init method. It will be called whenever a client * talk to server the room.
*/
public void onModuleMessage(RoomEvent evt)//Message msg,Client client)// {
s_log.debug("module message recieved");

Message message=evt.getMessage();
String messageCode=message.getMessageName();

switch(MessageCodes.valueOf(messageCode))
{
case hiuser1:
s_log.debug("module message "+messageCode);
m_ctx.getRoom().sendMessage("CHAT_MESSAGE", "We wish you "+evt.getClient().getAttribute("USERNAME").getValue().toString()+" HI too. We are procesing your data: "+message.getArg("text"));
break;
default:
m_ctx.getRoom().sendMessage("CHAT_MESSAGE", "We understand only HI for now. We are USER1.");
}

}


Replies

RE: How to send Message to the module. - Added by colin moock 984 days ago

hi alex,
good to see you exploring modules and module messages. they're a very powerful part of the platform. we'll be adding additional module message examples to the docs soon!

colin