• Examples (iOS)
• Examples (Java/Android)
• Examples (C++)
Server API Documentation

 

» Client API setup | HTML5 — JavaScript

The JavaScript API is used to build application and games for all modern browsers supporting HTML5. For more informations please visit this page.

You can setup the API manually or using the npm package manager.

» Manual setup

The API is distributed for manual installation as a zip file containing a library JavaScript file and a source map file; the latter can be helpful to locate and debug issues in case of errors originating in the API.

After downloading and unzipping the package in the project's folder (usually in a libs subfolder), import the JavaScript file in your project's main HTML page by means of the <script> tag, just like in the following code snippet. Please note that the version number in the file name may be different: make sure your code matches the actual one.

<script type="text/javascript" src="libs/sfs2x-api-1.7.11.js"></script>

Most examples in the HTML5 tutorials section of this documentation are based on this approach.

» NPM package

If your project makes use of the npm package manager, switch to your project's main folder in a terminal/console window and execute this command:

> npm install sfs2x-api --save

This automatically adds the sfs2x-api entry in the dependancies section of your project's package.json file. You can then use a module bundler and the ES2015 module loading syntax to access the API, like this:

import * as SFS2X from "sfs2x-api";

We recommend using the webpack module bundler. You can check a complete, yet simple example showing how to setup your npm project and build it using webpack here.

NOTE
If you are using npm and a module bundler, but you still want to manage the API library manually (no automatic installation through npm), download the API package from the SmartFoxServer website and unzip it in the project's folder (for example in a libs subfolder). Then change the from clause in the import statement above to "../libs/sfs2x-api-1.7.11" (version number in the name may be different).

» API usage

All import methods outlined above will expose the API library as a variable called SFS2X, which represents the namespace containing all SmartFox-related classes.

Check the JavaScript client API documentation's introduction to learn how to get started with the development.

If you are interested in developing Node.js applications using the SmartFoxServer API, please also check this blog post.

 

« back to client API list