Events #
An event system allows to be notified when the SDK status changes. These events are issued by the Kuzzle SDK object.
The API for interacting with events is described by our KuzzleEventEmitter class documentation.
You can listen to every events on the SDK by using the events property:
for (const event of kuzzle.events) {
kuzzle.on(event, (...args) => console.log(event, ...args));
}
Note: listeners are called in the order of their insertion.
Emitted Events #
connected #
Triggered when the SDK has successfully connected to Kuzzle.
discarded #
Triggered when Kuzzle discards a request, typically if no connection is established and the request is not queuable, either because the offline mode is not set or if set explicitely.
Callback arguments:
@param {object} request
: the discarded request
disconnected #
Triggered when the current session has been unexpectedly disconnected.
Callback arguments:
@param {object} context
Property | Type | Description |
---|---|---|
origin | string | Indicate what is causing the disconnection |
Origins
Name | Description |
---|---|
websocket/auth-renewal | The websocket protocol si reconnecting to renew the token. See Websocket Cookie Authentication. |
user/connection-closed | The disconnection is done by the user. |
network/error | An network error occured and caused a disconnection. |
beforeLogin #
Triggered before login attempt.
afterLogin #
Triggered when a login attempt completes, either with a success or a failure result.
loginAttempt #
Legacy event triggered when a login attempt completes, either with a success or a failure result.
Callback arguments:
@param {object} data
Property | Type | Description |
---|---|---|
success | boolean | Indicate if login attempt succeed |
error | string | Error message when login fail |
beforeLogout #
Triggered before logout attempt.
afterLogout #
Triggered when a logout attempt completes, either with a success or a failure result.
logoutAttempt #
Legacy event triggered when a logout attempt completes, either with a success or a failure result.
Callback arguments:
@param {object} data
Property | Type | Description |
---|---|---|
success | boolean | Indicate if logout attempt succeed |
error | string | Error message when logout fail |
networkError #
Triggered when the SDK has failed to connect to Kuzzle.
Callback arguments:
@param {Error} error
Property | Type | Description |
---|---|---|
message | string | Error description |
status | number | Error code |
stack | string | Stacktrace (development mode only) |
offlineQueuePop #
Triggered whenever a request is removed from the offline queue.
Callback arguments:
@param {object} request
: the request removed from the queue
offlineQueuePush #
Triggered whenever a request is added to the offline queue.
Callback arguments:
@param {object} data
Property | Type | Description |
---|---|---|
request | object | Request added to the queue |
queryError #
Triggered whenever Kuzzle responds with an error
Callback arguments:
@param {KuzzleError} error - Error details
@param {object} request - Request that caused the error
callbackError #
Triggered whenever the notification handler's callback returns a rejected promise
Callback arguments:
@param {Error} error - Error details
@param {Notification} notification - Notification of the handler
reconnected #
Triggered when the current session has reconnected to Kuzzle after a disconnection, and only if autoReconnect
is set to true
.
tokenExpired #
Triggered when Kuzzle rejects a request because the authentication token has expired.