How to use the kuzzle-sdk.WebSocket function in kuzzle-sdk

To help you get started, we’ve selected a few kuzzle-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kuzzleio / sdk-javascript / doc / 6 / getting-started / webpack / snippets / init-kuzzle.js View on Github external
// load the Kuzzle SDK module
/* snippet:start:1 */
import { Kuzzle, WebSocket } from 'kuzzle-sdk';
/* snippet:end */

// instantiate a Kuzzle client
/* snippet:start:2 */
const kuzzle = new Kuzzle(new WebSocket('kuzzle'));
/* snippet:end */

// add a listener to detect any connection problems
/* snippet:start:3 */
kuzzle.on('networkError', error => {
  console.error(`Network Error: ${error}`);
});
/* snippet:end */

/* snippet:start:4 */
const run = async () => {
  try {
    // Connect to Kuzzle server
    await kuzzle.connect();

    // Create an index
github kuzzleio / kuzzle / bin / commands / sendAction.js View on Github external
const config = {
    host: options.host || 'localhost',
    port: options.port || 7512
  };

  if (options.username && options.password) {
    config.login = {
      strategy: 'local',
      credentials: {
        username: options.username,
        password: options.password
      }
    };
  }

  const kuzzle = new Kuzzle(new WebSocket(config.host, { port: config.port }));

  return kuzzle.connect()
    .then(() => {
      if (config.login) {
        return kuzzle.auth.login(config.login.strategy, config.login.credentials);
      }
    })
    .then(() => kuzzle.query(query));
}
github kuzzleio / kuzzle / features-sdk / support / world.js View on Github external
_getSdk () {
    let protocol;

    switch (this.protocol) {
      case 'http':
        protocol = new Http(this.host, { port: this.port });
        break;
      case 'websocket':
        protocol = new WebSocket(this.host, { port: this.port });
        break;
      default:
        throw new Error(`Unknown protocol "${this.protocol}".`);
    }

    return new Kuzzle(protocol);
  }
}
github kuzzleio / kuzzle / features-sdk / support / hooks.js View on Github external
function getProtocol (world) {
  let protocol;

  switch (world.protocol) {
    case 'http':
      protocol = new Http(world.host, { port: world.port });
      break;
    case 'websocket':
      protocol = new WebSocket(world.host, { port: world.port });
      break;
    default:
      throw new Error(`Unknown protocol "${world.protocol}".`);
  }

  return protocol;
}

kuzzle-sdk

Official Javascript SDK for Kuzzle

Apache-2.0
Latest version published 2 days ago

Package Health Score

70 / 100
Full package analysis