Code Monkey home page Code Monkey logo

sonic-js's Introduction

Sonic-js Build Status npm version

WebSockets Client library for the Sonic protocol

Installation

  • Using npm:
npm install sonic-js
  • For browser usage, bundling has has been tested with browserify and babel.

Usage

var Client = require('sonic-js').Client;
var assert = require('assert');

var client = new Client('ws://0.0.0.0:9111');

var query = {
  query: '5',
  config: {
    "class" : "SyntheticSource",
    "seed" : 1000,
    "progress-delay" : 10
  }
};

/* Client.prototype.run */

client.run(query, function(err, res) {
  if (err) {
    console.log(err);
    return;
  }

  res.forEach(function(e) {
    console.log(e);
  });

  client.close();
  console.log('exec is done!');

});

/* Client.prototype.stream */

var stream = client.stream(query);

var done = 0;

stream.on('data', function(data) {
  console.log(data);
});

stream.on('progress', function(p) {
  done += p.progress;
  console.log('running.. ' + done + "/" + p.total + " "+ p.units);
});

stream.on('output', function(out) {
  console.log(out);
});

stream.on('metadata', function(meta) {
  console.log('metadata: ' + JSON.stringify(meta));
});

stream.on('done', function() {
  console.log('stream is done!');
});

stream.on('error', function(err) {
  console.log('stream error: ' + err);
});

For a more complete example, check examples/example.js.

Contribute

If you would like to contribute to the project, please fork the project, include your changes and submit a pull request back to the main repository.

License

MIT License

sonic-js's People

Contributors

ernestrc avatar

Watchers

James Cloos avatar Michael Kelleher avatar  avatar Nan Xin avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.