- In the
socket.ioas a dependency.
- In the
app.js, in the
startedevent listener, load the socket.io module and pass it the server instance ( API Builder instance's
serverproperty), 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.
- Any client-side code, such as the view templates, will need to include the
socket.io.jsclient 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.
config.json file defines a websocket that whenever a
newChatMsg is received, the API Runtime Services application executes the
receiveMessage() method in the
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 above.
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 above.