Would you like to contribute to the Titanium docs? To get started, sign up for an account on the Appcelerator Wiki and sign our CLA.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Made a minor grammar change

...

  1. In the package.json file, add socket.io as a dependency.
  2. In the app.js, in the started event listener, load the socket.io module and pass it the server instance ( API Builder instance's server property), then make API calls to the socket.io instance.  If you assign the socket.io instance to a property of the  API Builder instance, you can access the socket.io instance with that property wherever an  API Builder instance is passed to a method.
  3. Any client-side code, such as the view templates, will need to include the socket.io.js client script.  Note that when the client connects to the socket.io server ( API Builder application), you will need to update the URL when switching between testing the project locally or when its it's published to API Runtime Services.

...

For all websockets declared in the config.json file of your API Runtime Services application, you will need to add an event listener to the socket once a connection is established, which requires socket.io to be added to the project. For details, see the socket.io instance section above.

Example:

The config.json file defines a websocket that whenever a newChatMsg is received, the API Runtime Services application executes the receiveMessage() method in the websockets/chatroom.js file.

...

To use the same websocket in API Builder, first add socket.io as described in the socket.io instance section, then add a newChatMsg event listener for the socket in the connection event listener.

...

All logic declared in the API Runtime Services controllers should be moved to the API Builder Route module in the web/routes folder of the API Builder project or API Builder API module. For details, see the config.json section above.

Filters directory

...

All logic declared in API Runtime Services websockets will need to be declared with the socket event listener, which requires socket.io to be added to the project. For details, see the config.json section above.

Public directory

...