Home
Demo
Download
Documentation
Community
Credit

 

ICEspresso Chat API

 

Developer Guide

Demo Codes

Support Resources

Latest Blog Posts

powered by Push4Free.com

Docs > API Reference

ICEspresso Chat Framework API Reference

The ICEspresso Chat Framework API provides the interface to interact with and to manipulate the ICEspresso Service which offers chat-related and web presence functionalities. The ICEspresso Chat Framework aims to free developers from having to deal with low-level socket programming as well as back-end server design thus, through simple API, developers may devote their time and creativity to UI design.

The ICEspresso Chat Framework is built on asynchronous paradigm for most of its parts. In contrary to the conventional synchronous programming, developers will find the API methods heavily rely on callback functions. Those who have worked with Ajax or possess similar experiences in asynchronous programming will adapt to ICEspresso Chat Framework in a quicker pace.

For most of the API methods, developer will call a method (sends command to ICEspresso Service) and set-up a mapping handler to be notified of the results from ICEspresso Service. Depending on the nature of the command, different callback handler will be invoked with appropriate event id to let application identify the type of event.

This API reference mainly focuses on individual method and tries to explain what each method does. Developers looking for big picture or crash course on ICEspresso package should read the Tutorial page.

Table of Contents

  1. ICEspresso Namespace
    1. function icespresso.initialize
    2. function icespresso.log
  2. ICEspresso Class
    1. method connect
    2. method disconnect
    3. method isReady
    4. method isConnected
    5. method setDebug
    6. method joinRoom
    7. method quitRoom
    8. method send2Room
    9. method kick
    10. method getRoom
    11. method getMyRoomCount
    12. method roomExists
    13. method getTotalUserCount
    14. method getRoomChatterCount
    15. method iAm
    16. method getMe
    17. method setFriends
    18. method addFriends
    19. method removeFriends
    20. method getFriends
    21. method sendPM
  3. Room Class
    1. method getName
    2. method getMessages
    3. method getChatterCount
  4. Chatter Class
    1. method getId
    2. method getHandle
    3. method getLastHandle
    4. method isMe
  5. Message Class
    1. method getMessage
    2. method getBy
    3. method getWhen
    4. method getType
    5. property ROOM_MSG
    6. property JOIN_MSG
    7. property QUIT_MSG
  6. Callback function
    1. function icespresso.onSystemEvent
      1. event  SYS_INITIALIZED
      2. event  SYS_CONNECTED
      3. event  SYS_DISCONNECTED
      4. event  SYS_HANDSHAKED
      5. event  SYS_ROOMEXISTS
      6. event  SYS_TOTALUSER
      7. event  SYS_ROOMCHATTER
    2. function icespresso.onChatEvent
      1. event  CHAT_ROOMJOIN
      2. event  CHAT_ROOMREADY
      3. event  CHAT_ROOMMSG
      4. event  CHAT_HANDLEUPDATE
      5. event  CHAT_ROOMQUIT
      6. event  CHAT_ROOMKICK
    3. function icespresso.onFriendEvent
      1. event  FRIEND_ONLINE
      2. event  FRIEND_JOINROOM
      3. event  FRIEND_QUITROOM
      4. event  FRIEND_OFFLINE
      5. event  FRIEND_LOCATION
      6. event  FRIEND_PRIVATEMSG
      7. event  FRIEND_PMSENT
      8. event  FRIEND_PMFAILED

ICEspresso Namespace

The icespresso package resides under icespresso namespace. Within the namespace, the icespresso class is defined, but by design it is not directly accessible. The namespace instead exports an entry function icespresso.initialize() to, as the name suggests, prepare the framework components. Developers having background in other modern programming languages will easily find the icespresso.initialize() approach by nature a static type initializer.

Under the icespresso namespace, four classes are defined, being Icespresso, Room, Chatter, and Message respectively. These four classes are the building blocks of the ICEspresso Chat Framework. Developers do not have to create concrete objects from these classes. Depending on the situation, objects of these classes will be created by the framework and passed to application either through explicit method call or event callback handlers.

icespresso.initialize()

This is the entry function that instantiates and returns an Icespresso object. This function needs to be called to initialize the required framework components properly before other operations can kick in. icespresso.initialize() only instructs the framework to set-up its state. The actual initialization process is asynchronous. Under the hood, a Flash object has to be embedded in the web page and its own initialization handler be invoked before the framework is considered initialized. As such, when icespresso.initialize() returns, the internal resources *may not* have completed the initialization process. The framework will signal the ready state via callback handlers.

parameter:

none

returns:

object The core ICEspresso object through which operations are performed. The ICEspresso package is built on singleton pattern so multiple calls to icespresso.initialize() will always return the copy created in the initial call.

example:

<script language="javascript">
// The ICEspresso object created through initialization process.
// When the function returns, chat object's state may still be undefined.
// Developers have to be notified of the ready state via event signal.
var chat = icespresso.initialize();

// The following code *can* lead to run-time error because chat object
// is defined but may not have been fully initialized yet
// chat.iAm("foo");
</script>

icespresso.log(logMsg)

This method opens up a floating log pane and displays the messages written to it.

parameter:

logMsg The message to display in the floating log pane. ICEspresso Chat Framework calls this method if debug mode is turned on to

returns:

none

 


(Figure 1. ICEspresso log pane)

ICEspresso Class

The entry function icespresso.initialize() returns an object with which developers use to manipulate the framework. It has been stressed enough that the initialization process is asynchronous. Some of the following methods are not applicable before initialized signal has been alerted.

Methods which communicate with ICEspresso Service are all asynchronous and thus require connectivity to ICEspresso Service. Absence of connectivity results in immediate "not connected" error throw when asynchronous methods called. Also, these methods will have a corresponding callback handler counterpart.

connect(prop, [uniqueKey], [ip])

Connect to iPush Server.

connect() must be called before other ICEspresso Service related operations can proceed. The parameter prop is a iPush Server specific property that may require further reading which is outside the scope of this API reference. Please refer to [...] for more information. connect() call is asynchronous, meaning that successful or failed connection is notified later in icespresso.onSystemEvent() callback.

The current design only supports one connection per web page. Calling connect() when already connected will result in exception thrown.

parameter:

prop The connection properties in the form of associative array which is consisted of:
- host
- port
- group
- product
- user
- password
uniqueKey Optional. This parameter essentially gives the connection a name with which the framework can identify. In the event of multiple pages accessing the framework within the same browser, connection made on each page is unrelated to one another. With uniqueKey, the framework can group distinct connections into one single entity. This parameter is crucial to the friend-based methods. uniqueKey parameter can only contain alphanumerical characters (A-Za-z_0-9) with length limited at 32 characters long.
ip Optional. The presence of this parameter instructs ICEspresso Service to log activities performed by the appliation with the specified user IP address. Developer is advised to provide IP address instead of hostname as hostname may lead to character truncation in the logging table.

returns:

none

throws error when:

not ready connect() attempted before the framework is fully initialized.
already connected connect() attempted when connection is already established.
missing prop connection property argument is missing or its required elements are not in place.
invalid uniqueKey either uniqueKey contains non-acceptable characters or its length exceeds 32 characters long.

mapped callback event:

SYS_CONNECTED When connected, the framework will call icespresso.onSystemEvent() with event id set to SYS_CONNECTED.
example:
<script language="javascript">
var prop = {
    host: "www.push4free.com",
    port: 443,
    group: "icespresso",
    product: "chat",
    user: "foo",
    password: "bar1"
};
var uniqueKey = "baz";
chat.connect(prop, uniqueKey);
</script>

disconnect()

disconnect() unregisters from ICEspresso Service and disconnects from iPush Server. disconnect() will also reset Framework's internal state variables.

disconnect() is an asynchronous call because of the ICEspresso Service unregistration part. Completion of disconnection is notified in icespresso.onSystemEvent() callback.

parameter:

none

returns:

none

throws error when:

not connected disconnect attempted when the Framework is not connected.

mapped callback event:

SYS_DISCONNECTED When disconnected, the framework will call icespresso.onSystemEvent() with event id set to SYS_DISCONNECTED.
example:
<script language="javascript">
chat.disconnect();

icespresso.onSystemEvent(chat, eventId, arg) {
    switch (eventId) {
        case chat.SYS_DISCONNECTED:
        // Perform other application-specific clean-up code here
        break;
    }
}
</script>

isReady()

Query the framework to check for initialization status. Normally, developers do not have to actively check for the initialization status as the framework will send event signal when it has finished initialization. This method exists as a convenient utility function that may come handy when debugging.

parameter:

none

returns:

boolean true when the framework has loaded the Flash object and has instructed the object to initialize itself.

isConnected()

Query the framework to see if it has connected to remote iPush Server. As with isReady(), this is a convenient utility that developers can resort to when developing or debugging.

parameter:

none

returns:

boolean true when the framework has connected to iPush Server.

setDebug(mode)

Turn on or turn off the debug mode. When debug mode is on, ICEspresso Chat Framework will output descriptive messages of what is happening to log pane when system level event occurs.

parameter:

mode true/false to turn on/off debug mode.

returns:

none

joinRoom(roomName)

Join the room specified by the roomName parameter.

parameter:

roomName Name of the room to join. roomName can only contain alphanumerical (A-Za-z_0-9) characters with length limited at 32 characters.

returns:

none

throws error when:

invalid roomName if roomName contains non-acceptable characters or its length is longer than 32 characters.
not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

CHAT_ROOMJOIN When someone else joins a room, the framework will call icespresso.onChatEvent() with event id set to CHAT_ROOMJOIN
CHAT_ROOMREADY When application joins a room, the framework will call icespresso.onChatEvent() with event id set to CHAT_ROOMREADY
example:
<script language="javascript">
// join the room named Olympic
chat.joinRoom("Olympic");
</script>

quitRoom(roomName)

Quit the room currently joined.

parameter:

roomName Name of the room to quit.

returns:

boolean true when roomName exists in internal room structure, false when otherwise. When it returns true, it merely indicates that room quitting action is being transacted, completion of the action is pending event signal.

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

CHAT_ROOMQUIT When quitting a room succeeds, the framework will call icespresso.onChatEvent() with event id set to CHAT_ROOMQUIT
example:
<script language="javascript">
// quit the room named Olympic
chat.quitRoom("Olympic");
</script>

send2Room(msg, roomName)

Send message to the room specified by roomName.

parameter:

msg The message to be sent.
roomName The room to send the message to.

returns:

boolean true when roomName exists in internal room structure, false when otherwise.

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

CHAT_ROOMMSG When message is sent to room, the framework will call icespresso.onChatEvent() with event id set to CHAT_ROOMMSG.
example:
<script language="javascript">
// Send message to the room named Olympic
chat.send2Room("How is everything going?", "Olympic");
</script>

kick(roomName, who)

Remove a chatter from the specified room. If a chatter is associated with multiple sessions in the same room. Those sessions will be removed from the room as well.

parameter:

roomName The room where the chatter is to be removed from.
who Id of the chatter. Id is obtained by getId() in Chatter class.

returns:

boolean true when the caller is granted privilege to perform kick operation.

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

CHAT_ROOMKICK When the kick operation is performed on ICEspresso Service, the framework will call icespresso.onChatEvent() with event id set to CHAT_ROOMKICK.
example:
<script language="javascript">
// Remove the chatter with id 3 from room Olympic.
chat.kick("Olympic", 3);
</script>

getRoom(roomName)

Retrieve the Room object named by roomName. The Room object is a local resource rather than remote resource. That is, getRoom() retrieves the Room object that the application has joined and is still in session.

parameter:

roomName name of the room to be retrieved.

returns:

object The Room object referenced by roomName, null if the application has not joined the room.
example:
<script language="javascript">
// retrieve the room named "Olympic"
var room = chat.getRoom("Olympic");
if (room != null) {
  // do something with the room
}
</script>

getMyRoomCount()

Retrieve the number of rooms the applicatoin has joined and is currently in active session.

parameter:

none

returns:

number The number of rooms this application is participating in.

roomExists(roomName)

Query ICEspresso Service the existence of a room referenced by roomName. Unlike getRoom(), roomExists() queries ICEspresso Service for the availability of the room. The query result is returned via icespresso.onSystemEvent() event handler.

parameter:

roomName the name of the room to query for.

returns:

boolean true if query command is successfully sent to ICEspresso Service. If roomName is null or an empty string, false is returned.

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

SYS_ROOMEXISTS When query result arrives, the framework will call icespresso.onSystemEvent() with event id set to SYS_ROOMEXISTS.

getTotalUserCount()

Query ICEspresso Service the number of connected user at system level.

parameter:

none

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

SYS_TOTALUSER When query result arrives, the framework will call icespresso.onSystemEvent() with event id set to SYS_TOTALUSER.

getRoomChatterCount(rooms)

Query ICEspresso Service the number of chatters in the rooms specified by the rooms parameter.

parameter:

rooms an index-based array containing the name of the rooms to query for.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.
invalid array if the rooms parameter is not an index-based array.

mapped callback event:

SYS_ROOMCHATTER When query result arrives, the framework will call icespresso.onSystemEvent() with event id set to SYS_ROOMCHATTER.

iAm(handle)

Set the chatter's screen handle to handle.

parameter:

handle The new handle to be set.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.
example:
<script language="javascript">
// Set the chatter's handle to Oliver
chat.setHandle("Oliver");
</script>

getMe()

Obtain a Chatter object that essentially points to the current application user from ICEspresso Chat Framework. Technically speaking, the Chatter object is the one who creates the connection for the application page.

parameter:

none

returns:

object the Chatter object that owns the application page's connection.
example:
<script language="javascript">
// retrieve me object and test identity against it
var chatter= chat.getMe();
if (chatter.isMe())
    alert("This is me");
else
    alert("This is NOT me"); // won't happen
</script>

setFriends(friends)

Set the elements in friends parameter to watch list so that when the watched entity has signed in, logged off, or joined a chat room, the ICEspresso Service will dispatch a notification message. The technical detail involved in friend-related functions is discussed in [...]. Developers are encouraged to read it to gain an insight into the working mechanism.

setFriends() overwrites the current watch list. That is, a setFriends() call replaces the previous watched list (if any).

parameter:

friends an index-based array of friends' uniqueKey to watch for.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.
invalid array if the friends parameter is not an index-based array.
uniqueKey not set if the caller is not associated with a uniqueKey in connect() call.
example:
<script language="javascript">
var prop = {
    // code omitted for brevity
};
chat.connect(prop, "baz");
// After SYS_CONNECTED event has been signaled.
var friends = new Array();
friends.push("user1");
friends.push("user2");
friends.push("user3");
// watch for chatters whose uniqueKey is set to user1, user2, or user3 respectively.
chat.setFriends(friends);
// chat.setFriends(["user1", "user2", "user3"]);  This will achieve the same result.
</script>

addFriends(friends)

Add the elements in friends parameter to watch list so that when the watched entity has signed in, logged off, or joined a chat room, the ICEspresso Service will dispatch a notification message. The technical detail involved in friend-related functions is discussed in [...]. Developers are encouraged to read it to gain an insight into the working mechanism.

addFriends() appends the elements in friends parameter to the watch list.

parameter:

friends an index-based array containing friends' uniqueKey to watch for.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.
invalid array if the friends parameter is not an index-based array.
uniqueKey not set if the caller is not associated with a uniqueKey in connect() call.
example:
<script language="javascript">
var prop = {
    // code omitted for brevity
};
chat.connect(prop, "baz");
// After SYS_CONNECTED event has been signaled.
var friends = new Array();
friends.push("user1");
friends.push("user2");
friends.push("user3");
// watch for chatters whose uniqueKey is set to user1, user2, or user3 respectively.
chat.addFriends(friends);
// chat.addFriends(["user1", "user2", "user3"]);  This will achieve the same result.
</script>

removeFriends(friends)

Remove elements in friends parameter from current watch list. The technical detail involved in friend-related functions is discussed in [...]. Developers are encouraged to read it to gain an insight into the working mechanism.

parameter:

friends an index-based array of friends' uniqueKey to remove from the current watch list.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.
invalid array if the friends parameter is not an index-based array.
uniqueKey not set if the caller is not associated with a uniqueKey in connect() call.
example:
<script language="javascript">
var prop = {
    // code omitted for brevity
};
chat.connect(prop, "baz");
// After SYS_CONNECTED event has been signaled.
var rmv = new Array();
rmv.push("user1");
rmv.push("user2");
rmv.push("user3");
// remove user1, user2, and user3 from current watch list.
chat.removeFriends(friends);
// chat.removeFriends(["user1", "user2", "user3"]);  This will achieve the same result.
</script>

getFriends(getOffline)

Query the ICEspresso Service to retrieve the status of those who are in my watch list. The default behavior is to list online entities only. The result is returned to application via icespresso.onFriendEvent() handler.

parameter:

getOffline if results should contain offline friends.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

FRIEND_LOCATION When connected, the framework will call icespresso.onFriendEvent() with event id set to FRIEND_LOCATION.
example:
<script language="javascript">
var prop = {
    // code omitted for brevity
};
chat.connect(prop, "baz");
// After SYS_CONNECTED event has been signaled.
chat.setFriends(["user1", "user2", "user3"]);
chat.getFriends();
</script>

sendPM(chatterId, msg)

Send a private message to the designated recipient. If the message recipient owns several concurrent sessions, each session will receive a copy of the message.

parameter:

chatterId The connection id associated with the message recipient.
msg the text to send to the recipient.

returns:

none

throws error when:

not connected if the ICEspresso instance is not connected to iPush Server.

mapped callback event:

FRIEND_PMSENT When message is routed to recipient via ICEspresso Service, the sender will also receive the message-sent acknowledgement.
FRIEND_PMFAILED If ICEspresso Service cannot locate the recipient, the sender will be notified of the failed attempt through this event.
example:
<script language="javascript">
icespresso.onFriendEvent(chat, eventId, arg) {
    switch (eventId) {
        case chat.FRIEND_PMSENT: {
            var to = arg.to; // recipient's connection id (3 in this sample)
            var handle = arg.handle; // recipient's current handle
            var msg = arg.msg; // In this sample, msg translates to "Hi, how are you?"
            break;
        }

        case chat.FRIEND_PMFAILED: {
            var to = arg.to; // recipient's connection id (3 in this sample)
            var msg = arg.msg; // In this sample, msg translates to "Hi, how are you?"
        }
    }
}

chat.sendPM(3, "Hi, how are you?");
</script>

Room Class

The Room class is used to maintain the state of the chatters who participate in the room activity. Under the hood, room objects contain raw data which are linked and kept synchronized with ICEspresso Service. As a result, developers do not create room objects. Instead, the ICEspresso Chat Framework will create and maintain a list of room objects and pass them to application when necessary.

If application needs to inspect a room object, the ICEspresso class provides getRoom(roomName) method for such purpose.

getName()

Get the name of the room.

parameter:

none

returns:

string The canonical name of the room.

getMessages()

Get the historic messages before room is created. Technically speaking, room object creation from Framework's perspective happens when application joins a room. Upon room creation, ICEspresso Service will pass messages (20 by default) that were exchanged in the room to the ICESpresso Chat Framework which will in turn assign these messages to the newly created room object. This approach gives application a way to examine the historic messages prior to joining. Hence, what getMessages() returns is a snapshot of those historic messages right before application joins a room.

parameter:

none

returns:

array An index-based array containing message objects. Lower index denotes older messages.
example:
<script language="javascript">
function output(str) {
    var d = document.createElement("DIV");
    d.innerHTML = msg;
    document.body.appendChild(d);
}

// suppose room object is passed to application from framework
var messages = room.getMessages();
for (var i=0; i<messages.length; ++i) {
    // display messages in ascending order (older message is displayed near top)
    output(messages[i].getMessage());
}
</script>

getChatterCount()

Returns the number of chatters in the room.

parameter:

none

returns:

number The number of chatters in this room. If two ore more chatters belong to the same session, they are counted as one. Thus the returned count may be less than the actual number of chatters.

Chatter Class

The Chatter class represents users who have connected to ICEspresso Service.

getId()

Return the id associated with this chatter. Id is assigned by ICEspresso Service to guarantee the uniqueness within the system.

parameter:

none

returns:

number The chatter's id in numerical value. The uniqueness of id for all simultaneously connected chatter is backed-up by ICEspresso Service.

getHandle()

Get the screen handle the chatter goes by. Screen handle is synonymous to nickname.

parameter:

none

returns:

string Screen handle of the chatter.

getLastHandle()

The screen handle that is previously used by this chatter.

parameter:

none

returns:

string In the event of chatter handle change, the original handle will be saved and is retrievable using this method.

isMe()

Indicates whether or not this chatter is me.

parameter:

none

returns:

boolean true if the chatter object points to me. "Me" in this context figuratively translates to the chatter object created by ICESpresso Chat Framework behind the scene when an ICEspresso-powered application calls icespresso.initialize().

Message Class

The Message class packs room message exchanged among various sources. Its fundamental properties include message originator, publishing date, message type, and actual message content. There are three pre-defined message types but developer can easily add custom types through prototype inheritance.

getMessage()

Get the raw message content contained in this message.

parameter:

none

returns:

string The unaltered content of the message.

getBy()

Get the message publisher's handle.

parameter:

none

returns:

string The message originator's handle when the message is published.

getWhen()

The message's publishing date.

parameter:

none

returns:

Date A JavaScript date object that represents the message's publishing timeframe.

getType()

The type of message which can be thought as an indicator to the nature of the message.

parameter:

none

returns:

number ICESpresso Chat Framework pre-defined three messages type to match user-join, user-quit, and user-chat events. Developer can compare the message type against the three pre-defined constants in order to process the message in a way suitable for the application.

ROOM_MSG

Reflects that the message results from chat input.

JOIN_MSG

Reflects that the message results from chatter join.

QUIT_MSG

Reflects that the message results from chatter quit.

Callback function

These callback functions serve as event sinks. The opening section in this reference states that the ICESpresso Chat Framework is built on asynchronous programming model. This technique allows events occur independently of the main program flow. In an interactive environment where events may take place from different sources at random timeframe, asynchronous programming model may prove to be more versatile as it handles events only when necessary rather than waiting indefinitely for non-anticipatable events to occur.

Having said that, it is also noted that asynchronous programming usually breaks the processing flow into two phases where in phase one a command is sent and in phase two the concerning party responds with the command processing result. This inevitably adds complexity to the program structuring but this is the trade-off for versatility.

The ICESpresso Chat Framework defines three callback functions to handle chat-related and web-presence events. icespresso.onSystemEvent is responsible for responding to action that is a result of system-level request. icespresso.onChatEvent processes events related to chat room activities. icespresso.onFriendEvent deals with friends' presence and their whereabouts.

The three callback handlers bear the same calling interface. What they differ lie within the event type and the argument that maps to the type of event.

function icespresso.onSystemEvent(chat, eventId, arg)

This callback handler is called when system-level events occur.

parameter:

chat the ICEspresso object that is identical to the object returned by icespresso.initialize(). It is provided in the handler for convenience.
eventId the event type identifier - SYS_INITIALIZED, SYS_CONNECTED, SYS_DISCONNECTED, SYS_HANDSHAKED, SYS_ROOMEXISTS, SYS_TOTALUSER, SYS_ROOMCHATTER.
args an associative array that contains mixed data depending on event type.

event  SYS_INITIALIZED

This event is a result of icespresso.initialize() call. It is triggered once and only once regardless of number of calls to icespresso.initialize(). This event indicates that ICESpresso Chat Framework has set-up the necessary components. Application can call connect() method after this event has been signaled.

arg contains:

none

event  SYS_CONNECTED

This event is a result of connect() call. This event is basically informational as it will be immediately followed by SYS_HANDSHAKED event.

arg contains:

none

event  SYS_DISCONNECTED

This event is a result of disconnect() call.

arg contains:

msg string - the message always contains "connection lost".

event  SYS_HANDSHAKED

This event is automatically generated when ICESpresso Chat Framework has registered itself with ICEspresso Service immediately after a successful connection. Upon connection, ICESpresso Chat Framework immediately tries to exchange information with ICEspresso Service. The ICEspresso Service will at this time assign a session-level unique connection id to the Framework.

When this event has been signaled, the Framework can be seen as in-sync with the ICEspresso Service, permitting other server-related operations to take place.

arg contains:

msg number - the connection id ICEspresso Service has assigned.

event  SYS_ROOMEXISTS

This event is a result of roomExists() call.

arg contains:

roomName string - the name of room that is queried.
exists boolean - true when room exists on ICEspresso Service, false when otherwise.

event  SYS_TOTALUSER

This event is a result of getTotalUserCount() call. arg contains the query result.

arg contains:

num number - the number of connected chatters within the system.

event  SYS_ROOMCHATTER

This event is a result of getRoomChatterCount() call. arg contains the query result.

arg contains:

rooms associative array - an associative array with key being the name of the room and value being the number of chatters within.
example:
<script language="javascript">
// suppose room Olympic and Sport are hosted,
// having 10 and 20 chatters respectively.
// Room Tennis is non-existent.

icespresso.onSystemEvent(chat, eventId, arg) {
    case chat.SYS_ROOMCHATTER:
        var rooms = arg.rooms;
        /**
         * rooms looks like:
         * rooms["Olympic"] = 10;
         * rooms["Sport"] = 20;
         * rooms["Tennis"] = null;
         */
        break;
}

chat.getRoomChatterCount(["Olympic", "Sport", "Tennis"]);
</script>

function icespresso.onChatEvent(chat, eventId, arg)

This callback handler is called when chat events occur.

parameter:

chat the ICEspresso object that is identical to the object returned by icespresso.initialize(). It is provided in the handler for convenience.
eventId the event type identifier - CHAT_ROOMJOIN, CHAT_ROOMREADY, CHAT_ROOMMSG, CHAT_HANDLEUPDATE, CHAT_ROOMQUIT, CHAT_ROOMKICK.
args an associative array that contains mixed data depending on event type.

event  CHAT_ROOMJOIN

This event is fired when someone else joins the room. Application can take this opportunity to deliver announcement such as displaying join message or adding the new comer's information to the room user list.

arg contains:

room object - the Room object, representing the room that this event occurs within.
chatter object - the Chatter object, representing the joining chatter.
msg object - the Message object of which type is set to JOIN_MSG and by is set to chatter's handle.

event  CHAT_ROOMREADY

This event is triggered exclusively when application successfully joins a room through joinRoom() call. It will be fired once and only once per each room joined. In this event, the ICEspresso Service will send a snapshot of current list of chatters and messages. Application can make use of these raw data to construct visual information for the application user.

arg contains:

messages index-based array - an array containing messages just before application joins the room. The array is constructed in ascending order (lower index means older message).
chatters associative array - an array containing chatters who is participating in the room just before application joins.

event  CHAT_ROOMMSG

This event is fired whenever a chat-input message is exchanged in the room. The arg parameter contains three objects that allow application to identify who said what in which room.

arg contains:

room object - the Room object, representing the room that this event occurs within.
chatter object - the Chatter object, representing the chatter who published this message.
msg object - the Message object of which type is set to ROOM_MSG and by is set to chatter's handle.

event  CHAT_HANDLEUPDATE

This event is fired when someone's handle is changed. The "someone" needs to be in the same room that the application is participating in for this event to occur. When this event occurs, application will be passed a Chatter object with which getHandle() returns the new handle and getLastHandle() returns the old handle.

arg contains:

room object - the Room object, representing the room that this event occurs within.
chatter object - the Chatter object, representing the chatter whose handle has just been changed.

event  CHAT_ROOMQUIT

This event is fired when someone quits the room. The arg parameter contains three objects that allow application to identify who left which room.

arg contains:

room object - the Room object, representing the room that this event occurs within.
chatter object - the Chatter object, representing the quitting chatter.
msg object - the Message object of which type is set to QUIT_MSG and by is set to chatter's handle.

event  CHAT_ROOMKICK

This event is fired when room moderator calls kick() method to remove specified chatter from a room.

arg contains:

room object - the Room object, representing the room that this event occurs within.
kicker object - the Chatter object, representing the kick command issuer.
kicked object - the Chatter object, representing the chatter who's removed from the room.

function icespresso.onFriendEvent(handle, roomName)

This callback handler is called when friends-related events take place.

parameter:

chat the ICEspresso object that is identical to the object returned by icespresso.initialize(). It is provided in the handler for convenience.
eventId the event type identifier. FRIEND_ONLINE, FRIEND_JOINROOM, FRIEND_QUITROOM, FRIEND_OFFLINE, FRIEND_LOCATION, FRIEND_PRIVATEMSG, FRIEND_PMSENT, FRIEND_PMFAILED
args an associative array that contains mixed data depending on event type.

event  FRIEND_ONLINE

This event is fired whenever someone in application's watch list has just registered with ICEspresso Service. In other words, someone in the watch list has signed in.

The watch list is set by using friend-related methods.

arg contains:

connId number - the connection id of the watched entity.
friend string - the unique key of the watched entity.

event  FRIEND_JOINROOM

This event is fired whenever someone in application's watch list has just joined a chat room.

arg contains:

connId number - the connection id of the watched entity.
friend string - the unique key of the watched entity.
roomName string - the name of the room joined.

event  FRIEND_QUITROOM

This event is fired whenever someone in application's watch list has just left a chat room.

arg contains:

connId number - the connection id of the watched entity.
friend string - the unique key of the watched entity.
roomName string - the name of the room joined.

event  FRIEND_OFFLINE

This event is fired whenever someone in application's watch list has just unregistered from the ICEspresso System. In other words, someone in the watch list has signed off.

arg contains:

friend string - the name of the watched entity.

event  FRIEND_LOCATION

This event is fired when application queries friend status. The arg parameter contains the queried result.

arg contains:

friends

associative array - key of the array is the unique key of the watched entity while value of the array is associative array containing two elements, connId and rooms.
- connId is the connection id of the watched entity.
- rooms is an index-based array consisting of name of the rooms the watched entity is in.

example:
<script language="javascript">
/**
 * Suppose we are watching foo, bar, and baz
 * - foo is currently in room A and room B
 * - bar is online but not in any room
 * - baz is offline
 */

// set foo, bar and baz to my watch list
chat.setFriends( ["foo", "bar", "baz"] );

// implement the onFriendEvent handler
icespresso.onFriendEvent = function(chat, eventId, arg) {
    switch (eventId) {
        case chat.FRIEND_LOCATION: {
            var result = arg.friends;
            /** 
             * result would look like this:
             * result["baz"]["connId"] == -1; // baz is offline
             * result["baz"]["rooms"] = null; // baz is offline
             *
             * result["bar"]["connId"] == 1; // bar is online
             * result["bar"]["rooms"] == []; // bar is online but not in any rooms
             *
             * result["foo"]["connId"] == 2; // foo is online
             * result["foo"]["rooms"][0] == "A"; // foo is in room A
             * result["foo"]["rooms"][1] == "B"; // foo is also in room B
             */
            break;
        }
    }
}

// query ICEspresso Service
chat.getFriends();
</script>

event  FRIEND_PRIVATEMSG

This event is fired when a private message is sent to the application user. If application holds several concurrent sessions, each session will receive this message.

arg contains:

msg A Message object that encapsulates handle of the sender, message date, and the message text of this private message.
from The connection id associated with the sender.
handle The current handle used by the sender.
example:
<script language="javascript">
icespresso.onFriendEvent(chat, eventId, arg) {
    switch (eventId) {
        case chat.FRIEND_PRIVATEMSG: {
            var msg = arg.msg;
            var from = arg.from;
            var handle = arg.handle; // equivalent to msg.getBy()

            _DEBUG(handle + " sent you a private message: " + msg.getMessage());
            break;
        }
    }
}
</script>

event  FRIEND_PMSENT

This event is fired when private message is sent to the destined recipient.

arg contains:

msg The original text message sent.
to The connection id associated with the message recipient.
handle The handle currently used by the message recipient.
example:

Please refer to sendPM() for sample code.

event  FRIEND_PMFAILED

This event is fired when ICEspresso Service could not locate the message recipient specified by the id parameter in sendPM().

arg contains:

msg The original text message sent.
to The connection id specified in sendPM() call.
example:

Please refer to sendPM() for sample code.