0.8.2 • Published 8 years ago

sonic-js v0.8.2

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

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

0.8.2

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago