Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

conducto

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conducto

foobar

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

conducto

WebSocket and HTTP framework. WIP

Build Status Dependency Status devDependency Status

Server
var conducto = require('conducto');

var server = new conducto.Server();

server.use({
  //name of the method to handle
  method: 'sum',
  /* this is a json schema to validate the payload,
  if it fails an error will be sent to the client */
  payload: {
    required: true,
    type: 'array',
    items: {
      type: 'number'
    }
  },
  //res is the callback to be called to send the error or the result to the client
  handler: function(payload, res) {
    var sum = 0;
    for (var i = 0; i < payload.length; i++) {
      sum += payload[i];
    }
    //first argument is the error, second is the result
    res(null, sum);
  }
});
server.listen(3000);
Client
var client = new conducto.Client();
//open client socket to server address
client.open('ws://localhost:3000');
//wait for socket to open
client.on('open', function() {
 /*
  * first argument is the method name,
  * second the payload, optional
  * third a callback optional, (if absent will trigger a notifications, no id)
  */
  client.emit('sum', ['foo', 'bar'], function(err, res) {
    /* an err will be received as the payload doesn't
     * validate against the previously defined json schema
     */
  });

  client.emit('sum', [0, 1, 2, 3], function(err, res) {
    console.log(res);
    //6
  });
});

FAQs

Package last updated on 13 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc