SmartFoxServer 2X JavaScript client API (binary)

Welcome to the SmartFoxServer 2X JavaScript client API documentation.

You can start exploring the API from the SmartFox class. The other relevant classes you will often use are those with names ending with Request, for example the LoginRequest class.

Some of the classes listed here are never instantiated by developers directly; instances are returned by methods or as event parameters (for example instances of SFSUser or SFSRoom). You can use this API reference to learn what properties and methods are available on those instances.

Getting started

IMPORTANT: make sure that WebSocket protocol is active and set to 'binary' mode in the SmartFoxServer 2X configuration. If not, enable it using the AdminTool's Server Configurator module (Web server tab) and restart the SmartFoxServer.

In order to get started with the development, you can import the API's JavaScript file on an HTML page by means of the <script> tag (the version number in the file name may vary):

<script type="text/javascript" src="sfs2x-api-1.7.0.js"></script>;

In your JavaScript code, you can access all instantiable classes by means of the SFS2X namespace. The following example shows how to create an instance of the main SmartFox class, add a few listeners and establish a connection with SmartFoxServer.

var 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("Connected to SmartFoxServer 2X!");
     else
         console.log("Connection failed. Is the server running at all?");
}

AddBuddyRequest

ChangeRoomNameRequest

ChangeRoomPasswordStateRequest

CreateSFSGameRequest

GoOnlineRequest

InitBuddyListRequest

LeaveRoomRequest

LogoutRequest

PlayerToSpectatorRequest

RemoveBuddyRequest

SFSValidationError

SetBuddyVariablesRequest

SetUserVariablesRequest

SpectatorToPlayerRequest

SubscribeRoomGroupRequest

UnsubscribeRoomGroupRequest