sfs2x-api
Version:
Official JavaScript client API for SmartFoxServer 2X, the leading SDK to create large scale multiplayer games and MMOs
988 lines (986 loc) • 318 kB
TypeScript
/**
* Creates a new <em>SmartFox</em> instance.
*
* <p>The <em>SmartFox</em> class is responsible for connecting the client to a SmartFoxServer instance and for dispatching all asynchronous events.
* Developers always interact with SmartFoxServer through this class.<br/>
* For detailed informations please check our website: <a href="http://www.smartfoxserver.com" target="_blank">http://www.smartfoxserver.com</a>.</p>
*
* <p>The <em>SmartFox</em> instance can be configured through a configuration object with the following properties (all optional):</p>
*
* <table class="jsdoc-details-table">
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>host</td><td>string</td><td>The IP address or host name of the SmartFoxServer 2X instance to connect to.</td></tr>
* <tr><td>port</td><td>number</td><td>The WebSocket port of the SmartFoxServer 2X instance to connect to.</td></tr>
* <tr><td>useSSL</td><td>boolean</td><td>Use an encrypted SSL connection (WebSocket Secure).</td></tr>
* <tr><td>zone</td><td>string</td><td>The Zone of the SmartFoxServer 2X instance to join during the login process.</td></tr>
* <tr><td>debug</td><td>boolean</td><td>Indicates whether the client-server messages console debug should be enabled or not.</td></tr>
* </table>
*
* <p><b>NOTE</b>: in the examples provided throughout the documentation, <b><code>sfs</code> always indicates a SmartFox instance</b>.</p>
* @example
* <caption>This example instantiates the SmartFox class passing a configuration object.</caption>
* function init()
* {
* // Create configuration object
* var config = {};
* config.host = "127.0.0.1";
* config.port = 8080;
* config.useSSL = false;
* config.zone = "BasicExamples";
* config.debug = false;
*
* // Create SmartFox client instance
* sfs = new SFS2X.SmartFox(config);
* }
* @param [configObj = null] - An object containing the client configuration properties.
*/
export class SmartFox extends EventDispatcher {
constructor(configObj?: any);
/**
* Indicates whether the client-server messages console debug is enabled or not.
* <p>If set to <code>true</code>, detailed debugging informations for all the incoming and outgoing messages are provided in the browser's debug console (if available).
* Debugging can be enabled when instantiating the <em>SmartFox</em> class too by means of the configuration object.</p>
*/
debug: boolean;
/**
* Returns the current version of the SmartFoxServer 2X JavaScript API.
*/
readonly version: string;
/**
* Returns the client configuration object passed during the <em>SmartFox</em> instance creation.
*/
readonly config: any;
/**
* Returns a reference to the internal <em>Logger</em> instance used by SmartFoxServer 2X.
*/
readonly logger: Logger;
/**
* Returns the unique session token of the client.
* <p>The session token is a string sent by the server to the client after the initial handshake.<br/>
* It is required as mean of identification when uploading files to the server (see specific documentation).</p>
*/
readonly sessionToken: string;
/**
* Returns a reference to the Room Manager.
* <p>This manager is used internally by the SmartFoxServer 2X API; the reference returned by this property
* gives access to the Rooms list and Groups, allowing interaction with <em>SFSRoom</em> objects.</p>
*/
readonly roomManager: SFSRoomManager;
/**
* Returns a reference to the User Manager.
* <p>This manager is used internally by the SmartFoxServer 2X API; the reference returned by this property
* gives access to the users list, allowing interaction with <em>SFSUser</em> objects.</p>
*/
readonly userManager: SFSUserManager;
/**
* Returns a reference to the Buddy Manager.
* <p>This manager is used internally by the SmartFoxServer 2X API; the reference returned by this property
* gives access to the buddies list, allowing interaction with <em>Buddy</em> and <em>BuddyVariable</em> objects and access to user properties in the <b>Buddy List</b> system.</p>
*/
readonly buddyManager: SFSBuddyManager;
/**
* Returns the <em>SFSUser</em> object representing the client itself when connected to a SmartFoxServer 2X instance.
*
* <p>This object is generated upon successful login only, so it is <code>null</code> if login was not performed yet.</p>
*
* <p><b>NOTE</b>: setting the <em>mySelf</em> property manually can disrupt the API functioning.</p>
*/
readonly mySelf: SFSUser;
/**
* Returns the object representing the last Room joined by the client, if any.
*
* <p>This property is <code>null</code> if no Room was joined.</p>
*/
readonly lastJoinedRoom: SFSRoom;
/**
* Indicates whether the client is connected to the server or not.
* @example
* <caption>This example checks the connection status.</caption>
* console.log("Am I connected? " + sfs.isConnected);
*/
readonly isConnected: boolean;
/**
* Returns the maximum size of messages allowed by the server.
* <p>Any request exceeding this size will not be sent. The value is determined by the server configuration.</p>
*/
readonly maxMessageSize: number;
/**
* <b>[CLUSTER]</b> The identifier of the cluster node which the current SmartFox instance is connected to.
*
* <p> If the SmartFox instance is not connected to a cluster node, this property is <code>null</code>.</p>
*/
readonly nodeId: string;
/**
* Allows to specify custom client details that will be used to gather statistics about the client platform via the AdminTool's Analytics Module.
*
* <p>By default no details are sent and the client type is the generic "JavaScript".</p>
*
* <p><b>NOTE</b>: this method must be called before the connection is started. The length of the two strings combined must be less than 512 characters.</p>
* @param platformId - An identification string for the client, like the browser name for example.
* @param version - An additional string to describe the client version, like the browser version for example.
*/
setClientDetails(platformId: string, version: string): void;
/**
* Establishes a connection between the client and a SmartFoxServer 2X instance.
*
* <p>If one or more arguments are missing, the client will use the corresponding settings passed during the <em>SmartFox</em> class instantiation.</p>
* @example
* <caption>This example connects to a local SmartFoxServer 2X instance.</caption>
* function someMethod()
* {
* sfs = new SFS2X.SmartFox();
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
*
* // Connect
* sfs.connect(127.0.0.1, 8080);
* }
*
* function onConnection(evtParams)
* {
* if (evtParams.success)
* console.log("Connection established");
* else
* console.log("Connection failed");
* }
* @param [host = null] - The address of the server to connect to.
* @param [port = -1] - The TCP port to connect to.
* @param [useSSL = null] - Use an encrypted SSL connection.
*/
connect(host?: string, port?: number, useSSL?: boolean): void;
/**
* Closes the connection between the client and the SmartFoxServer 2X instance.
*/
disconnect(): void;
/**
* Simulates an abrupt disconnection from the server.
*
* <p>This method should be used for testing and simulations only, otherwise use the <see cref="Disconnect()"/> method.</p>
*/
killConnection(): void;
/**
* Enables the automatic realtime monitoring of the lag between the client and the server (round robin).
*
* <p>When turned on, the <em>pingPong</em> event type is dispatched continuously, providing the average of the last ten measured lag values.
* The lag monitoring is automatically halted when the user logs out of a Zone or gets disconnected.</p>
*
* <p><b>NOTE</b>: the lag monitoring can be enabled after the login has been completed successfully only.</p>
* @param enabled - The lag monitoring status: <code>true</code> to start the monitoring, <code>false</code> to stop it.
* @param [interval = 4] - The amount of seconds to wait between each query (recommended 3-4s).
* @param [queueSize = 10] - The amount of values stored temporarily and used to calculate the average lag.
*/
enableLagMonitor(enabled: boolean, interval?: number, queueSize?: number): void;
/**
* Sends a request to the server.
* @example
* <caption>This example shows how to send a login request.</caption>
* sfs.send(new SFS2X.LoginRequest("KermitTheFrog", "kermitPwd", null, "TheMuppetZone"));
* @example
* <caption>This example sends a "join room" request.</caption>
* sfs.send(new SFS2X.JoinRoomRequest("Lobby"));
* @example
* <caption>This example creates an object containing some parameters and sends it to the server-side Extension.</caption>
* var params = new SFS2X.SFSObject();
* params.putInt("x", 10);
* params.putInt("y", 37);
*
* sfs.send(new SFS2X.ExtensionRequest("setPosition", params));
* @param request - A request object.
*/
send(request: BaseRequest): void;
/**
* Retrieves a <em>SFSRoom</em> object from its id.
*
* <p><b>NOTE</b>: the same object is returned by the <em>SFSRoomManager.getRoomById()</em> method, accessible through the <em>roomManager</em> property;
* this was replicated on the <em>SmartFox</em> class for handy access due to its usually frequent usage.</p>
* @example
* <caption>This example retrieves a SFSRoom object and traces its name.</caption>
* var roomId = 3;
* var room = sfs.getRoomById(roomId);
* console.log("The name of Room " + roomId + " is " + room.name);
* @param id - The id of the Room.
* @returns The object representing the requested Room; <code>undefined</code> if no <em>SFSRoom</em> object with the passed id exists in the Rooms list.
*/
getRoomById(id: number): SFSRoom;
/**
* Retrieves a <em>SFSRoom</em> object from its name.
*
* <p><b>NOTE</b>: the same object is returned by the <em>SFSRoomManager.getRoomByName()</em> method, accessible through the <em>roomManager</em> property;
* this was replicated on the <em>SmartFox</em> class for handy access due to its usually frequent usage.</p>
* @example
* <caption>This example retrieves a SFSRoom object and traces its id.</caption>
* var roomName = "The Lobby";
* var room = sfs.getRoomByName(roomName);
* console.log("The ID of Room '" + roomName + "' is " + room.id);
* @param name - The name of the Room.
* @returns The object representing the requested Room; <code>undefined</code> if no <em>SFSRoom</em> object with the passed name exists in the Rooms list.
*/
getRoomByName(name: string): SFSRoom;
/**
* Returns the list of <em>SFSRoom</em> objects representing the Rooms currently "watched" by the client.
*
* <p>The list contains all the Rooms that are currently joined and all the Rooms belonging to the Room Groups that have been subscribed by the client.</p>
*
* <p><b>NOTE 1</b>: at login time, the client automatically subscribes all the Room Groups specified in the Zone's <b>Default Room Groups</b> setting.</p>
*
* <p><b>NOTE 2</b>: the same list is returned by the <em>SFSRoomManager.getRoomList()</em> method, accessible through the <em>roomManager</em> property;
* this was replicated on the <em>SmartFox</em> class for handy access due to its usually frequent usage.</p>
* @returns The list of <em>SFSRoom</em> objects representing the Rooms available on the client.
*/
getRoomList(): SFSRoom[];
/**
* Retrieves the list of Rooms which are part of the specified Room Group.
*
* <p><b>NOTE</b>: the same list is returned by the <em>SFSRoomManager.getRoomListFromGroup()</em> method, accessible through the <em>roomManager</em> property;
* this was replicated on the <em>SmartFox</em> class for handy access due to its usually frequent usage.</p>
* @param groupId - The name of the Group.
* @returns The list of <em>SFSRoom</em> objects belonging to the passed Group.
*/
getRoomListFromGroup(groupId: string): SFSRoom[];
/**
* Returns a list of <em>SFSRoom</em> objects representing the Rooms currently joined by the client.
*
* <p><b>NOTE</b>: the same list is returned by the <em>SFSRoomManager.getJoinedRooms()</em> method, accessible through the <em>roomManager</em> property;
* this was replicated on the <em>SmartFox</em> class for handy access due to its usually frequent usage.</p>
* @returns The list of <em>SFSRoom</em> objects representing the Rooms joined by the client.
*/
getJoinedRooms(): SFSRoom[];
/**
* Registers an event listener function that will receive notification of an event.
*
* <p>If you no longer need an event listener, remove it by calling the <em>removeEventListener()</em> method, or memory issues could arise.
* In fact event listeners are not automatically removed from memory.</p>
* @example
* <caption>This example shows how to add a number of common event listeners to the SmartFox instance, usually during initialization:</caption>
* function init()
* {
* sfs = new SFS2X.SmartFox();
*
* // Add LoggerEvent listeners
* sfs.logger.addEventListener(SFS2X.LoggerEvent.DEBUG, onDebugMessage, this);
* sfs.logger.addEventListener(SFS2X.LoggerEvent.INFO, onInfoMessage, this);
* sfs.logger.addEventListener(SFS2X.LoggerEvent.WARNING, onWarningMessage, this);
* sfs.logger.addEventListener(SFS2X.LoggerEvent.ERROR, onErrorMessage, this);
*
* // Add SFSEvent listeners
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGOUT, onLogout, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoin, this);
* }
* @param evtType - The type of event to listen to, among those available in the <em>SFSEvent</em>, <em>SFSBuddyEvent</em> and <em>LoggerEvent</em> classes.
* @param callback - The listener function that processes the event. This function should accept an object as its only parameter, which in turn contains the event parameters.
* @param scope - The object that acts as a context for the event listener: it is the object that acts as a "parent scope" for the callback function, thus providing context (i.e. access to variables and other mehtods) to the function itself.
*/
addEventListener(evtType: string, callback: (...params: any[]) => any, scope: any): void;
/**
* Removes an event listener.
* @param evtType - The type of event to remove, among those available in the <em>SFSevent</em>, <em>SFSBuddyEvent</em> and <em>LoggerEvent</em> classes.
* @param callback - The listener function to be removed.
*/
removeEventListener(evtType: string, callback: (...params: any[]) => any): void;
}
/**
* <b>Developers never istantiate the <em>EventDispatcher</em> class</b>: this is done internally by the SmartFoxServer 2X API.
*/
export class EventDispatcher {
/**
* Registers an event listener function that will receive notification of an event.
*
* <p>If you no longer need an event listener, remove it by calling the <em>removeEventListener()</em> method, or memory issues could arise.
* In fact event listeners are not automatically removed from memory.</p>
* @example
* <caption>This example shows how to add a number of common event listeners to the SmartFox instance, usually during initialization:</caption>
* function init()
* {
* sfs = new SFS2X.SmartFox();
*
* // Add LoggerEvent listeners
* sfs.logger.addEventListener(SFS2X.LoggerEvent.DEBUG, onDebugMessage, this);
* sfs.logger.addEventListener(SFS2X.LoggerEvent.INFO, onInfoMessage, this);
* sfs.logger.addEventListener(SFS2X.LoggerEvent.WARNING, onWarningMessage, this);
* sfs.logger.addEventListener(SFS2X.LoggerEvent.ERROR, onErrorMessage, this);
*
* // Add SFSEvent listeners
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGOUT, onLogout, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoin, this);
* }
* @param evtType - The type of event to listen to, among those available in the <em>SFSEvent</em>, <em>SFSBuddyEvent</em> and <em>LoggerEvent</em> classes.
* @param callback - The listener function that processes the event. This function should accept an object as its only parameter, which in turn contains the event parameters.
* @param scope - The object that acts as a context for the event listener: it is the object that acts as a "parent scope" for the callback function, thus providing context (i.e. access to variables and other mehtods) to the function itself.
*/
addEventListener(evtType: string, callback: (...params: any[]) => any, scope: any): void;
/**
* Removes an event listener.
* @param evtType - The type of event to remove, among those available in the <em>SFSevent</em>, <em>SFSBuddyEvent</em> and <em>LoggerEvent</em> classes.
* @param callback - The listener function to be removed.
*/
removeEventListener(evtType: string, callback: (...params: any[]) => any): void;
}
/**
* <b>Developers never istantiate the <em>SFSEvent</em> class</b>: only use its static properties.
*
* <p>The constants contained in this class are used to register the event listeners; when an event is dispatched, an object containing event-specific parameters is passed to the listener.
* See the documentation below for a description of the parameters available for each event.</p>
* @example
* <caption>This example shows the generic approach to be implemented to listen to events; please refer to the specific event types for the parameters object content.</caption>
* var sfs = null;
*
* function init()
* {
* // Create SmartFox client instance
* sfs = new SFS2X.SmartFox();
*
* // Add event listener for connection
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
*
* // Connect to the server
* sfs.connect("127.0.0.1", 8080);
* }
*
* // Handle connection event
* function onConnection(evtParams)
* {
* if (evtParams.success)
* console.log("Connected to SmartFoxServer 2X!");
* else
* console.log("Connection failed. Is the server running at all?");
* }
*/
export class SFSEvent {
constructor();
/**
* The <em>connection</em> event type, dispatched when a connection between the client and a SmartFoxServer 2X instance is attempted.
*
* <p>This event is fired in response to a call to the <em>SmartFox.connect()</em> method.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>success</td><td>boolean</td><td>The connection result: <code>true</code> if a connection was established, <code>false</code> otherwise.</td></tr>
* </table>
* @example
* <caption>This example starts a connection.</caption>
* function someMethod()
* {
* sfs = new SFS2X.SmartFox();
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
*
* sfs.connect(127.0.0.1, 8080);
* }
*
* function onConnection(evtParams)
* {
* if (evtParams.success)
* console.log("Connection established");
* else
* console.log("Connection failed");
* }
*/
static readonly CONNECTION: string;
/**
* The <em>connectionLost</em> event type, dispatched when the connection between the client and the SmartFoxServer 2X instance is interrupted.
*
* <p>This event is fired in response to a call to the <em>SmartFox.disconnect()</em> method.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>reason</td><td>string</td><td>The reason of the disconnection, among those available in the <em>ClientDisconnectionReason</em> class.</td></tr>
* </table>
* @example
* <caption>This example handles a disconnection event:</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);
* }
*
* function onConnectionLost(evtParams)
* {
* var reason = evtParams.reason;
*
* if (reason != SFS2X.ClientDisconnectionReason.MANUAL)
* {
* if (reason == SFS2X.ClientDisconnectionReason.IDLE)
* console.log("A disconnection occurred due to inactivity");
* else if (reason == SFS2X.ClientDisconnectionReason.KICK)
* console.log("You have been kicked by the moderator");
* else if (reason == SFS2X.ClientDisconnectionReason.BAN)
* console.log("You have been banned by the moderator");
* else
* console.log("A disconnection occurred due to unknown reason; please check the server log");
* }
* else
* {
* // Manual disconnection is usually ignored
* }
* }
*/
static readonly CONNECTION_LOST: string;
/**
* The <em>login</em> event type, dispatched when the current user performs a successful login in a server Zone.
*
* <p>This event is fired in response to the <em>LoginRequest</em> request.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>user</td><td>{@link SFSUser}</td><td>An object representing the user who performed the login.</td></tr>
* <tr><td>data</td><td>{@link SFSObject}</td><td>A <em>SFSObject</em> containing custom parameters returned by a custom login system, if any.</td></tr>
* </table>
* @example
* <caption>This example performs a login in the "BasicExamples" Zone:</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
* sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
*
* // Login
* sfs.send(new SFS2X.LoginRequest("FozzieTheBear", "", "BasicExamples"));
* }
*
* function onLogin(evtParams)
* {
* console.log("Login successful!");
* }
*
* function onLoginError(evtParams
* {
* console.log("Login failure: " + evtParams.errorMessage);
* }
*/
static readonly LOGIN: string;
/**
* The <em>loginError</em> event type, dispatched if an error occurs while the user login is being performed.
*
* <p>This event is fired in response to the <em>LoginRequest</em> request in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>LOGIN</em> constant description.</p>
*/
static readonly LOGIN_ERROR: string;
/**
* The <em>logout</em> event type, dispatched when the current user performs logs out of the server Zone.
*
* <p>This event is fired in response to the <em>LogoutRequest</em> request.</p>
*
* <table class="jsdoc-details-table">
* <caption>No parameters are available for this event object.</caption>
* </table>
* @example
* <caption>This example performs a logout from the current Zone.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.LOGOUT, onLogout, this);
*
* // Logout
* sfs.send(new SFS2X.Requests.System.LogoutRequest());
* }
*
* function onLogout(evtParams)
* {
* console.log("Logout executed!");
* }
*/
static readonly LOGOUT: string;
/**
* The <em>roomAdd</em> event type, dispatched when a new Room is created inside the Zone under any of the Room Groups that the client subscribed.
*
* <p>This event is fired in response to the <em>CreateRoomRequest</em> and <em>CreateSFSGameRequest</em> requests in case the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room that was created.</td></tr>
* </table>
* @example
* <caption>This example creates a new chat Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_ADD, onRoomCreated, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError, this);
*
* // Define the settings of a new chat Room
* var settings = new SFS2X.RoomSettings("My Chat Room");
* settings.maxUsers = 40;
* settings.groupId = "chats";
*
* // Create the Room
* sfs.send(new SFS2X.CreateRoomRequest(settings));
* }
*
* function onRoomCreated(evtParams)
* {
* console.log("Room created: " + evtParams.room);
* }
*
* function onRoomCreationError(evtParams)
* {
* console.log("Room creation failure: " + evtParams.errorMessage);
* }
*/
static readonly ROOM_ADD: string;
/**
* The <em>roomCreationError</em> event type, dispatched if an error occurs while creating a new Room.
*
* <p>This event is fired in response to the <em>CreateRoomRequest</em> and <em>CreateSFSGameRequest</em> requests in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>ROOM_ADD</em> constant description.</p>
*/
static readonly ROOM_CREATION_ERROR: string;
/**
* The <em>roomRemove</em> event type, dispatched when a Room belonging to one of the Groups subscribed by the client is removed from the Zone.
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room that was removed.</td></tr>
* </table>
* @example
* <caption>This example shows how to handle this event type.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_REMOVE, onRoomRemoved, this);
* }
*
* function onRoomRemoved(evtParams)
* {
* console.log("The following Room was removed: " + evtParams.room);
* }
*/
static readonly ROOM_REMOVE: string;
/**
* The <em>roomJoin</em> event type, dispatched when a Room is joined by the current user.
*
* <p>This event is fired in response to the <em>JoinRoomRequest</em> and <em>QuickJoinGameRequest</em> requests in case the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room that was joined.</td></tr>
* </table>
* @example
* <caption>This example makes the user join an existing Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoined, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
*
* // Join a Room called "Lobby"
* sfs.send(new SFS2X.JoinRoomRequest("Lobby"));
* }
*
* function onRoomJoined(evtParams)
* {
* console.log("Room joined successfully: " + evtParams.room);
* }
*
* function onRoomJoinError(evtParams)
* {
* console.log("Room joining failed: " + evtParams.errorMessage);
* }
*/
static readonly ROOM_JOIN: string;
/**
* The <em>roomJoinError</em> event type, dispatched when an error occurs while the current user is trying to join a Room.
*
* <p>This event is fired in response to the <em>JoinRoomRequest</em> request in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>ROOM_JOIN</em> constant description.</p>
*/
static readonly ROOM_JOIN_ERROR: string;
/**
* The <em>userEnterRoom</em> event type, dispatched when one of the Rooms joined by the current user is entered by another user.
*
* <p>This event is caused by a <em>JoinRoomRequest</em> request; it might be fired or not depending on the Room configuration defined upon its creation (see the <em>RoomSettings.events</em> setting).</p>
*
* <p><b>NOTE</b>: if the Room is of type <em>MMORoom</em>, this event is never fired and it is substituted by the <em>proximityListUpdate</em> event.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>user</td><td>{@link SFSUser}</td><td>An object representing the user who joined the Room.</td></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room that was joined by a user.</td></tr>
* </table>
* @example
* <caption>This example shows how to handle this event type.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.USER_ENTER_ROOM, onUserEnterRoom, this);
* }
*
* function onUserEnterRoom(evtParams)
* {
* var room = evtParams.room;
* var user = evtParams.user;
*
* console.log("User " + user.name + " just joined Room " + room.name);
* }
*/
static readonly USER_ENTER_ROOM: string;
/**
* The <em>userExitRoom</em> event type, dispatched when one of the Rooms joined by the current user is left by another user, or by the current user himself.
*
* <p>This event is caused by a <em>LeaveRoomRequest</em> request; it might be fired or not depending on the Room configuration defined upon its creation (see the <em>RoomSettings.events</em> setting).</p>
*
* <p><b>NOTE</b>: if the Room is of type <em>MMORoom</em>, this event is fired when the current user leaves the Room only.
* For the other users leaving the Room it is substituted by the <em>proximityListUpdate</em> event.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>user</td><td>{@link SFSUser}</td><td>An object representing the user who left the Room.</td></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room that was left by a user.</td></tr>
* </table>
* @example
* <caption>This example shows how to handle this event type.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.USER_EXIT_ROOM, onUserExitRoom, this);
* }
*
* function onUserExitRoom(evtParams)
* {
* var room = evtParams.room;
* var user = evtParams.user;
*
* console.log("User " + user.name + " just left Room " + room.name);
* }
*/
static readonly USER_EXIT_ROOM: string;
/**
* The <em>userCountChange</em> event type, dispatched when the number of users/players or spectators inside a Room changes.
*
* <p>This event is caused by a <em>JoinRoomRequest</em> request or a <em>LeaveRoomRequest</em> request.
* The Room must belong to one of the Groups subscribed by the current client; also this event might be fired or not depending on
* the Room configuration defined upon its creation (see the <em>RoomSettings.events</em> setting).</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room in which the users count changed.</td></tr>
* <tr><td>uCount</td><td>number</td><td>The new users count (players in case of Game Room).</td></tr>
* <tr><td>sCount</td><td>number</td><td>The new spectators count (Game Room only).</td></tr>
* </table>
* @example
* <caption>This example shows how to handle this event type.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.USER_COUNT_CHANGE, onUserCountChange, this);
* }
*
* function onUserCountChange(evtParams)
* {
* var room = evtParams.room;
* var uCount = evtParams.uCount;
* var sCount = evtParams.sCount;
*
* console.log("Room: " + room.name + " now contains " + uCount + " users and " + sCount + " spectators");
* }
*/
static readonly USER_COUNT_CHANGE: string;
/**
* The <em>proximityListUpdate</em> event type, dispatched when one more users or one or more <em>MMOItem</em> objects enter/leave the current user's Area of Interest in a <em>MMORoom</em>.
*
* <p>This event is fired after an <em>MMORoom</em> is joined and the <em>SetUserPositionRequest</em> request is sent at least one time.</p>
*
* <p><b>NOTE</b>: this event substitutes the default <em>userEnterRoom</em> and <em>userExitRoom</em> events available in regular Rooms.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>addedUsers</td><td><code>Array of {@link SFSUser}</code></td><td>A list of <em>SFSUser</em> objects representing the users who entered the current user's Area of Interest.</td></tr>
* <tr><td>removedUsers</td><td><code>Array of {@link SFSUser}</code></td><td>A list of <em>SFSUser</em> objects representing the users who left the current user's Area of Interest.</td></tr>
* <tr><td>addedItems</td><td><code>Array of {@link MMOItem}</code></td><td>A list of <em>MMOItem</em> objects which entered the current user's Area of Interest.</td></tr>
* <tr><td>removedItems</td><td><code>Array of {@link MMOItem}</code></td><td>A list of <em>MMOItem</em> objects which left the current user's Area of Interest.</td></tr>
* </table>
* @example
* <caption>This example shows how to handle the proximity user list provided by the event in order to add new avatars on the screen and remove those who left the current user's proximity range.</caption>
* function onProximityListUpdate(evtParams)
* {
* var added = evtParams.addedUsers;
* var removed = evtParams.removedUsers;
*
* // Add users that entered the proximity list
* for (var i = 0; i < added.length; i++)
* {
* var user = added[i];
*
* // Obtain the coordinates at which the user "appeared" in our range
* var entryPoint = user.aoiEntryPoint;
*
* // Add new avatar on screen
* var avatarSprite = new AvatarSprite();
* avatarSprite.x = entryPoint.px;
* avatarSprite.y = entryPoint.py;
* ...
* }
*
* // Remove users that left the proximity list
* for (var j = 0; j < removed.length; j++)
* {
* var user = removed[j];
*
* // Remove the avatar from screen
* ...
* }
* }
*/
static readonly PROXIMITY_LIST_UPDATE: string;
/**
* The <em>playerToSpectator</em> event type, dispatched when a player is turned to a spectator inside a Game Room.
*
* <p>This event is fired in response to the <em>PlayerToSpectatorRequest</em>> request if the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room in which the player is turned to spectator.</td></tr>
* <tr><td>user</td><td>{@link SFSUser}</td><td>An object representing the player who was turned to spectator.</td></tr>
* </table>
* @example
* <caption>This example turns the current user from player to spectator in the last joined Game Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.PLAYER_TO_SPECTATOR, onPlayerToSpectatorSwitch, this);
* sfs.addEventListener(SFS2X.SFSEvent.PLAYER_TO_SPECTATOR_ERROR, onPlayerToSpectatorSwitchError, this);
*
* // Switch player to spectator
* sfs.send(new SFS2X.PlayerToSpectatorRequest());
* }
*
* function onPlayerToSpectatorSwitch(evtParams)
* {
* console.log("Player " + evtParams.user + " is now a spectator");
* }
*
* function onPlayerToSpectatorSwitchError(evtParams)
* {
* console.log("Unable to become a spectator due to the following error: " + evtParams.errorMessage);
* }
*/
static readonly PLAYER_TO_SPECTATOR: string;
/**
* The <em>playerToSpectatorError</em> event type, dispatched when an error occurs while the current user is being turned from player to spectator in a Game Room.
*
* <p>This event is fired in response to the <em>PlayerToSpectatorRequest</em> request in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>PLAYER_TO_SPECTATOR</em> constant description.</p>
*/
static readonly PLAYER_TO_SPECTATOR_ERROR: string;
/**
* The <em>spectatorToPlayer</em> event type, dispatched when a spectator is turned to a player inside a Game Room.
*
* <p>This event is fired in response to the <em>SpectatorToPlayerRequest</em>> request if the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room in which the spectator is turned to player.</td></tr>
* <tr><td>user</td><td>{@link SFSUser}</td><td>An object representing the spectator who was turned to player.</td></tr>
* <tr><td>playerId</td><td>number</td><td>The player id of the user.</td></tr>
* </table>
* @example
* <caption>This example turns the current user from spectator to player in the last joined Game Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.SPECTATOR_TO_PLAYER, onSpectatorToPlayerSwitch, this);
* sfs.addEventListener(SFS2X.SFSEvent.SPECTATOR_TO_PLAYER_ERROR, onSpectatorToPlayerSwitchError, this);
*
* // Switch spectator to player
* sfs.send(new SFS2X.SpectatorToPlayerRequest());
* }
*
* function onSpectatorToPlayerSwitch(evtParams)
* {
* console.log("Spectator " + evtParams.user + " is now a player");
* }
*
* function onSpectatorToPlayerSwitchError(evtParams)
* {
* console.log("Unable to become a player due to the following error: " + evtParams.errorMessage);
* }
*/
static readonly SPECTATOR_TO_PLAYER: string;
/**
* The <em>spectatorToPlayerError</em> event type, dispatched when an error occurs while the current user is being turned from spectator to player in a Game Room.
*
* <p>This event is fired in response to the <em>SpectatorToPlayerRequest</em> request in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>SPECTATOR_TO_PLAYER</em> constant description.</p>
*/
static readonly SPECTATOR_TO_PLAYER_ERROR: string;
/**
* The <em>roomNameChange</em> event type, dispatched when the name of a Room is changed.
*
* <p>This event is fired in response to the <em>ChangeRoomNameRequest</em> request if the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room which was renamed.</td></tr>
* <tr><td>oldName</td><td>string</td><td>The previous name of the Room.</td></tr>
* </table>
* @example
* <caption>This example renames an existing Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_NAME_CHANGE, onRoomNameChanged, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_NAME_CHANGE_ERROR, onRoomNameChangeError, this);
*
* var theRoom = sfs.getRoomByName("Gonzo's Room");
* sfs.send(new SFS2X.ChangeRoomNameRequest(theRoom, "Gonzo The Great's Room"));
* }
*
* function onRoomNameChanged(evtParams)
* {
* console.log("Room " + evtParams.oldName + " was successfully renamed to " + evtParams.room.name);
* }
*
* function onRoomNameChangeError(evtParams)
* {
* console.log("Room name change failed: " + evtParams.errorMessage);
* }
*/
static readonly ROOM_NAME_CHANGE: string;
/**
* The <em>roomNameChangeError</em> event type, dispatched when an error occurs while attempting to change the name of a Room.
*
* <p>This event is fired in response to the <em>ChangeRoomNameRequest</em> request in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>ROOM_NAME_CHANGE</em> constant description.</p>
*/
static readonly ROOM_NAME_CHANGE_ERROR: string;
/**
* The <em>roomPasswordStateChange</em> event type, dispatched when the password of a Room is set, changed or removed.
*
* <p>This event is fired in response to the <em>ChangeRoomPasswordStateRequest</em>> request if the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room whose password was changed.</td></tr>
* </table>
* @example
* <caption>This example changes the password of an existing Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_PASSWORD_STATE_CHANGE, onRoomPasswordStateChanged, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR, onRoomPasswordStateChangeError, this);
*
* var theRoom = sfs.getRoomByName("Gonzo's Room");
* sfs.send(new SFS2X.ChangeRoomPasswordStateRequest(theRoom, "mammamia"));
* }
*
* function onRoomPasswordStateChanged(evtParams)
* {
* console.log("The password of Room " + evtParams.room.name + " was changed successfully");
* }
*
* function onRoomPasswordStateChangeError(evtParams)
* {
* console.log("Room password change failed: " + evtParams.errorMessage);
* }
*/
static readonly ROOM_PASSWORD_STATE_CHANGE: string;
/**
* The <em>roomPasswordStateChangeError</em> event type, dispatched when an error occurs while attempting to set, change or remove the password of a Room.
*
* <p>This event is fired in response to the <em>ChangeRoomPasswordStateRequest</em> request in case the operation failed.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>errorMessage</td><td>string</td><td>A message containing the description of the error.</td></tr>
* <tr><td>errorCode</td><td>number</td><td>The error code.</td></tr>
* </table>
*
* <p>See the example provided in the <em>ROOM_PASSWORD_STATE_CHANGE</em> constant description.</p>
*/
static readonly ROOM_PASSWORD_STATE_CHANGE_ERROR: string;
/**
* The <em>roomCapacityChange</em> event type, dispatched when the capacity of a Room is changed.
*
* <p>This event is fired in response to the <em>ChangeRoomCapacityRequest</em>> request if the operation is executed successfully.</p>
*
* <table class="jsdoc-details-table">
* <caption>The object passed to the listener contains the following parameters:</caption>
* <tr><th>Property</th><th>Type</th><th>Description</th></tr>
* <tr><td>room</td><td>{@link SFSRoom}</td><td>An object representing the Room whose capacity was changed.</td></tr>
* </table>
* @example
* <caption>This example changes the capacity of an existing Room.</caption>
* function someMethod()
* {
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_CAPACITY_CHANGE, onRoomCapacityChanged, this);
* sfs.addEventListener(SFS2X.SFSEvent.ROOM_CAPACITY_CHANGE_ERROR, onRoomCapacityChangeError, this);
*
* var theRoom = sfs.getRoomByName("Gonzo's Room");
*
* // Resize the Room so that it allows a maximum of 100 users and zero spectators
* sfs.send(new SFS2X.ChangeRoomCapacityRequest(theRoom, 100, 0));
* }
*
* function onRoomCapacityChanged(evtParams)
* {
* console.log("The capacity of Room " + evtParams.room.name + " was changed successfully");
* }
*
* function onRoomCapacityChangeError(evtParams)
* {
* console.log("Room capacity change failed: " + evtParams.errorMessage);
* }
*/
static readonly ROOM_CAPACITY_CHANGE: string;
/**
* The <em>roomCapacityChangeError</em> event type, dispatched when an error occurs while attempting to change the capacity of a Room.
*
* <p>This event is fired in response to t