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.

JavaScript

1

const push = rest.push;

Properties

The Push interface has the following properties:

A PushAdmin object for managing push notifications administratively (requires the push-admin capability).

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.

JavaScript

1

await rest.push.activate();

Parameters

The activate() method takes the following parameters:

registerCallbackoptionalFunction
A function passed to override the default implementation to register the local device for push activation. Called with the local device's DeviceDetails and a callback of the form callback(err, deviceDetails), where err is an ErrorInfo or null and deviceDetails is the registered DeviceDetails.
updateFailedCallbackoptionalFunction
A callback to be invoked when the device registration fails to update. Called with an ErrorInfo 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.

JavaScript

1

await rest.push.deactivate();

Parameters

The deactivate() method takes the following parameters:

deregisterCallbackoptionalFunction
A function passed to override the default implementation to deregister the local device for push activation. Called with the local device's DeviceDetails 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

idString
A unique ID generated by the device.
deviceSecretString
A unique device secret generated by the Ably SDK.
deviceIdentityTokenString or Undefined
A unique identity token the device uses to authenticate itself with Ably. Not present until device activation has completed.

List subscriptions for the local device

localDevice.listSubscriptions(): Promise<PaginatedResult<PushChannelSubscription>>

Retrieves push subscriptions active for the local device.

JavaScript

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.

channelString
The channel that this push notification subscription is associated with.
deviceIdString or Undefined
The device with this identifier is linked to this channel subscription. When present, clientId is never present.
clientIdString or Undefined
Devices with this client identifier are included in this channel subscription. When present, deviceId is never present.