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

LiveQuerySubscription "open" event does not fire as expected #1147

Closed
travsr opened this issue Apr 12, 2020 · 6 comments · Fixed by #1151
Closed

LiveQuerySubscription "open" event does not fire as expected #1147

travsr opened this issue Apr 12, 2020 · 6 comments · Fixed by #1151

Comments

@travsr
Copy link

travsr commented Apr 12, 2020

Issue Description

When I register an open event for a LiveQuerySubscription, the event does not fire on the intial websocket subscribed event as you'd expect. However, if it does fire if a reconnect happens.

My guess is the fact that you now have to wait for the subscription object to be returned via promise from query.subscribe() may be the cause. By the time you are able to register your event, the "open" event will already have been emitted by LiveQueryClient.

My quick fix was to add a slight timeout delay before the open event is emitted in LiveQueryClient.js, but that seems like more of a hack than a real solution.

Maybe I was just doing something wrong but this seemed like something potentially worth posting here.

Test Case

let query = new Parse.Query("MyClass");
let subscription = await query.subscribe();

subscription.on('open', (response) => {

    // (the stuff in here will not run)
    console.log("SUBSCRIPTION OPENED"); // <-- does not print to console
   
});

To accurately reproduce your issue. Add your test cases here and read the Contributing Guide to run the tests.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : ^4.2.0
    • Operating System: macOS 10.15.4
    • Localhost or remote server?: Localhost
  • JS SDK

    • JS SDK version: ^2.12.0
    • Application?: Browser

Logs/Trace

@dplewis
Copy link
Member

dplewis commented Apr 14, 2020

You brought up an interesting point. The point of waiting for the subscription is to ensure the connection is successful, resulting in the open event to not fire.

We should remove it from the documentation.

@acinader @davimacedo Thoughts?

@dplewis
Copy link
Member

dplewis commented Apr 14, 2020

@travsr Can you post your quick fix? I'm curious on how you got it to work.

@davimacedo
Copy link
Member

@dplewis what do you want to remove from the docs? The open event?

@dplewis
Copy link
Member

dplewis commented Apr 14, 2020

@davimacedo Hmm we could add a slight delay here. This will allow client time to set an Open Event and possibly the same for Error event.

@davimacedo
Copy link
Member

Yes. Just setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response)); should do the magic.

@travsr
Copy link
Author

travsr commented Apr 14, 2020

@dplewis @davimacedo Yep that's exactly where I added it in my code as well :) I used 200 ms and it hasn't given me issues so far.

dplewis added a commit that referenced this issue Apr 22, 2020
Closes: #1147

Waits 200 milliseconds to allow for client to set open event after the subscription resolves.
dplewis added a commit that referenced this issue Apr 22, 2020
* Fix: Live Query Subscription Open Event

Closes: #1147

Waits 200 milliseconds to allow for client to set open event after the subscription resolves.

* fix tests
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 a pull request may close this issue.

3 participants