Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LongPoll #814

Merged
merged 55 commits into from
Dec 2, 2021
Merged

LongPoll #814

merged 55 commits into from
Dec 2, 2021

Conversation

mahboubii
Copy link
Contributor

@mahboubii mahboubii commented Nov 22, 2021

  • Retry
  • Recover state
  • Test

@github-actions
Copy link
Contributor

github-actions bot commented Nov 22, 2021

Size Change: +14.3 kB (5%) 🔍

Total Size: 277 kB

Filename Size Change
dist/browser.es.js 60.3 kB +3.17 kB (5%) 🔍
dist/browser.full-bundle.min.js 33.9 kB +2 kB (5%) 🔍
dist/browser.js 61 kB +3 kB (4%)
dist/index.es.js 60.4 kB +3.17 kB (5%) 🔍
dist/index.js 61.1 kB +3 kB (4%)

compressed-size-action

@@ -256,14 +266,14 @@ export class StableWSConnection<
* @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Promise that completes once the first health check message is received
*/
async _connect() {
if (this.isConnecting) return; // simply ignore _connect if it's currently trying to connect
if (this.isConnecting || this.isDisconnected) return; // simply ignore _connect if it's currently trying to connect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will affect background/foreground logic on mobile, no? Once disconnected, user won't be able to connect again when app comes back to foreground

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs maintenance of it in callback to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you call to connect again when the app comes to foreground?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you call disconnect(), and then call connectUser() again, it should work since connect will set isDisconnected to false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on RN we use openConnection/closeConnection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it should be OK, but still worth manual testing with both longpoll enabled/disabled situation

src/utils.ts Outdated Show resolved Hide resolved
src/errors.ts Show resolved Hide resolved
src/client.ts Show resolved Hide resolved
* connect try to open a longpoll request
* @param reconnect should be false for first call and true for subsequent calls to keep the connection alive and call recoverState
*/
connect = async (reconnect = false) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this connect has reconnect as argument, while the other has timeout. Maybe better to use an object on both.

Suggested change
connect = async (reconnect = false) => {
connect = async (options = { reconnect: false }) => {

} catch (err) {
// run fallback only if it's WS/Network error and not a normal API error
// make sure browser is online before even trying the longpoll
if (this.options.enableWSFallback && isWSFailure(err) && isOnline()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't remove thhe online check. If you're offline the this.wsConnection.connect fails and isWsFailure will return false anyways. On the other hand, if it could be the case that you have a wsFailure and you're offline, in RN this check wouldn't work, and we would trigger the fallback while offline. I'm not sure if I'm missing something, though. Does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we did a bad job with naming here but isWSFailure here returns true if you are offline, basically, isWSFailure is in contrast with isAPIFailure. isWSFailure is true when we couldn't reach API for any reason, including network issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on this: so I just tested on RN. If you access window.navigator it looks like following:

{"product": "ReactNative"}

And thus isOnline() function will return always undefined -> fallback will never be executed. Maybe we can provide a way so that RN SDK can let JS client know about the online status (e.g., we can provide js client with async function to fetch online status).

@mahboubii mahboubii marked this pull request as ready for review December 2, 2021 11:17
Copy link
Contributor

@vishalnarkhede vishalnarkhede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mahboubii mahboubii merged commit d4e8c6a into master Dec 2, 2021
@mahboubii mahboubii deleted the longpoll branch December 2, 2021 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants