HTML and CSS Reference
In-Depth Information
socket server. Others include a PrivateMessageRequest and a PluginMessageRequest . A
PublicMessageRequest is a message that will be sent to everyone in the room. We send that
data using an EsObject , which is native to the ElectroServer API. It allows you to create and
access ad hoc data elements for any type of information you want to send to other users in the
same room.
For a full discussion of EsObject and ElectroServer events, see the ElectroServer documentation.
It is installed with the server on your local machine in [your install folder] //documentation/
html/index.html * .
For this simple chat example, we want to send the chat message the user typed and submitted.
To do this, we will use the setString() method of EsObject . This method takes two para-
meters: the text you want to send, and an identifier you can use to access the text. We also
set another element named type , which will tell us what kind of message we are sending. We
do this because, in a more complicated application, you might send all sorts of messages and
need a way to identify what they are so that you can process them.
After we have configured our PublicMessageEvent with the roomId , the zoneId , and the
EsObject , we call es.engine.send(pmr) to send it to the rest of the room:
function sendMessage ( event ) {
var formElement = document . getElementById ( "textBox" );
var pmr = new
new PublicMessageRequest ();
pmr . message = "" ;
pmr . roomId = _room . id ;
pmr . zoneId = _room . zoneId ;
var esob = new
new ElectroServer . EsObject ();
esob . setString ( "message" , formElement . value );
esob . setString ( "type" , "chatmessage" );
pmr . esObject = esob ;
es . engine . send ( pmr );
statusMessages . push ( "message sent" );
Notice that we did not print the user's chat message to the canvas when it was submitted.
Instead, we will wait for the PublicMessageEvent to return from ElectroServer and then
handle it like all the other chats. This keeps the interface clean, while preserving a create
event/handle event processing model across the entire application.
Search WWH ::

Custom Search