Implementing the Pusher Realtime API for Android and iOS.
yarn add react-native-realtime-pusher
include ':Pusher'
project(':Pusher').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-realtime-pusher/android')
compile project(':Pusher')
import com.gijoehosaphat.pusher.PusherPackage;
new PusherPackage()
import Pusher from 'react-native-realtime-pusher'
...
// These values determined by *your* setup on *your* backend.
// hostname ~= http://myserver.com
// authPath ~= /auth
// channelPath ~= /channel
Pusher.initialize(hostname, authPath, channelPath, appKey, cluster, token) //This is a Promise
...
//Connect (There is also disconnect)
Pusher.connect() //This is a Promise
...
//Subscribe to a channel (There is also channelUnsubscribe)
Pusher.channelSubscribe(channel, channelEventName) //This is a Promise
...
//Send a message
Pusher.messagePost(messageObject, channelName, channelEvent) //This is a promise
...
//You will want to listen for events:
componentDidMount() {
DeviceEventEmitter.addListener('pusher-event', this.yourEventHandler)
}
componentWillUnmount() {
DeviceEventEmitter.removeAllListeners('pusher-event')
}