Session/fetching channels throwing error after opening the application from background

I need help with session,
right now I’m starting my session with authentication call with following code,

const kittyChat = await kitty.startSession({
username: result.data.email,
authParams: {
password: result.data.token,
},
});
if (kittyChat.failed) {
setLoading(false);
return alert(kittyChat.error.message);
}

and for refreshing application, I’m calling hook in app.js to refresh token but after leaving application in background opening it again, following function returning success false

kitty.getChannels({filter: {joined: true}}).then((res) => {
if (res.succeeded) {
if (!isCancelled) {
setChannels(res.paginator.items);
}
}
if (loading) {
setLoading(false);
}
});
return () => {
isCancelled = true;
};

Hey @developer, welcome to ChatKitty Community! :wave:

Can you console log the result of kitty.getChannels(...)?

I suspect the previous ChatKitty session ended and therefore the current user is not set.

ChatKittyFailedResult {
“cancelled”: false,
“error”: [TypeError: undefined is not an object (evaluating ‘this._stompHandler.subscribe’)],
“failed”: true,
“succeeded”: false,
}

So every time when I re open my app from background it gives that error and showing loading… image continuously

Is this happening for all SDK function calls or just getChannels?

Can you try calling kitty.getCurrentUser()

Not sure about other SDK but when I open my app, I’m using getChannels only

Okay can you temporarily add kitty.getCurrentUser() and log the result? I want to see if this is related to not having an active session.

This is what I’m getting by using kitty.getCurrentUser()

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating ‘this._stompHandler.subscribe’)]
at node_modules/@stomp/stompjs/bundles/stomp.umd.js:620:51 in Client#subscribe
at http://192.168.2.13:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:197505:40 in
at node_modules/chatkitty/build/main/lib/chatkitty.js:128:27 in Promise$argument_0
at http://192.168.2.13:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:187746:24 in
at http://192.168.2.13:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:239620:37 in handleInitial
at app/screens/CommunicationScreen.js:56:4 in CommunicationScreen
at [native code]:null in callFunctionReturnFlushedQueue

Thanks @developer! That stack trace was very helpful.

This looks like it’s caused by an issue in stompjs, a library the SDK depends on TypeError: Cannot read property 'publish' of undefined · Issue #109 · stomp-js/stompjs · GitHub. Due to a timing issue when a request is sent before the network connection is re-established.

I’ll update the SDK to wait for the device to reconnect with ChatKitty before sending requests when resuming from the background.

@developer I’ve published a new version of the SDK 1.27.1 that fixes this.

Thanks, do I need to do anything from my end? in order to make it work properly?

You just have to upgrade your ChatKitty SDK version.

completed upgrade for sdk and checked with the same test case and result is still showing this,

ChatKittyFailedResult {
“cancelled”: false,
“error”: [TypeError: undefined is not an object (evaluating ‘this._stompHandler.subscribe’)],
“failed”: true,
“succeeded”: false,
}

for following code,

const handleInitial = (load = false) => {
        if(load) setLoading(true);

        let isCancelled = false;
        kitty.getChannels({filter: {joined: true}}).then((res) => {
            console.log(res);
            if (res.succeeded) {
                if (!isCancelled) {
                    setChannels(res.paginator.items);
                }
            }
            if (loading) {
                setLoading(false);
            }
        });
        return () => {
            isCancelled = true;
        };
    }

    useEffect(() => {
        handleInitial();
    }, [isFocused, loading]);

with dependency,


"node_modules/chatkitty": {
      "version": "1.27.1",
      "resolved": "https://registry.npmjs.org/chatkitty/-/chatkitty-1.27.1.tgz",
      "integrity": "sha512-qtn7jlxfVL3vVYPNspYm3Te6XtoQaiSyWtSwUK9Qk3kZgfqVTFwPp/PA/6Foe+5RMTgkdlhTwD5WXm4GDzISPQ==",
      "dependencies": {
        "@stomp/rx-stomp": "^1.1.2",
        "axios": "^0.21.1",
        "rxjs": "^6.6.7",
        "sockjs-client": "^1.5.1",
        "text-encoding": "^0.7.0"
      },
      "engines": {
        "node": ">=10"
      }
    },

I haven’t seen any connections with version 1.27.1 from your application

I updated my sdk with following command,

npm upgrade chatkitty

let me know if I’m doing something wrong.

Is there anyway to verify my sdk and other details?

The server logs show your version is ChatKitty-JS/1.24.1.

Can you try stopping your expo CLI, deleting your node_modules directory, running npm install and reloading Expo?

Sure, Thanks

1 Like

Can you try stopping your expo CLI, deleting your node_modules directory, running npm install and reloading Expo?

Tried this and still the same issue

I’m still not seeing the new version. How are you reloading Expo?

Its working properly with deployed version now.

Thanks for your help

1 Like