-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
How to detect a user is offline when using liveQuery in a realtime chat app #1906
Comments
Lets say your Live Query is finding objects that have the
|
@drew-gross Thanks very much for your reply. Is it possible to set |
No, although that does sound like a good use case that we may want to think about adding. In the meantime, my recommendation is to use a separate save in the |
@drew-gross did you guys ended up adding any functionality for online/offline users? I need to detect user presence for a chat application. Do you have any recommendations on how to do it form a web application. If a user closes the browser window for example, I havent found a way to detect the user is gone. |
i tried to implement online/offline with the onLiveQueryEvent method. with the connect event i can save the client id with the user but when i close the tab, ws_disconnect event is triggered without the client id. i also tried with installationId but with multiple tabs it doesn't change. is it possible to retrieve the client id when the ws_disconnect event is triggered? |
Any solution? |
I found a solution. I've added one line of code to the file /node_modules/parse-server/lib/LiveQuery/ParseLiveQueryServer.js The line is With that you are able to recognize who disconnected from the websocket by the users sessionToken. Before it was just possible to get the sessionToken when the user connected. With that you can make a function to get the user object from the Session class and save it maybe in an array. This is where I added the line:
|
Thanks for the update. I reopened the issue because it seems like a useful and much sought after enhancement. If I understand correctly, it would currently be possible to infer the user from the @maxiqsoft Would you want to open a PR for this? |
Sorry, I am too dumb to push the changed code to the repo. I become the message that my local git version is too old and I am currently in homeoffice, so no admin rights. The file that has to become changed is located here: parse-server\src\LiveQuery
should become to |
I am using live queries to realize the realtime chat app, but I could not find the method to detect a user is online or offline. I am also confused with the
enter
andleave
events.When an existing ParseObject's old value does not fulfill the ParseQuery but its new value fulfills the ParseQuery, you'll get this event. The object is the ParseObject which enters the ParseQuery. Its content is the latest value of the ParseObject.
When an existing ParseObject's old value fulfills the ParseQuery but its new value doesn't fulfill the ParseQuery, you'll get this event. The object is the ParseObject which leaves the ParseQuery. Its content is the latest value of the ParseObject.
I wonder when to trigger these two events. Thanks in advance!
The text was updated successfully, but these errors were encountered: