undefined

Push Notifications

Push Notifications provide a way to deliver some information to users while they are not using your app actively. The following use cases can be covered additionally with push notifications:

  • send a chat message when a recipient is offline (a push notification will be initiated automatically in this case)
  • make a video call with offline opponents (need to send a push notification manually)

Configuration

In order to start work with push notifications you need to configure it.

For iOS application that uses Apple Push Notifications you must have APNS certificate uploaded via the ConnectyCube Dashboard Console panel.

For Android application that uses Firebase Cloud Messaging (FCM) you need to obtain API Key and set it on ConnectyCube Dashboard Console panel.

Subscribe

In order to start receiving push notifications you need to subscribe your current device as follows:

const params = {
  notification_channels: "apns", // or 'gcm' for Android
  device: {
    platform: "ios",
    udid: "2b6f0cc904d137be2e1730235f5664094b831186"
  },
  push_token: {
    environment: "development",
    client_identification_sequence: "2b6f0cc9...4b831186"
  }
};

// JS SDK v1
ConnectyCube.pushnotifications.subscriptions.create(
  params,
  (error, result) => {}
);

// JS SDK v2
ConnectyCube.pushnotifications.subscriptions
  .create(params)
  .then(result => {})
  .catch(error => {});

Send push notifications

You can manually initiate a push notification to user/users on any event in your application. To do so you need to form a push notification parameters (payload) and set the push recipients:

const payload = JSON.stringify({
  message: "Alice is calling you",
  ios_badge: 1
});

const pushParameters = {
  notification_type: "push",
  user: { ids: [21, 12] }, // recipients.
  environment: "development", // environment, can be 'production'.
  message: ConnectyCube.pushnotifications.base64Encode(payload)
};

// JS SDK v1
ConnectyCube.pushnotifications.events.create(
  pushParameters,
  (error, result) => {}
);

// JS SDK v2
ConnectyCube.pushnotifications.events
  .create(pushParameters)
  .then(result => {})
  .catch(error => {});

Receive push notifications

The flow how you receive push notifications depends on what platform you use: NativeScript, React Native or something else. Please refer to the push notifications documentation of these platforms.

Unsubscribe

In order to unsubscribe and stop receiving push notifications you need to list your current subscriptions and then choose those to be deleted:

const deleteSubscription = subscriptions => {
  const subscriptionId = subscriptions[0].subscription.id;
  // JS SDK v1
  ConnectyCube.pushnotifications.subscriptions.delete(
    subscriptionId,
    error => {}
  );
  // JS SDK v2
  ConnectyCube.pushnotifications.subscriptions.delete(subscriptionId);
};

// JS SDK v1
ConnectyCube.pushnotifications.subscriptions.list((error, subscriptions) => {
  if (!error) {
    deleteSubscription();
  }
});

// JS SDK v2
ConnectyCube.pushnotifications.subscriptions
  .list()
  .then(deleteSubscription)
  .catch(error => {});