LiveQueryClient

Parse~ LiveQueryClient

Creates a new LiveQueryClient. Extends events.EventEmitter cloud functions.

A wrapper of a standard WebSocket client. We add several useful methods to help you connect/disconnect to LiveQueryServer, subscribe/unsubscribe a ParseQuery easily.

javascriptKey and masterKey are used for verifying the LiveQueryClient when it tries to connect to the LiveQuery server

We expose three events to help you monitor the status of the LiveQueryClient.

let Parse = require('parse/node');
let LiveQueryClient = Parse.LiveQueryClient;
let client = new LiveQueryClient({
  applicationId: '',
  serverURL: '',
  javascriptKey: '',
  masterKey: ''
 });

Open - When we establish the WebSocket connection to the LiveQuery server, you'll get this event.

client.on('open', () => {

});

Close - When we lose the WebSocket connection to the LiveQuery server, you'll get this event.

client.on('close', () => {

});

Error - When some network error or LiveQuery server error happens, you'll get this event.

client.on('error', (error) => {

});

Constructor

new LiveQueryClient(options)

Parameters:
Name Type Description
options Object
Name Type Description
applicationId string

applicationId of your Parse app

serverURL string

the URL of your LiveQuery server

javascriptKey string

(optional)

masterKey string

(optional) Your Parse Master Key. (Node.js only!)

sessionToken string

(optional)

installationId string

(optional)

Methods

close()

This method will close the WebSocket connection to this LiveQueryClient, cancel the auto reconnect and unsubscribe all subscriptions based on it.

open()

After open is called, the LiveQueryClient will try to send a connect request to the LiveQuery server.

subscribe(query, sessionToken) → {LiveQuerySubscription}

Subscribes to a ParseQuery

If you provide the sessionToken, when the LiveQuery server gets ParseObject's updates from parse server, it'll try to check whether the sessionToken fulfills the ParseObject's ACL. The LiveQuery server will only send updates to clients whose sessionToken is fit for the ParseObject's ACL. You can check the LiveQuery protocol here for more details. The subscription you get is the same subscription you get from our Standard API.

Parameters:
Name Type Description
query Object

the ParseQuery you want to subscribe to

sessionToken string

(optional)

Returns:
Type:
LiveQuerySubscription

subscription

unsubscribe(subscription)

After calling unsubscribe you'll stop receiving events from the subscription object.

Parameters:
Name Type Description
subscription Object

subscription you would like to unsubscribe from.