SDK
SDK Javascript v7.x
2

Constructor #

Use this constructor to create a new instance of the SDK. Each instance represent a different connection to a Kuzzle server with specific options.

Arguments #

Copied to clipboard!
Kuzzle(protocol, [options]);

Argument Type Description
protocol
Protocol
Protocol used by the SDK instance
options
object
Kuzzle object configuration

protocol #

The protocol used to connect to the Kuzzle instance. It can be one of the following available protocols:

options #

Kuzzle SDK instance options.

Property Type
(default)
Description
autoQueue
boolean

(false)
Automatically queue all requests during offline mode
autoReplay
boolean

(false)
Automatically replay queued requests on a reconnected event
autoResubscribe
boolean

(true)
Automatically renew all subscriptions on a reconnected event
cookieAuth
boolean

(false)
Uses cookie to store token, this option set offlineMode to auto and autoResubscribe to true
deprecationWarning
boolean

(true)
Show deprecation warning in development (hidden either way in production)
eventTimeout
number

(200)
Time (in ms) during which a similar event is ignored
offlineMode
string

(manual)
Offline mode configuration. Can be manual or auto
queueTTL
number

(120000)
Time a queued request is kept during offline mode, in milliseconds. Set it to 0 to keep queued requests indefinitely
queueMaxSize
number

(500)
Number of maximum requests kept during offline mode
replayInterval
number

(10)
Delay between each replayed requests, in milliseconds
requestTimeout
number

Default time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely
tokenExpiredInterval
number

(1000)
Time (in ms) during which a TokenExpired event is ignored
volatile
object

({})
Common volatile data, will be sent to all future requests

Return #

The Kuzzle SDK instance.

Usage #

Copied to clipboard!
// Loads the Kuzzle SDK module
const
  {
    Kuzzle,
    WebSocket,
    Http
  } = require('kuzzle-sdk');
const options = {
  offlineMode: 'auto',
  volatile: { username: 'Gordon' }
};
// Instantiates the SDK with the websocket protocol
const
  kuzzleWs = new Kuzzle(
    new WebSocket('kuzzle'),
    options
  );
// Instantiates the SDK with the http protocol
const
  kuzzleHttp = new Kuzzle(
    new Http('kuzzle')
  );