Constructor
new SmartFox()
Members
(readonly) buddyManager :SFSBuddyManager
The Buddy Manager is used internally by the SmartFoxServer Client API; the reference returned by this property gives access to the Buddy List, allowing interaction with SFSBuddy and SFSBuddyVariable objects and access to User properties in the Buddy List System.
(readonly) config :ConfigData
The object properties are set to their default values when the SmartFox class is instantiated.
(readonly) httpUploadURI :string
Uploads must be enabled on the server side for the specific Zone. The value of this property is null if the client is not yet logged in.
- string
(readonly) isConnected :boolean
The value is false until a successful connection is established, or a disconnection occurred.
- boolean
(readonly) lastJoinedRoom :SFSRoom
This property is null if no Room was joined yet, or all joined Rooms have been left.
(readonly) logger :Logger
(readonly) mySelf :SFSUser
This object is generated upon successful login only, so it is null if login was not performed yet or client logged out.
(readonly) roomManager :SFSRoomManager
The Room Manager is used internally by the SmartFoxServer Client API; the reference returned by this property gives access to the Room List and Groups, allowing interaction with SFSRoom objects.
(readonly) sessionToken :string
The session token is a string sent by the server to the client after the initial handshake, so it is null until handshake is complete. It is required as a mean of identification when uploading files to the server.
- string
(readonly) userManager :SFSUserManager
The User Manager is used internally by the SmartFoxServer Client API; the reference returned by this property gives access to the User List, allowing interaction with SFSUser objects.
(readonly) version :string
- string
Methods
addEventListener(evtType, callback, scope)
| Name | Type | Description |
|---|---|---|
evtType | string | The type (name) of event to listen to. |
callback | function | The listener function that processes the event. This function should accept an object as its only parameter, which in turn contains the event parameters. |
scope | object | 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. |
This example shows how to add a number of common event listeners to the SmartFox instance, usually during initialization:
function init()
{
sfs = new SmartFox();
// Add SFSEvent listeners
sfs.addEventListener(SFSEvent.CONNECTION, onConnection, this);
sfs.addEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost, this);
sfs.addEventListener(SFSEvent.LOGIN_ERROR, onLoginError, this);
sfs.addEventListener(SFSEvent.LOGIN, onLogin, this);
sfs.addEventListener(SFSEvent.LOGOUT, onLogout, this);
sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
sfs.addEventListener(SFSEvent.ROOM_JOIN, onRoomJoin, this);
}connect(cfgopt)
The client communicates with the SmartFoxServer instance through a WebSocket connection.
It is possible to configure che connection without passing the cfg parameter: just set the properties on the default configuration object throught the SmartFox#config getter.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
cfg | ConfigData | <optional> | null | The client configuration object. |
- See
disconnect()
- See
enableLagMonitor(enabled, intervalopt, queueSizeopt)
When the lag monitor is activated, the SFSEvent.PING_PONG event type is then dispatched continuously. The event provides the average value of the last ten measured lag values, and the minimum and maximum lag avalues for the current lag monitoring session. The lag monitoring can be enabled after a successful login only and it is automatically halted when the client logs out of a Zone or gets disconnected.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
enabled | boolean | The lag monitoring status: true to start the monitoring, false to stop it. | ||
interval | number | <optional> | 4 | An optional amount of seconds to wait between each query (recommended 3-4s). |
queueSize | number | <optional> | 10 | The amount of values stored temporarily and used to calculate the average lag. |
getJoinedRooms() → {Array.<SFSRoom>}
The same list is returned by the SFSRoomManager#getJoinedRooms method, accessible through the SmartFox#roomManager getter; this is replicated on this class for handy access due to its usually frequent usage.
- Type:
- Array.<SFSRoom>
killConnection()
This method should be used for testing and simulations only, otherwise use the SmartFox#disconnect method.
- See
removeAllEventListeners()
removeEventListener(evtType, callback)
| Name | Type | Description |
|---|---|---|
evtType | string | The type (name) of event to remove. |
callback | function | The listener function to be removed. |
send(request)
| Name | Type | Description |
|---|---|---|
request | BaseRequest | A request object. |
This example shows how to send a login request:
sfs.send(new LoginRequest("KermitTheFrog", "kermitPwd", "TheMuppetZone"));This example sends a request to join a Room:
sfs.send(new JoinRoomRequest("Lobby"));This example creates an object containing some parameters and sends it to the server-side Extension:
const params = new SFSObject();
params.putInt("x", 10);
params.putInt("y", 37);
sfs.send(new ExtensionRequest("setPosition", params));setClientDetails(platformId, version)
This method must be called before the connection is started. The length of the two strings combined must be less than 512 characters.
If not set, the default value of the underlying property is the generic JavaScript. Version is not specified in this case.
| Name | Type | Description |
|---|---|---|
platformId | string | An identifier of the runtime platform. |
version | string | An optional version number of the runtime platform. |