SkygearIO / chat

Skygear Plugin - Chat SDK
Apache License 2.0
17 stars 18 forks source link

Subscribe to a conversation failed occasionally #204

Closed carmenlau closed 6 years ago

carmenlau commented 6 years ago

Some time subscribe to a conversation failed. It looks like if all messages in a room are marked as read, subscribe to conversation doesn’t work. Not 100% sure. Need verify.

Reported user is using JS SDK in hybrid app.

carmenlau commented 6 years ago

Need further check the following scenario

carmenlau commented 6 years ago

@howawong Would like to know any findings or updates so far? About JS reconnect and the reconnection in react native. Thanks!!

howawong commented 6 years ago

talked to @chpapa last friday. I think it is the expected behavior of pubsub as it is not expected to receive any message sent from plugin after the connection is lost and even the connection is recovered. I think we either have

  1. persistent pubsub or
  2. call getMessages in pubsub listener onOpen in UIKit

The first approach is probably too big for now, I think we can stick to the second approach.

howawong commented 6 years ago

and @chpapa found the issue in Android/ iOS

howawong commented 6 years ago

FYI, JS SDK has implemented _reconnect. It is called whenever a connection is closed.

howawong commented 6 years ago

@carmenlau I had verified with chat-SDK-JS demo, the reconnection works as expected.

howawong commented 6 years ago

Further tested with react native sample code, the reconnection still works after switching different apps, turning off screen and airplane mode.

howawong commented 6 years ago

@carmenlau , @chpapa As discussed, the pub/sub is not persistent. Therefore it is best to call getMessages() whether pub/sub connection is established.

Sample Code

function refresh() {
  skygearChat.getMessages(conversation, limit, beforeTime)
    .then(function (messages) {
       //Update the UI with new messages
    });
}

const refreshHandler = skygear.pubsub.onOpen(refresh);

Meanwhile, there is an issue regarding pub/sub SkygearIO/skygear-server#556.

carmenlau commented 6 years ago

Check the client app, it looks like it is not related to the connection status. The user never get any message after enter the room, for the room has around 200 people.