LiveQueryClient

Parse. LiveQueryClient

Creates a new LiveQueryClient. 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.

const LiveQueryClient = Parse.LiveQueryClient;
const 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

(async) close() → {Promise|undefined}

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

Returns:
Type:
Promise | undefined

open()

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

subscribe(query, sessionToken) → {LiveQuerySubscription|undefined}

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 ParseQuery

the ParseQuery you want to subscribe to

sessionToken string

(optional)

Returns:
Type:
LiveQuerySubscription | undefined

(async) unsubscribe(subscription) → {Promise|undefined}

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.

Returns:
Type:
Promise | undefined