Push
The Push object provides device-level push notification management, such as activating and deactivating the local device. Access it via the push property of a Rest client instance (rest.push).
Device activation operates on the local device's push registration, so it is only meaningful in environments that have a push-capable device, such as a browser or a mobile app. For server-side push administration, use the PushAdmin object instead.
1
const push = rest.push;Properties
The Push interface has the following properties:
Activate the device
push.activate(registerCallback?: Function, updateFailedCallback?: Function): Promise<void>Activates the device for push notifications. Subsequently registers the device with Ably and stores the deviceIdentityToken in local storage.
1
await rest.push.activate();Parameters
The activate() method takes the following parameters:
registerCallbackoptionalFunctionDeviceDetails and a callback of the form callback(err, deviceDetails), where err is an ErrorInfo or null and deviceDetails is the registered DeviceDetails.updateFailedCallbackoptionalFunctionErrorInfo or null as updateFailedCallback(err).Returns
Promise<void>
Returns a promise. The promise is fulfilled when the device has been activated, or rejected with an ErrorInfo object.
Deactivate the device
push.deactivate(deregisterCallback?: Function): Promise<void>Deactivates the device from receiving push notifications.
1
await rest.push.deactivate();Parameters
The deactivate() method takes the following parameters:
deregisterCallbackoptionalFunctionDeviceDetails and a callback of the form callback(err, deviceId), where err is an ErrorInfo or null and deviceId is the deregistered device's ID string.Returns
Promise<void>
Returns a promise. The promise is fulfilled when the device has been deactivated, or rejected with an ErrorInfo object.
LocalDevice
A LocalDevice represents the current device as registered for push notifications, exposing the identity token and secret it uses to authenticate itself with Ably. Access it by calling await rest.getDevice().
Properties
idStringdeviceSecretStringdeviceIdentityTokenString or UndefinedList subscriptions for the local device
localDevice.listSubscriptions(): Promise<PaginatedResult<PushChannelSubscription>>Retrieves push subscriptions active for the local device.
1
2
const device = await rest.getDevice();
const subs = await device.listSubscriptions();Returns
Promise<PaginatedResult<PushChannelSubscription>>
Returns a promise. The promise is fulfilled with a PaginatedResult containing an array of PushChannelSubscription objects for each push channel subscription active for the local device, or rejected with an ErrorInfo object.
channelStringdeviceIdString or UndefinedclientId is never present.clientIdString or UndefineddeviceId is never present.