pubnub / js-chat

PubNub JavaScript Chat SDK
https://github.com/pubnub/js-chat
8 stars 8 forks source link

Time Out User #183

Open manfe opened 2 weeks ago

manfe commented 2 weeks ago

@piotr-suwala

I am having issues on how to listen to user being timed out.

BTW: our time out is being set on custom fields, and when updating the custom fields, no events are fired to the streamUpdates

I am trying to listen for user streamUpdates but this is not receiving anything related to this.

useEffect(() => {
    if (!chat?.currentUser) return

    setCurrentUser(chat.currentUser)

    // Subscribe to user updates
    console.debug("Subscribing to user updates")
    const disconnect = chat.currentUser.streamUpdates((user) => {
      console.debug("User updated", user)
      setCurrentUser(user)
    })

    return () => {
      console.debug("Unsubscribing from user updates")
      disconnect()
    }

  }, [chat?.currentUser])
manfe commented 2 weeks ago

I debug a bit more this and find some weird behaviors:

Our Access Manager didn't have permission to leave the channel, so was returning 403 and when trying to disconnect it was returning 504. (user channel)

But the weird behavior, is that when I joined another channel and the above error happened ^, the channel.streamUpdates for main channel, just stopped work and doesn't listen new messages.

After I removed the code above for currentUser.streamUpdates the main channel started working again.

manfe commented 1 week ago

Ok, we found a root cause, when trying to join a channel nothing is thrown, but when I listed the events for the sdk, it was returning 403 when trying to join the user channel and also user channel pnpres, so the network call for leave the channel was failing because it never succeeded to join it.

So we have an issue of not throwing error when a 403 error happens to join a channel.

Also the documentation of streamUpdates for Users, must be clear about the Access Manager permission needed to make it work correctly.

And, when a 403 happens on user streamUpdates, the channel.connect stopped receiving messages.

piotr-suwala commented 3 days ago

Hey, @manfe. We have acknowledged the problem and will put this into our backlog.