- Version: 1.0.0
- GitHub: https://github.com/slidebean/pusher-nativescript
- NPM: https://www.npmjs.com/package/pusher-nativescript
- Downloads:
- Last Day: 0
- Last Week: 0
- Last Month: 0
Pusher Nativescript
Pusher NativeScript adds Pusher support to {N} applications.
There is not official support for NativeScript in pusher-js sdk, but the Pusher team made a great work designing the JS library to target multiple platforms (react-native, node, browser, etc), while reusing a lot of code in the process. Taking advantage of that architecture, we were able to create a version of the pusher-js sdk that maintains the original API and provides support for NativeScript.
Usage
You can install the library using any npm compatible package manager, like npm or yarn:
$ npm install --save pusher-nativescript
Or use NativeScript CLI:
$ tns plugin add pusher-nativescript
Once the package has been installed, you can import it
As a CommonJS module:
const Pusher = require('pusher-nativescript');
Or ES6 module:
import Pusher from 'pusher-nativescript';
If you are using Typescript you might have to import it like this:
import * as Pusher from 'pusher-nativescript';
This build of pusher-js
uses NativeScript's Connectivity API to detect changes on connectivity state. It will use this to automatically reconnect.
On Android, to access any connection related information we will need explicit permission from the user. To enable the permission request add the follwing in app/App_Resources/Android/AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
NativeScript do not have official support for WebSockets. We are relying on nativescript-websockets plugin to add that support. That is why the plugin is a peer dependency.
As it was mentioned above, pusher-nativescript
shares the same API as the official pusher-js
library. To see how the library is used and configured checkout pusher-js repository.
Credits
- pusher-js team, for their great work designing the pusher-js sdk.
- NathanaelA, for his nativescript-websockets plugin.