Node.js module to connect to servers using DDP protocol.
The client implements version 1 of DDP, as well as fallbacks to pre1 and pre2.
npm install ddp
Built-in authentication support was removed in ddp 0.7.0 due to changes in Meteor version 0.8.2.
DDP Authentication is now implemented by vsivsi/ddp-login.
A quick and dirty (but insecure) alternative is to use plain-text logins via a method call:
// logging in with e-mailddpclient;// logging in with usernameddpclient;
Please see the example in
examples/example.js. Or here for reference:
var DDPClient = ;var ddpclient =// All properties optional, defaults shownhost : "localhost"port : 3000ssl : falseautoReconnect : trueautoReconnectTimer : 500maintainCollections : trueddpVersion : '1' // ['1', 'pre2', 'pre1'] available// uses the SockJs protocol to create the connection// this still uses websockets, but allows to get the benefits// from projects like meteorhacks:cluster// (for load balancing and service discovery)// do not use `path` option when you are using useSockJsuseSockJs: true// Use a full url instead of a set of `host`, `port` and `ssl`// do not set `useSockJs` option if `url` is usedurl: 'wss://example.com/websocket';/** Connect to the Meteor Server*/ddpclient;/** Useful for debugging and learning the ddp protocol*/ddpclient;/** Close the ddp connection. This will close the socket, removing it* from the event-loop, allowing your application to terminate gracefully*/ddpclient;/** If you need to do something specific on close or errors.* You can also disable autoReconnect and* call ddpclient.connect() when you are ready to re-connect.*/ddpclient;ddpclient;/** You can access the EJSON object used by ddp.*/var oid = ;
By using the
useSockJs option like below, DDP connection will use SockJs protocol to establish the WebSocket connection.
var ddpClient = useSockJs: true ;
Meteor server uses SockJs to implement it's DDP server. With this mode, we can get the benefits provided by meteorhacks:cluster. Some of those are load balancing and service discovery.
pathoption to identify the service you are referring to.
With this mode,
pathoption has a special meaning. So, thing twice before using
pathoption when you are using this option.
The node DDP client does not implement ordered collections, something that while in the DDP spec has not been implemented in Meteor yet.
Many thanks to Alan Sikora for the ddp-client which formed the inspiration for this code.