ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
125 stars 111 forks source link

Push notification opening and screen redirect errors #244

Closed rexcode closed 3 years ago

rexcode commented 3 years ago

I have forked RNVideochat sample code and expanded it to include chat functionality as per RNChat sample code

I have set up push notifications as provided by conectycube documentation. reference - https://developers.connectycube.com/reactnative/push-notifications

I have also setup subcribeToPushNotification() method and I can manually send notification (data only) using ConnectyCube.pushnotifications.events method

However, when there is a new chat I am able to receive new push notifications for it but when I open the push notification and try to navigate to a different screen I get one of these 2 errors as shown below. Once I get any of these errors, then even if I try to open a simple data-only notification with no processing, I get any of these 2 errors.

I have tried opening push notifications using both react-native-push-notification and @react-native-firebase/messaging packages

I am using PushNotification.configure({ onRegister: }) to subscribe to push notifications as user logs and goes to the first screen of my app I have tried to open notification using PushNotification.configure({ onNotification }) on the first screen after user logs in and also in App.js I have also used @react-native-firebase/messaging messaging().onNotificationOpenedApp method to open the notifications but every time I get the same 2 errors

I have used NavigationActions from 'react-navigation' on App.js to access the navigator

I had initially installed react-native-push-notification:@3.1.9 version as was specified in your RNChat code sample and tried to upgrade it to the latest version but due to some error I reverted to back 3.1.9 version

2 Errors I receive when I try to open a push notification and redirect to a different screen -

  1. image
  2. image

package.json from your reference image

Please guide

ccvlad commented 3 years ago

Hi @rexcode ! Thanks for expanded description! Before use classes and methods from ConnectyCube SDK you have to call ConnectyCube.init(...). It will create all classes. Please take a look on ConnectyCube.chat.markActive(). Seems it is calling before the ConnectyCube.init(...).. Usually methods markActive and markInactive are called in RN AppState's listener.

rexcode commented 3 years ago

Hi, Thank you for your very quick reply.

I am relatively new to React Native, can u please guide where I need to call ConnectyCube.init(...) ie. before or after sending push notification

I see _ConnectyCube.init(...) is called in auth-service.js which is called in appWrap.js which is the entry point for my app.

I am able to debug my app crashes after getUserSession() is called by autologin() in auth-service.js

image

ccvlad commented 3 years ago

Depends of where you are calling ConnectyCube.chat.markActive(). Is it calling from RN AppStateListener? You can call AppState.addEventListener('change', someFunc) after ConnectyCube.init(...appConfig.connectyCubeConfig) or autologin(). Second way is change ConnectyCube.chat.markActive() to ConnectyCube.chat?.markActive(). The chaining operator ? will check possibility to call method markActive from ConnectyCube.chat class.

rexcode commented 3 years ago

Hi, thanks for your reply. For time being I have commented out ConnectyCube.chat.markActive() and app crash error has gone away

I think this will have minor effect if not so kindly inform

I will update again in sometime

ccvlad commented 3 years ago

FYI - https://developers.connectycube.com/js/messaging?id=mark-a-client-as-activeinactive

Also guide by my previous message to make all correctly