I have a couple of questions regarding connection handling. Couldn’t find any information in the documentation.
Do we need to explicitly call Sendbird.disconnect() when the app goes into background state ? Or does the SDK handle it out of the box ?
How is the number of concurrent users calculated ? If Sendbird.connect() is called multiple times within seconds; does it count as multiple concurrent connections ?
If connect() is called shortly after disconnect() is being called on an active user, does it have any impact on the number of concurrent users ?
Q: Do we need to explicitly call Sendbird.disconnect() when the app goes into background state ? Or does the SDK handle it out of the box ?
A: For Android and iOS native SDKs Sendbird takes care of disconnection. For JavaScript you will need to take care of it.
Q: How is the number of concurrent users calculated ? If Sendbird.connect() is called multiple times within seconds; does it count as multiple concurrent connections ?
A: Each minute, SendBird takes a snapshot of the number of concurrent connections. Concurrent connections are users connected through a websocket. Multiple browser tabs equate to multiple connections.
Q: If connect() is called shortly after disconnect() is being called on an active user, does it have any impact on the number of concurrent users ?
A: I’m not sure what you mean here. If you are trying to reduce concurrent users via connect and disconnect you are taking an approach that will impact user experience. Please help to explain your use case further.
Thank you @Jason . My questions were specifically regarding native android sdk. What i wanted to know was whether it’s possible for a user on the same device to be counted multiple times in the concurrent users snapshot ? e.g if the user disconnected and connected again with in the same minute ? Also what happens when the connect() method is called multiple times in a short window ? e.g I noticed in logs that SendBird.connect() gets called twice in the app and success response is received because it gets called from multiple threads almost at the same time. I checked the connection status at the time of second call, and the status of sendbird was CONNECTING
@sayedhassan Thanks so much for getting back with a concrete example.
In the case you describe it is not possible for the same user to be counted more than once.
The reason for this is that the same user will never have more than one web-socket connection. Regardless of connecting or disconnecting sequence, at any given moment there will not be more than one web-socket connection for that user. Sendbird takes a snapshot of web-socket connections, meaning Sendbird doesn’t accumulate connections over a minute. Rather, Sendbird grabs total connections at the 1 minute mark.
Therefore, when the concurrent connection is counted there can only be one web-socket count for an Android SDK user.
Thank you @Jason for a detailed explanation. We saw a huge spike in our concurrent connections during the last month and just trying to figure out whether there’s anything wrong in our implementation.
@sayedhassan As Supertopoz said, Sendbird SDK supports a single connection. Therefore, even if there are multiple simultaneous requests, only one connection is performed.
Thank you guys. I think I figured it out. As I mentioned earlier, we were connecting to the SendBird server as soon as a user opens the app regardless of whether they intend to use the Chat feature or not. I have removed that code from the BaseApplication class and will monitor the number of connections after we release it early next week. The BaseApplication class now only has the SDK init call not the connect call.