stream-chat-js icon indicating copy to clipboard operation
stream-chat-js copied to clipboard

Presence showing true then immediately false

Open jmckenney opened this issue 3 years ago • 3 comments

I got over the hurdle of being able to listen to presence changes but it looks like the ws messages are immediately showing the users as offline milliseconds after showing online. Any tips?

Uploading video now showing websocket messages:

https://www.youtube.com/watch?v=MeyE6O5I8rY

Where I'm listening for presence:

export const ChatChannelSetter: FC<ChatChannelSetterProps> = (properties) => {
  const { children, channelInit } = properties
  const client = useChatClient()
  const [, setChannel] = useChannelState()

  const { type, id, data } = channelInit
  useEffect(() => {
    const loadChat = async () => {
      if (client) {
        const channel = client.channel(type, id, data)
        await channel.watch({ presence: true })
        setChannel(channel)
      }
    }
    loadChat()
  }, [type, id, data, client, setChannel])

  return <>{children}</>
}

Where I'm listening to the event:

  useEffect(() => {
    const updateChannelUsers = (event?: Event) => {
      console.log('JOSH: user presence changed', event)
      if (!event || channel.state.members[event.user?.id] !== undefined) {
        setChannelUsers(
          Object.values(channel.state.members).map((user) => ({
            name: user.user_id!,
            online: !!user.user?.online,
          }))
        )
      }
    }

    updateChannelUsers()

    client.on('user.presence.changed', updateChannelUsers)

    return () => {
      client.off('user.presence.changed', updateChannelUsers)
    }
  }, [client, channel])

jmckenney avatar Apr 08 '22 16:04 jmckenney

I'm having the same issue. I also checked users' online status through Stream dashboard, but all the users are shown as offline. It was working a couple of weeks ago, and I haven't made any changes since then.

onurarrii avatar Jun 07 '22 14:06 onurarrii

I'm having the same issue. I also checked users' online status through Stream dashboard, but all the users are shown as offline. It was working a couple of weeks ago, and I haven't made any changes since then.

I am also facing the same issue.

ghazanfar22 avatar Jun 08 '22 08:06 ghazanfar22

I'm having the same issue. I also checked users' online status through Stream dashboard, but all the users are shown as offline. It was working a couple of weeks ago, and I haven't made any changes since then.

It seems to be working now.

onurarrii avatar Jun 08 '22 19:06 onurarrii

@ jmckenney I'm closing this issue. It works for @onurarrii and myself locally. Don't hesitate to contact us in the future may you be facing this or any other issues.

vanGalilea avatar Aug 18 '22 12:08 vanGalilea