Socket
Socket
Sign inDemoInstall

ddp

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ddp

Node.js module to connect to servers using DDP protocol.


Version published
Weekly downloads
660
decreased by-12.58%
Maintainers
4
Weekly downloads
 
Created
Source

Node DDP Client

A callback style DDP (Meteor's Distributed Data Protocol) node client.

Based heavily on alansikora's node-js_ddp-client, and meteor's python client. Uses a more callback style approach.

The client implements the pre1 version of DDP, with optional EJSON support. It is unfinished at this point, but should do most of what you want it to do.

Installation

  npm install ddp

Example

Please see the example in examples/example.js. Or here for reference:

var DDPClient = require("ddp");

var ddpclient = new DDPClient({
  host: "localhost", 
  port: 3000,
  /* optional: */
  auto_reconnect: true,
  auto_reconnect_timer: 500,
  use_ejson: true  // default is false
});

ddpclient.connect(function(error) {
  if (error) {
    console.log('DDP connection error!');
    return;
  }
  
  console.log('connected!');
  
  ddpclient.call('test-function', ['foo', 'bar'], function(err, result) {
    console.log('called function, result: ' + result);
  })
  
  ddpclient.subscribe('posts', [], function() {
    console.log('posts complete:');
    console.log(ddpclient.collections.posts);
  })
});

/*
 * Useful for debugging and learning the ddp protocol
 */
ddpclient.on('message', function(msg) {
  console.log("ddp message: " + msg);
});

/* 
 * If you need to do something specific on close or errors.
 * (You can also disable auto_reconnect and call ddpclient.connect()
 * when you are ready to re-connect.)
*/
ddpclient.on('socket-close', function(code, message) {
  console.log("Close: %s %s", code, message);
});

ddpclient.on('socket-error', function(error) {
  console.log("Error: %j", error);
});

Unimplemented Features

  • Server to Client messages
    • 'addedBefore'
    • 'movedBefore'
    • 'error'
    • 'updated'

Thanks

Many thanks to Alan Sikora for the ddp-client which formed the inspiration for this code.

Contributions:

  • Tom Coleman (@tmeasday)
  • Thomas Sarlandie (@sarfata)
  • Mason Gravitt (@emgee3)
  • Mike Bannister (@possiblities)
  • Chris Mather (@eventedmind)

Keywords

FAQs

Package last updated on 28 Aug 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