Search code examples
parse-platform

detect LiveQuery connected clients on parse Server


how do i can detect when client connects via liveQuery to parse server. I want to updata some data in MongoDB on client's Disconnect Event by Server. Log display on Server but how i can call some function after detection of this event.

I am using self hosted Parse SErver. connect client lists on server

thanks in advance


Solution

  • Here you go:

    Parse.Cloud.onLiveQueryEvent( ({event, clients, subscriptions, error}) => {
      if (event !== 'ws_disconnect') {
        return;
      }
      // Do your magic
    });
    

    In case you were wondering, these are the currently emitted events:

    • connect
    • subscribe
    • unsubscribe
    • ws_connect
    • ws_disconnect
    • ws_disconnect_error

    "connect" differs from "ws_connect", the former means that the client completed the connect procedure as defined by Parse livequery protocol, where "ws_connect" just means that a new websocket was created.