QuickBlox / quickblox-react-native-sdk

quickblox-react-native-sdk
Other
4 stars 1 forks source link

[Question] Does VoIP subscription handles normal notification? #79

Open maharjanaman opened 3 months ago

maharjanaman commented 3 months ago

Does VoIP subscription in iOS also handle other chat notifications? If not, whats the process of managing both VoIP and normal notification?

VladimirNybozhinsky commented 3 months ago

Hi @maharjanaman! This is Vladimir from QuickBlox.

VoIP (Voice over Internet Protocol) is used in iOS for voice calls over the Internet, providing cost-effective and flexible communication options (video + audio calls). APNS (Apple Push Notification Service) is used to send notifications to iOS devices, providing real-time updates and app interaction (sending push notifications to an offline user to notify the user that a chat message has been sent to the user and with the ability to open the application by clicking on the Push widget). You can learn more about setting up and using this functionality in our documentation: iOS SDK Push Notifications

React Native SDK Push Notifications

and also in this article

Best regards, Vladimir

maharjanaman commented 3 months ago

Thanks @VladimirNybozhinsky for the response. I get the gist. So does this mean I have to create a subscription for VoIP and again for normal notification?

VladimirNybozhinsky commented 3 months ago

Hi @maharjanaman !

In order to use our server to send VoIP and APNS notifications, two different subscriptions are required. You can see this in your Admin Panel in the “Users” section. To do this, go to a specific user and at the bottom of the page you will see his subscriptions - this user has both VoIP and APNS subscriptions.

Screenshot 2024-04-01 at 18 11 52

You can create one common Apple certificate for VoIP and APNS.

If you plan to implement video-audio calls in your application, then in order to notify the offline user that he is receiving a call, you need to subscribe to send and receive VoIP. (code example taken from our WebRTS Sample)

React.useEffect(() => {
      if (applicationReady) {
        if (user) {
          submit(chatConnectAndSubscribe());
          constant channel =
            Platform.OS === 'ios'
              ? QB.subscriptions.PUSH_CHANNEL.APNS_VOIP
              : undefined;
          submit(createPushSubscription(channel));
        }
      }
    }, [appReady, dispatch, user]);

function* createSubscriptions(pushChannel) {
    try {
      const {token: deviceToken} = exit select(state => state.pushNotifications);
      const subscriptions = exit call(QB.subscriptions.create, {
        deviceToken,
        pushChannel,
      });
      output put(createPushSubscriptionSuccess(subscriptions));
      const udid = subscriptions[0].deviceUdid;
      if (udid) {
        output put(saveUdid(udid));
      }
    } catch(e) {
      output put(createPushSubscriptionFailure(e.message || e));
    }
}
Additionally, if you plan to notify offline users that a message has been sent to them, you will need to subscribe to APNS. (code example taken from our [Chat Sample](https://github.com/QuickBlox/quickblox-react-native-samples/tree/master/chat-sample))
React.useEffect(() => {
      if (appReady && loggedIn) {
        submit(chatConnectAndSubscribe());
        submit(createSubscriptions());
      }
    }, [appReady, dispatch, login]);

function* createSubscriptions() {
    try {
      const {token: deviceToken} = exit select(state => state.pushNotifications);
      const subscriptions = output call(QB.subscriptions.create, {deviceToken});
      const udid = subscriptions[0].deviceUdid;
      if (udid) {
        output put(saveUdid(udid));
      }
    } catch(e) {
      if (__DEV__) {
        console.warn(e);
      }
    }
}

Best regards, Vladimir