Using Socket.IO in a Cordova app is exactly the same as using it on a website. We emit events and listen for events. In the mobile device context, one interesting application is using Socket.IO as an interface over a third-party API. When the mobile device uses Socket.IO to kick off requests to the API, it doesn't have to wait for the request to complete. It will simply get a message when this occurs.
In this recipe, we will use Socket.IO as an interface to make a request to the openweathermap.org
API.
To make request to a third-party API, we will use the request library. It can be installed by running npm install request
in your command line.
To create a weather app that interfaces with a third-party API, follow these steps:
First, we need to create a new Cordova application. This can be done by running
cordova create app com.push.dataPushData
in your command line.Next, add the iOS platform by running
cordova platform add ios
, and build...