Skip to content

ernestrc/sonic-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

JavaScript client library for the Sonic query protocol

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published