HTML and CSS Reference
In-Depth Information
es . engine . send ( r );
When ElectroServer responds from the LoginRequest , it is time to join a zone and a room .
Recall that any user connected to ElectroServer needs to belong to a room , and every room
belongstoa zone .Therefore,weneedtomakeauserbelongtooneofeach,whichweaccom-
plish with a CreateRoomRequest() . We set the zoneName property to TestZoneChat and the
roomName property to TestRoomChat . If either of these does not already exist, it will be cre-
ated by the server. If they do exist, the user will be added to them. We then send the message
to ElectroServer:
function onLoginResponse ( event ) {
statusMessages . push ( "Login Successful?: " + event . successful );
username = event . userName ;
var crr = new
new CreateRoomRequest ();
crr . zoneName = "TestZoneChat" ;
crr . roomName = "TestRoomChat" ;
es . engine . send ( crr );
the API via port 8989. We know we have to join a zone , and we handle the event with the
function onJoinZoneEvent() , but we don't need to do anything with it:
function onJoinZoneEvent ( event ) {
statusMessages . push ( "joined a zone" );
The most important event we are waiting to handle is JoinRoomEvent . When we receive this
event, we know that we have joined both a zone and a room , and the application is ready
to run. For the chat application, this means the user can start typing and sending messages.
First, we set the _room variable equal to the Room object, which was returned by the event
from ElectroServer . We will use this variable for our further communications with Elec-
troServer . The other thing we do in this function is set an HTML <div> with the id of
inputForm , which is made visible by changing its style. The inputForm <div> is invisible
when the page loads. We do this so that the user won't send chat messages before the con-
nection to ElectroServer is established. Now that everything is ready to go, we display the
inputForm <div> so that chatting can start:
Search WWH ::

Custom Search