Improve Live Query Monitoring (#5927)
* Improve Live Query Monitoring * typo
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
cea1988ce9
commit
3ab9dcdfd0
@@ -15,6 +15,7 @@ class Client {
|
||||
id: number;
|
||||
parseWebSocket: any;
|
||||
hasMasterKey: boolean;
|
||||
sessionToken: string;
|
||||
userId: string;
|
||||
roles: Array<string>;
|
||||
subscriptionInfos: Object;
|
||||
@@ -27,10 +28,16 @@ class Client {
|
||||
pushDelete: Function;
|
||||
pushLeave: Function;
|
||||
|
||||
constructor(id: number, parseWebSocket: any, hasMasterKey: boolean) {
|
||||
constructor(
|
||||
id: number,
|
||||
parseWebSocket: any,
|
||||
hasMasterKey: boolean = false,
|
||||
sessionToken: string
|
||||
) {
|
||||
this.id = id;
|
||||
this.parseWebSocket = parseWebSocket;
|
||||
this.hasMasterKey = hasMasterKey;
|
||||
this.sessionToken = sessionToken;
|
||||
this.roles = [];
|
||||
this.subscriptionInfos = new Map();
|
||||
this.pushConnect = this._pushEvent('connected');
|
||||
|
||||
@@ -580,15 +580,24 @@ class ParseLiveQueryServer {
|
||||
}
|
||||
const hasMasterKey = this._hasMasterKey(request, this.keyPairs);
|
||||
const clientId = uuid();
|
||||
const client = new Client(clientId, parseWebsocket, hasMasterKey);
|
||||
const client = new Client(
|
||||
clientId,
|
||||
parseWebsocket,
|
||||
hasMasterKey,
|
||||
request.sessionToken
|
||||
);
|
||||
parseWebsocket.clientId = clientId;
|
||||
this.clients.set(parseWebsocket.clientId, client);
|
||||
logger.info(`Create new client: ${parseWebsocket.clientId}`);
|
||||
client.pushConnect();
|
||||
runLiveQueryEventHandlers({
|
||||
client,
|
||||
event: 'connect',
|
||||
clients: this.clients.size,
|
||||
subscriptions: this.subscriptions.size,
|
||||
sessionToken: request.sessionToken,
|
||||
useMasterKey: client.hasMasterKey,
|
||||
installationId: request.installationId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -663,13 +672,16 @@ class ParseLiveQueryServer {
|
||||
const subscriptionInfo = {
|
||||
subscription: subscription,
|
||||
};
|
||||
// Add selected fields and sessionToken for this subscription if necessary
|
||||
// Add selected fields, sessionToken and installationId for this subscription if necessary
|
||||
if (request.query.fields) {
|
||||
subscriptionInfo.fields = request.query.fields;
|
||||
}
|
||||
if (request.sessionToken) {
|
||||
subscriptionInfo.sessionToken = request.sessionToken;
|
||||
}
|
||||
if (request.installationId) {
|
||||
subscriptionInfo.installationId = request.installationId;
|
||||
}
|
||||
client.addSubscriptionInfo(request.requestId, subscriptionInfo);
|
||||
|
||||
// Add clientId to subscription
|
||||
@@ -685,9 +697,13 @@ class ParseLiveQueryServer {
|
||||
);
|
||||
logger.verbose('Current client number: %d', this.clients.size);
|
||||
runLiveQueryEventHandlers({
|
||||
client,
|
||||
event: 'subscribe',
|
||||
clients: this.clients.size,
|
||||
subscriptions: this.subscriptions.size,
|
||||
sessionToken: request.sessionToken,
|
||||
useMasterKey: client.hasMasterKey,
|
||||
installationId: request.installationId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -763,9 +779,13 @@ class ParseLiveQueryServer {
|
||||
this.subscriptions.delete(className);
|
||||
}
|
||||
runLiveQueryEventHandlers({
|
||||
client,
|
||||
event: 'unsubscribe',
|
||||
clients: this.clients.size,
|
||||
subscriptions: this.subscriptions.size,
|
||||
sessionToken: subscriptionInfo.sessionToken,
|
||||
useMasterKey: client.hasMasterKey,
|
||||
installationId: subscriptionInfo.installationId,
|
||||
});
|
||||
|
||||
if (!notifyClient) {
|
||||
|
||||
Reference in New Issue
Block a user