@senspark/sfs2x-api
Version:
declaration file for smartfox
1,186 lines (988 loc) • 165 kB
TypeScript
// tslint:disable:member-access
// tslint:disable-next-line:no-namespace
declare namespace SFS2X {
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/ClientDisconnectionReason.html
*
* The possible reasons why a disconnection from the server occurred.
*/
enum ClientDisconnectionReason {
/**
* Client was banned from the server.
*
* Banning can occur automatically (i.e. for flooding, if the flood filter is active) or due to the intervention
* of a user with enough privileges (i.e. an administrator or a moderator).
*/
BAN,
/**
* Client was disconnected because it was idle for too long.
*
* The connection timeout depends on the server settings.
*/
IDLE,
/**
* Client was kicked out of the server.
*
* Kicking can occur automatically (i.e. for swearing, if the words filter is active) or due to the intervention
* of a user with enough privileges (i.e. an administrator or a moderator).
*/
KICK,
/**
* The client manually disconnected from the server.
*
* The disconnect() method on the SmartFox class was called.
*/
MANUAL,
/**
* A generic network error occurred, and the client is unable to determine the cause of the disconnection.
*
* The server-side log should be checked for possible error messages or warnings.
*/
UNKNOWN,
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSErrorCodes.html
*
* The SmartFoxServer error codes and the related error messages.
*
* This class class provides a mean of translation between server error codes and the related error messages.
*
* Error messages are provided by defualt in the English language but they can be localized and substituted in any
* other language. The error messages contain special placeholders that are processed at runtime and substituted
* with runtime data. They are in the form of a number enclosed in curly brackets such as: {0}, {1}, etc. Please
* make sure you maintain these placeholders while translating the messages.
*/
class SFSErrorCodes {
/**
* Sets the text of the error message corresponding to the passed error code.
*
* NOTE: you have to make sure you maintain all the placeholders while modifying a message.
*
* @param code The code of the error message to be modified.
* @param message The new error message, including the placeholders for runtime informations.
*/
static setErrorMessage(code: number, message: string): void;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSEvent.html
*
* The main event types dispatched by the SmartFoxServer 2X JavaScript API.
*/
class SFSEvent {
/**
* The adminMessage event type, dispatched when the current user receives a message from an administrator user.
*
* This event is caused by the AdminMessageRequest request sent by a user with administration privileges.
*/
static readonly ADMIN_MESSAGE;
/**
* The connection event type, dispatched when a connection between the client and a SmartFoxServer 2X instance
* is attempted.
*
* This event is fired in response to a call to the SmartFox.connect() method.
*/
static readonly CONNECTION;
/**
* The connectionLost event type, dispatched when the connection between the client and the SmartFoxServer 2X
* instance is interrupted.
*
* This event is fired in response to a call to the SmartFox.disconnect() method.
*/
static readonly CONNECTION_LOST;
/**
* The extensionResponse event type, dispatched when data coming from a server-side Extension is received by the
* current user.
*
* Data is usually sent by the server to one or more clients in response to an ExtensionRequest request, but not
* necessarily.
*/
static readonly EXTENSION_RESPONSE;
/**
* The invitation event type, dispatched when the current user receives an invitation from another user.
*
* This event is caused by the InviteUsersRequest and CreateSFSGameRequest requests; the user is supposed to
* reply using the InvitationReplyRequest request.
*/
static readonly INVITATION;
/**
* The invitationReply event type, dispatched when the current user receives a reply to an invitation he sent
* previously.
*
* This event is caused by the InvitationReplyRequest request sent by the invitee.
*/
static readonly INVITATION_REPLY;
/**
* The invitationReplyError event type, dispatched when an error occurs while the current user is sending a
* reply to an invitation he received.
*
* This event is fired in response to the InvitationReplyRequest request in case the operation failed.
*/
static readonly INVITATION_REPLY_ERROR;
/**
* The login event type, dispatched when the current user performs a successful login in a server Zone.
*
* This event is fired in response to the LoginRequest request.
*/
static readonly LOGIN;
/**
* The loginError event type, dispatched if an error occurs while the user login is being performed.
*
* This event is fired in response to the LoginRequest request in case the operation failed.
*/
static readonly LOGIN_ERROR;
/**
* The logout event type, dispatched when the current user performs logs out of the server Zone.
*
* This event is fired in response to the LogoutRequest request.
*/
static readonly LOGOUT;
/**
* The mmoItemVariablesUpdate event type, dispatched when an MMOItem Variable is updated in an MMORoom.
*
* This event is caused by an MMOItem Variable being set, updated or deleted in a server side Extension, and it
* is received only if the current user has the related MMOItem in his Area of Interest.
*/
static readonly MMOITEM_VARIABLES_UPDATE;
/**
* The moderatorMessage event type, dispatched when the current user receives a message from a moderator user.
*
* This event can be caused by either the ModeratorMessageRequest, KickUserRequest or BanUserRequest requests
* sent by a user with at least moderation privileges. Also, this event can be caused by a kick/ban action
* executed through the SmartFoxServer 2X Administration Tool.
*/
static readonly MODERATOR_MESSAGE;
/**
* The objectMessage event type, dispatched when an object containing custom data is received by the current
* user.
*
* This event is caused by an ObjectMessageRequest request sent by any user in the target Room.
*/
static readonly OBJECT_MESSAGE;
/**
* The pingPong event type, dispatched when a new lag value measurement is available.
*
* This event is fired when the automatic lag monitoring is turned on by passing true to the enableLagMonitor()
* method.
*/
static readonly PING_PONG;
/**
* The playerToSpectator event type, dispatched when a player is turned to a spectator inside a Game Room.
*
* This event is fired in response to the PlayerToSpectatorRequest> request if the operation is executed
* successfully.
*/
static readonly PLAYER_TO_SPECTATOR;
/**
* The playerToSpectatorError event type, dispatched when an error occurs while the current user is being turned
* from player to spectator in a Game Room.
*
* This event is fired in response to the PlayerToSpectatorRequest request in case the operation failed.
*/
static readonly PLAYER_TO_SPECTATOR_ERROR;
/**
* The privateMessage event type, dispatched when a private message is received by the current user.
*
* This event is caused by a PrivateMessageRequest request sent by any user in the Zone.
*
* NOTE: the same event is fired by the sender's client too, so that the user is aware that the message was
* delivered successfully to the recipient, and it can be displayed in the private chat area keeping the correct
* message ordering. In this case there is no default way to know who the message was originally sent to. As
* this information can be useful in scenarios where the sender is chatting privately with more than one user at
* the same time in separate windows or tabs (and we need to write his own message in the proper one), the data
* parameter can be used to store, for example, the id of the recipient user.
*/
static readonly PRIVATE_MESSAGE;
/**
* The proximityListUpdate event type, dispatched when one more users or one or more MMOItem objects enter/leave
* the current user's Area of Interest in a MMORoom.
*
* This event is fired after an MMORoom is joined and the SetUserPositionRequest request is sent at least one
* time.
*
* NOTE: this event substitutes the default userEnterRoom and userExitRoom events available in regular Rooms.
*/
static readonly PROXIMITY_LIST_UPDATE;
/**
* The publicMessage event type, dispatched when a public message is received by the current user.
*
* This event is caused by a PublicMessageRequest request sent by any user in the target Room, including the
* current user himself.
*/
static readonly PUBLIC_MESSAGE;
/**
* The roomAdd event type, dispatched when a new Room is created inside the Zone under any of the Room Groups
* that the client subscribed.
*
* This event is fired in response to the CreateRoomRequest and CreateSFSGameRequest requests in case the
* operation is executed successfully.
*/
static readonly ROOM_ADD;
/**
* The roomCapacityChange event type, dispatched when the capacity of a Room is changed.
*
* This event is fired in response to the ChangeRoomCapacityRequest> request if the operation is executed
* successfully.
*/
static readonly ROOM_CAPACITY_CHANGE;
/**
* The roomCapacityChangeError event type, dispatched when an error occurs while attempting to change the
* capacity of a Room.
*
* This event is fired in response to the ChangeRoomCapacityRequest request in case the operation failed.
*/
static readonly ROOM_CAPACITY_CHANGE_ERROR;
/**
* The roomCreationError event type, dispatched if an error occurs while creating a new Room.
*
* This event is fired in response to the CreateRoomRequest and CreateSFSGameRequest requests in case the
* operation failed.
*/
static readonly ROOM_CREATION_ERROR;
/**
* The roomFindResult event type, dispatched when a Rooms search is completed.
*
* This event is fired in response to the FindRoomsRequest request to return the search result.
*/
static readonly ROOM_FIND_RESULT;
/**
* The roomGroupSubscribe event type, dispatched when a Group is subscribed by the current user.
*
* This event is fired in response to the SubscribeRoomGroupRequest> request if the operation is executed
* successfully.
*/
static readonly ROOM_GROUP_SUBSCRIBE;
/**
* The roomGroupSubscribeError event type, dispatched when an error occurs while a Room Group is being
* subscribed.
*
* This event is fired in response to the SubscribeRoomGroupRequest request in case the operation failed.
*/
static readonly ROOM_GROUP_SUBSCRIBE_ERROR;
/**
* The roomGroupUnsubscribe event type, dispatched when a Group is unsubscribed by the current user.
*
* This event is fired in response to the UnsubscribeRoomGroupRequest request if the operation is executed
* successfully.
*/
static readonly ROOM_GROUP_UNSUBSCRIBE;
/**
* The roomGroupUnsubscribeError event type, dispatched when an error occurs while a Room Group is being
* unsubscribed.
*
* This event is fired in response to the UnsubscribeRoomGroupRequest request in case the operation failed.
*/
static readonly ROOM_GROUP_UNSUBSCRIBE_ERROR;
/**
* The roomJoin event type, dispatched when a Room is joined by the current user.
*
* This event is fired in response to the JoinRoomRequest and QuickJoinGameRequest requests in case the
* operation is executed successfully.
*/
static readonly ROOM_JOIN;
/**
* The roomJoinError event type, dispatched when an error occurs while the current user is trying to join a
* Room.
*
* This event is fired in response to the JoinRoomRequest request in case the operation failed.
*/
static readonly ROOM_JOIN_ERROR;
/**
* The roomNameChange event type, dispatched when the name of a Room is changed.
*
* This event is fired in response to the ChangeRoomNameRequest request if the operation is executed
* successfully.
*/
static readonly ROOM_NAME_CHANGE;
/**
* The roomNameChangeError event type, dispatched when an error occurs while attempting to change the name of a
* Room.
*
* This event is fired in response to the ChangeRoomNameRequest request in case the operation failed.
*/
static readonly ROOM_NAME_CHANGE_ERROR;
/**
* The roomPasswordStateChange event type, dispatched when the password of a Room is set, changed or removed.
*
* This event is fired in response to the ChangeRoomPasswordStateRequest> request if the operation is executed
* successfully.
*/
static readonly ROOM_PASSWORD_STATE_CHANGE;
/**
* The roomPasswordStateChangeError event type, dispatched when an error occurs while attempting to set, change
* or remove the password of a Room.
*
* This event is fired in response to the ChangeRoomPasswordStateRequest request in case the operation failed.
*/
static readonly ROOM_PASSWORD_STATE_CHANGE_ERROR;
/**
* The roomRemove event type, dispatched when a Room belonging to one of the Groups subscribed by the client is
* removed from the Zone.
*/
static readonly ROOM_REMOVE;
/**
* The roomVariablesUpdate event type, dispatched when a Room Variable is updated.
*
* This event is caused by the SetRoomVariablesRequest request. The request could have been sent by a user in
* the same Room of the current user or, in case of a global Room Variable, by a user in a Room belonging to one
* of the Groups subscribed by the current client.
*/
static readonly ROOM_VARIABLES_UPDATE;
/**
* The socketError event type, dispatched when a low level socket error is detected, for example
* bad/inconsistent data.
*/
static readonly SOCKET_ERROR;
/**
* The spectatorToPlayer event type, dispatched when a spectator is turned to a player inside a Game Room.
*
* This event is fired in response to the SpectatorToPlayerRequest> request if the operation is executed
* successfully.
*/
static readonly SPECTATOR_TO_PLAYER;
/**
* The spectatorToPlayerError event type, dispatched when an error occurs while the current user is being turned
* from spectator to player in a Game Room.
*
* This event is fired in response to the SpectatorToPlayerRequest request in case the operation failed.
*/
static readonly SPECTATOR_TO_PLAYER_ERROR;
/**
* The userCountChange event type, dispatched when the number of users/players or spectators inside a Room
* changes.
*
* This event is caused by a JoinRoomRequest request or a LeaveRoomRequest 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 RoomSettings.events setting).
*/
static readonly USER_COUNT_CHANGE;
/**
* The userEnterRoom event type, dispatched when one of the Rooms joined by the current user is entered by
* another user.
*
* This event is caused by a JoinRoomRequest request; it might be fired or not depending on the Room
* configuration defined upon its creation (see the RoomSettings.events setting).
*
* NOTE: if the Room is of type MMORoom, this event is never fired and it is substituted by the
* proximityListUpdate event.
*/
static readonly USER_ENTER_ROOM;
/**
* The userExitRoom event type, dispatched when one of the Rooms joined by the current user is left by another
* user, or by the current user himself.
*
* This event is caused by a LeaveRoomRequest request; it might be fired or not depending on the Room
* configuration defined upon its creation (see the RoomSettings.events setting).
*
* NOTE: if the Room is of type MMORoom, this event is fired when the current user leaves the Room only. For the
* other users leaving the Room it is substituted by the proximityListUpdate event.
*/
static readonly USER_EXIT_ROOM;
/**
* The userFindResult event type, dispatched when a users search is completed.
*
* This event is fired in response to the FindUsersRequest request to return the search result.
*/
static readonly USER_FIND_RESULT;
/**
* The userVariablesUpdate event type, dispatched when a User Variable is updated.
*
* This event is caused by the SetUserVariablesRequest request sent by a user in one of the Rooms joined by the
* current user.
*/
static readonly USER_VARIABLES_UPDATE;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSDataType.html
*
* The costants defining the data types supported by SFSObject and SFSArray classes.
*/
enum SFSDataType {
/** A boolean value. */
BOOL,
/** An array of boolean values. */
BOOL_ARRAY,
/** A byte (8 bit) value. */
BYTE,
/** An array of byte values. */
BYTE_ARRAY,
/** A double precision number (64 bit) value. */
DOUBLE,
/** An array of double precision number values. */
DOUBLE_ARRAY,
/** A floating point number (32 bit) value. */
FLOAT,
/** An array of floating point number values. */
FLOAT_ARRAY,
/** An integer (32 bit) value. */
INT,
/** An array of integer values. */
INT_ARRAY,
/** A long integer value. */
LONG,
/** An array of long integer values. */
LONG_ARRAY,
/** A null value. */
NULL,
/** A nested SFSArray object. */
SFS_ARRAY,
/** A nested SFSObject object. */
SFS_OBJECT,
/** A short integer (16 bit) value. */
SHORT,
/** An array of short integer values. */
SHORT_ARRAY,
/** A UTF-8 encoded string value, with length up to 2 GBytes. */
TEXT,
/** A UTF-8 encoded string value, with length up to 32 KBytes. */
UTF_STRING,
/** An array of string values. */
UTF_STRING_ARRAY,
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSArray.html
*
* The SFSArray class is used by SmartFoxServer in client-server data transfer.
*/
class SFSArray {
/**
* Creates a new SFSArray instance.
*
* This is a sort of specialized list object that can contain any type of data. The advantage of using the
* SFSArray class (for example as a nested object inside a SFSObject object) is that you can fine tune the way
* your data is transmitted over the network. For instance, when transmitting a list of numbers between 0 and
* 100, those values can be treated as normal integers (which take 32 bits each), but also as shorts (16 bit) or
* even as bytes (8 bit).
*
* SFSArray supports many primitive data types and related arrays of primitives; see the SFSDataType class.
*/
constructor();
/**
* Appends a value of the passed type to the end of this array.
* @param value The value to be appended to this array.
* @param typeId The value's type identifier.
*/
add(value: any, typeId: SFSDataType): void;
/** Appends a boolean value to the end of this array. */
addBool(value: boolean): void;
/** Appends an array of booleans to the end of this array. */
addBoolArray(array: boolean[]): void;
/** Appends a number to the end of this array as a byte (8 bit). */
addByte(value: number): void;
/** Appends a byte array to the end of this array. */
addByteArray(array: Uint8Array): void;
/** Appends a number to the end of this array as a double precision value (64 bit). */
addDouble(value: number): void;
/** Appends an array of numbers to the end of this array as double precision values. */
addDoubleArray(array: number[]): void;
/** Appends a number to the end of this array as a floating point value (32 bit). */
addFloat(value: number): void;
/** Appends an array of numbers to the end of this array as floating point values. */
addFloatArray(array: number[]): void;
/** Appends a number to the end of this array as an integer (32 bit). */
addInt(value: number): void;
/** Appends an array of numbers to the end of this array as integers. */
addIntArray(array: number[]): void;
/** Appends a number to the end of this array as a long integer. */
addLong(value: number): void;
/** Appends an array of numbers to the end of this array as long integers. */
addLongArray(array: number[]): void;
/** Appends a null value to the end of this array. */
addNull(): void;
/** Appends a nested SFSArray to the end of this array. */
addSFSArray(value: SFSArray): void;
/** Appends a nested SFSObject to the end of this array. */
addSFSObject(value: SFSObject): void;
/** Appends a number to the end of this array as a short integer (16 bit). */
addShort(value: number): void;
/** Appends an array of numbers to the end of this array as short integers. */
addShortArray(value: number[]): void;
/** Appends a UTF-8 string to the end of this array (max length: 2 GBytes). */
addText(value: string): void;
/** Appends a UTF-8 string to the end of this array (max length: 32 KBytes). */
addUtfString(value: string): void;
/** Appends an array of UTF-8 strings to the end of this array. */
addUtfStringArray(array: string[]): void;
/**
* Indicates whether this SFSArray contains the specified object or not.
*
* NOTE: this method doesn't support checking the presence of a nested SFSObject or SFSArray.
*
* @param object The object whose presence in this array is to be tested.
* @returns true if the specified object is present in the SFSArray.
*/
contains(object: any): boolean;
/**
* Returns the element at the specified index.
*
* If the typeId parameter is passed, this method also executes a type check, to make sure the requested value
* has the expected type.
*
* @param index The position of the element to return.
* @param typeId The identifier of the expected value's type. If passed and the type is not corresponding, an
* error is thrown. If not passed, no type check is executed and the value is returned immediately.
* @returns The element of this array at the specified index.
*/
get(index: number, typeId: SFSDataType = null): any | null;
/** Returns the boolean value at the specified index. */
getBool(index: number): boolean | null;
/** Returns the array of boolean values at the specified index. */
getBoolArray(index: number): boolean[] | null;
/** Returns the byte value at the specified index. */
getByte(index: number): number | null;
/** Returns the byte array at the specified index. */
getByteArray(index: number): Uint8Array | null;
/** Returns the double precision number at the specified index. */
getDouble(index: number): number | null;
/** Returns the array of double precision numbers at the specified index. */
getDoubleArray(index: number): number[] | null;
/**
* Provides a formatted string representing this array.
*
* The returned string can be logged or traced in the console for debugging purposes.
*
* @param format If true, the output is formatted in human-readable way.
* @returns The string representation of this array.
*/
getDump(format: boolean = true): string;
/** Returns the floating point number at the specified index. */
getFloat(index: number): number | null;
/** Returns the array of floating point numbers at the specified index. */
getFloatArray(index: number): number[] | null;
/**
* Provides a detailed hexadecimal representation of this array.
*
* The returned string can be logged or traced in the console for debugging purposes.
*
* @returns The hexadecimal string representation of this array.
*/
getHexDump(): string;
/** Returns the integer at the specified index. */
getInt(index: number): number | null;
/** Returns the array of integers at the specified index. */
getIntArray(index: number): number[] | null;
/** Returns the long at the specified index. */
getLong(index: number): number | null;
/** Returns the array of long integers at the specified index. */
getLongArray(index: number): number[] | null;
/** Returns the SFSArray at the specified index. */
getSFSArray(index: number): SFSArray | null;
/** Returns the SFSObject at the specified index. */
getSFSObject(index: number): SFSObject | null;
/** Returns the short integer at the specified index. */
getShort(index: number): number | null;
/** Returns the array of short integers at the specified index. */
getShortArray(index: number): number[] | null;
/** Returns the UTF-8 string at the specified index. */
getText(index: number): string | null;
/** Returns the UTF-8 string at the specified index. */
getUtfString(index: number): string | null;
/** Returns the array of UTF-8 strings at the specified index. */
getUtfStringArray(index: number): string[] | null;
/** Indicates if the element at the specified index is of type SFSDataType.NULL. */
isNull(index: number): boolean;
/**
* Indicates the number of elements in this array.
* @returns The number of elements in this array.
*/
size(): number;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSObject.html
*
* The SFSObject class is used by SmartFoxServer in client-server data transfer.
*/
class SFSObject {
/**
* Creates a new SFSObject instance.
*
* This is a sort of specialized map object that can contain any type of data. The advantage of using the
* SFSObject class (for example when sending an ExtensionRequest request) is that you can fine tune the way your
* data is transmitted over the network. For instance, a number like 100 can be transmitted as a normal integer
* (which takes 32 bits), but also a short (16 bit) or even a byte (8 bit).
*
* SFSObject supports many primitive data types and related arrays of primitives; see the SFSDataType class.
*
* NOTE: UTF-8/multi-byte strings are not supported in key names. In other words you should restrict key names
* to standard ASCII characters. It is also recommended to keep key names very short to save bandwidth.
*/
constructor();
/**
* Indicates whether this object contains a mapping for the specified key.
* @param key The key whose presence in this object is to be checked.
* @returns true if this object contains a mapping for the passed key.
*/
containsKey(key: string): boolean;
/**
* Returns the value assigned to the specified key.
* @param key The key whose associated value is to be returned.
* @param typeId The identifier of the expected value's type.
* @returns The value assigned to the specified key. null is returned if no value is associated with the passed
* key.
*/
get(key: string, typeId: SFSDataType = null): any | null;
/** Returns the boolean value corresponding to the passed key. */
getBool(key: string): boolean | null;
/** Returns the array of boolean values corresponding to the passed key. */
getBoolArray(key: string): boolean[] | null;
/** Returns the byte value corresponding to the passed key. */
getByte(key: string): number | null;
/** Returns the byte array corresponding to the passed key. */
getByteArray(key: string): Uint8Array | null;
/** Returns the double precision number corresponding to the passed key. */
getDouble(key: string): number | null;
/** Returns the array of double precision numbers corresponding to the passed key. */
getDoubleArray(key: string): number[] | null;
/**
* Provides a formatted string representing this object.
*
* The returned string can be logged or traced in the console for debugging purposes.
*
* @param format If true, the output is formatted in a human-readable way.
*/
getDump(format: boolean = true): string;
/** Returns the floating point number corresponding to the passed key. */
getFloat(key: string): number | null;
/** Returns the array of floating point numbers corresponding to the passed key. */
getFloatArray(key: string): number[] | null;
/**
* Provides a detailed hexadecimal representation of this object.
*
* The returned string can be logged or traced in the console for debugging purposes.
*
* @returns The hexadecimal string representation of this object.
*/
getHexDump(): string;
/** Returns the integer corresponding to the passed key. */
getInt(key: string): number | null;
/** Returns the array of integers corresponding to the passed key. */
getIntArray(key: string): number[] | null;
/** Retrieves a list of all the keys contained in this object. */
getKeysArray(): string[];
/** Returns the long integer corresponding to the passed key. */
getLong(key: string): number | null;
/** Returns the array of long integers corresponding to the passed key. */
getLongArray(key: string): number[] | null;
/** Returns the SFSArray corresponding to the passed key. */
getSFSArray(key: string): SFSArray | null;
/** Returns the SFSObject corresponding to the passed key. */
getSFSObject(key: string): SFSObject | null;
/** Returns the short integer corresponding to the passed key. */
getShort(key: string): number | null;
/** Returns the array of short integers corresponding to the passed key. */
getShortArray(key: string): number[] | null;
/** Returns the UTF-8 string corresponding to the passed key. */
getText(key: string): string | null;
/** Returns the UTF-8 string corresponding to the passed key. */
getUtfString(key: string): string | null;
/** Returns the array of UTF-8 strings corresponding to the passed key. */
getUtfStringArray(key: string): string[] | null;
/** Indicates if the value mapped by the passed key is of type SFSDataType.NULL. */
isNull(key: string): boolean | null;
/**
* Assigns a value of the passed type to the passed key.
* @param key The key to which the specified value has to be assigned.
* @param value The value to be assigned to the passed key.
* @param typeId The value's type identifier.
*/
put(key: string, value: any, typeId: SFSDataType): void;
/** Assigns a boolean value to the passed key. */
putBool(key: string, value: boolean): void;
/** Assigns an array of booleans to the passed key. */
putBoolArray(key: string, array: boolean[]): void;
/** Assigns a number to the passed key as a byte (8 bit). */
putByte(key: string, value: number): void;
/** Assigns a byte array to the passed key. */
putByteArray(key: string, array: Uint8Array): void;
/** Assigns a number to the passed key as a double precision value (64 bit). */
putDouble(key: string, value: number): void;
/** Assigns an array of numbers to the passed key as double precision values. */
putDoubleArray(key: string, array: number[]): void;
/** Assigns a number to the passed key as a floating point value (32 bit). */
putFloat(key: string, value: number): void;
/** Assigns an array of numbers to the passed key as floating point values. */
putFloatArray(key: string, array: number[]): void;
/** Assigns a number to the passed key as an integer (32 bit). */
putInt(key: string, value: number): void;
/** Assigns an array of numbers to the passed key as integers. */
putIntArray(key: string, array: number[]): void;
/** Assigns a number to the passed key as a long integer. */
putLong(key: string, value: number): void;
/** Assigns an array of numbers to the passed key as long integers. */
putLongArray(key: string, value: number[]): void;
/** Assigns a null value to the passed key. */
putNull(key: string): void;
/** Assigns a nested SFSArray to the passed key. */
putSFSArray(key: string, value: SFSArray): void;
/** Assigns a nested SFSObject to the passed key. */
putSFSObject(key: string, value: SFSObject): void;
/** Assigns a number to the passed key as a short integer (16 bit). */
putShort(key: string, value: number): void;
/** Assigns an array of numbers to the passed key as short integers. */
putShortArray(key: string, value: number[]): void;
/** Assigns a UTF-8 text to the passed key (max length: 2 GBytes). */
putText(key: string, value: string): void;
/** Assigns a UTF-8 string to the passed key (max length: 32 KBytes). */
putUtfString(key: string, value: string): void;
/** Assigns an array of UTF-8 strings to the passed key. */
putUtfStringArray(key: string, value: string[]): void;
/** Returns the number of elements in this object. */
size(): number;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/VariableType.html
*
* The valid types for User, Room, Buddy and MMOItem Variables to be passed to the respective constructors.
*/
enum VariableType {
/** The type of the Variable is boolean. */
BOOLEAN,
/** The type of the Variable is number (specifically a double). */
DOUBLE,
/** The type of the Variable is number (specifically an integer). */
INT,
/** The Variable is null. */
NULL,
/** The type of the Variable is SFSArray. */
SFSARRAY,
/** The type of the Variable is SFSObject. */
SFSOBJECT,
/** The type of the Variable is string. */
STRING,
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/BaseVariable.html
*
* Base class for all SmartFoxServer Variable entities on the client.
*/
class BaseVariable {
/** Indicates if the Variable is null. */
readonly isNull: boolean;
/** Indicates the name of this variable. */
readonly name: string;
/**
* Indicates the type of this Variable. Possibly returned strings are: null, boolean, int, double, string,
* SFSObject, SFSArray.
*/
readonly type: string;
/** Returns the value of this variable. */
readonly value: boolean | number | string | SFSObject | SFSArray | null;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSBuddyVariable.html
*
* The Buddy Variable entity representation on the client.
*/
class SFSBuddyVariable extends BaseVariable {
/**
* The prefix to be added to a Buddy Variable name to make it persistent. A persistent Buddy Variable is made
* available to all users who have the owner in their Buddy List, whether that Buddy is online or not.
*/
static readonly OFFLINE_PREFIX: string;
/**
* Indicates whether the Buddy Variable is persistent or not.
*
* By convention any Buddy Variable whose name starts with the dollar sign ($) will be regarded as persistent
* and stored locally by the server. Persistent Buddy Variables are also referred to as "offline variables"
* because they are available to all users who have the owner in their Buddy List, whether that Buddy is online
* or not.
*/
readonly isOffline: boolean;
/**
* Creates a new SFSBuddyVariable instance.
*
* A SFSBuddyVariable is a custom value attached to a SFSBuddy object in a Buddy List that gets automatically
* synchronized between client and server on every change.
*
* Buddy Variables work with the same principle of the User and Room Variables. The only difference is the logic
* by which they get propagated to other users. While Room and User Variables are usually broadcast to all
* clients in the same Room, Buddy Variables updates are sent to all users who have the owner of the Buddy
* Variable in their Buddy Lists.
*
* Buddy Variables are particularly useful to store custom user data that must be "visible" to the buddies only,
* such as a profile, a ranking, a status message, etc. Buddy Variables can be set by means of the
* SetBuddyVariablesRequest request; they support the following data types (also nested): boolean, number,
* string, SFSObject, SFSArray. A Buddy Variable can also be null.
*
* There is also a special convention that allows Buddy Variables to be set as "offline". Offline Buddy
* Variables are persistent values which are made available to all users who have the owner in their Buddy List,
* whether that buddy is online or not. In order to make a Buddy Variable persistent, its name should start with
* a dollar sign ($). This conventional character is contained in the OFFLINE_PREFIX constant.
*
* @param name The name of the Buddy Variable.
* @param value The value of the Buddy Variable; it can also be null.
* @param type The type id of the Buddy Variable among those available in the VariableType class. Usually it is
* not necessary to pass this parameter, as the type is auto-detected from the value.
*/
constructor(
name: string,
value: boolean | number | string | SFSObject | SFSArray | null,
type: VariableType = -1);
/**
* Returns a string that contains the Buddy Variable name, type and value.
* @returns The string representation of the SFSBuddyVariable object.
*/
toString(): string;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSRoomVariable.html
*
* The Room Variable entity representation on the client.
*/
class SFSRoomVariable extends BaseVariable {
/**
* Indicates whether this Room Variable is persistent or not. A persistent Room Variable continues to exist in
* the Room after the user who created it has left it and until he disconnects.
*
* NOTE: setting the isPersistent property manually on an existing Room Variable returned by the API has no
* effect on the server and can disrupt the API functioning. This flag can be set after the Room Variable object
* is created using the constructor only.
*/
isPersistent: boolean;
/**
* Indicates whether this Room Variable is private or not. A private Room Variable is visible to all users in
* the same Room, but it can be modified only by its owner (the user that created it).
*
* NOTE: setting the isPrivate property manually on an existing Room Variable returned by the API has no effect
* on the server and can disrupt the API functioning. This flag can be set after the Room Variable object is
* created using the constructor only.
*/
isPrivate: boolean;
/**
* Creates a new SFSRoomVariable instance.
*
* A SFSRoomVariable is a custom value attached to a SFSRoom object that gets automatically synchronized between
* client and server on every change.
*
* Room Variables are particularly useful to store custom Room data such as a game status and other Room-level
* informations. They can be set by means of the SetRoomVariablesRequest request; they support the following
* data types (also nested): boolean, number, string, SFSObject, SFSArray. A Room Variable can also be null.
*
* @param name The name of the Room Variable.
* @param value The value of the Room Variable; it can also be null.
* @param type The type id of the Room Variable among those available in the VariableType class. Usually it is
* not necessary to pass this parameter, as the type is auto-detected from the value.
*/
constructor(
name: string,
value: boolean | number | string | SFSObject | SFSArray | null,
type: VariableType = -1);
/**
* Returns a string that contains the Room Variable name, type, value and isPrivate flag.
* @returns The string representation of the SFSRoomVariable object.
*/
toString(): string;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSUserVariable.html
*
* The User Variable entity representation on the client.
*/
class SFSUserVariable extends BaseVariable {
/**
* Indicates whether this User Variable is private or not. A private User Variable is visible only to its owner;
* any changes made to the variable will be transmitted to the owner only.
*
* NOTE: setting the isPrivate property manually on an existing User Variable returned by the API has no effect
* on the server and can disrupt the API functioning. This flag can be set after the User Variable object is
* created using the constructor only.
*/
isPrivate: boolean;
/**
* Creates a new SFSUserVariable instance.
*
* A SFSUserVariable is a custom value attached to a SFSUser object that gets automatically synchronized between
* client and server on every change.
*
* User Variables are particularly useful to store custom user data that must be "visible" to the other users,
* such as a profile, a score, a status message, etc. User Variables can be set by means of the
* SetUserVariablesRequest request; they support the following data types (also nested): boolean, number,
* string, SFSObject, SFSArray. A User Variable can also be null.
*
* @param name The name of the User Variable.
* @param value The value of the User Variable; it can also be null,
* @param type The type id of the User Variable among those available in the VariableType class. Usually it is
* not necessary to pass this parameter, as the type is auto-detected from the value.
*/
constructor(
name: string,
value: boolean | number | string | SFSObject | SFSArray | null,
type: VariableType = -1);
/**
* Returns a string that contains the User Variable name, type, value and isPrivate flag.
* @returns The string representation of the SFSUserVariable object.
*/
toString(): string;
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/ReservedBuddyVariables.html
*
* The reserved Buddy Variable names used by the Buddy List API.
*/
enum ReservedBuddyVariables {
/**
* The Buddy Variable with this name stores the optional nickname of the user in a buddy list.
*
* This variable is persistent, which means that the nickname is preserved upon disconnection.
*/
BV_NICKNAME,
/**
* The Buddy Variable with this name keeps track of the online/offline state of the user in a buddy list.
*
* This variable is persistent, which means that the online/offline state is preserved upon disconnection.
*/
BV_ONLINE,
/**
* The Buddy Variable with this name stores the custom state of the user in a buddy list.
*
* This variable is persistent, which means that the custom state is preserved upon disconnection.
*/
BV_STATE,
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/ReservedRoomVariables.html
*
* The reserved Room Variable names used by the Game API.
*/
enum ReservedRoomVariables {
/**
* The Room Variable with this name keeps track of the state (started or stopped) of a game created with the
* CreateSFSGameRequest request.
*/
RV_GAME_STARTED,
}
/**
* http://docs2x.smartfoxserver.com/api-docs/jsdoc/client/SFSBuddy.html
*
* The representation of a buddy in the current user's buddy list.
*/
class SFSBuddy {
/**
* Indicates the id of this buddy. This is equal to the id assigned by SmartFoxServer to the corresponding user.
*/
readonly id: number;
/**
* Indicates whether this buddy is blocked in the current user's buddy list or not. A buddy can be blocked by
* means of a BlockBuddyRequest request.
*/
readonly isBlocked: number;
/** Indicates whether this buddy is online in the Buddy List system or not. */
readonly isOnline: boolean;
/** Indicates whether this buddy is temporary (non-persistent) in the current user's buddy list or not. */
readonly isTemp: boolean;
/** Indicates the name of this buddy. This is equal to the name of the corresponding user. */
readonly name: string;
/** Returns the nickname of this buddy. If the nickname is not set, null is returned. */
readonly nickName: string | null;
/**
* Returns the custom state of this buddy. Examples of custom states are "Available", "Busy", "Be right back",
* etc. If the custom state is not set, null is returned.
*
* The list of available custom states is returned by the SFSBuddyManager.getBuddyStates() method.
*/
readonly state: string;
/**
* Indicates whether this user has the specified Buddy Variable set or not.
* @param varName The name of the Buddy Variable whose existance must be checked.
* @returns true if a Buddy Variable with the passed name is set for this buddy.
*/
containsVariable(varN