Socket
Socket
Sign inDemoInstall

ddp

Package Overview
Dependencies
Maintainers
5
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ddp - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

34

CHANGELOG.md

@@ -0,6 +1,12 @@

0.8.0 - 2014-09-16
- Bump DDP version to 1
- Fix connect callback handler (#41)
- Change underscored_variable_names to camelCase
0.7.0 - 2014-06-23
- Built-in support for authenticating to Meteor's Accounts system in has
been removed, due to changes in Meteor's Accounts system in 0.8.2
(https://github.com/meteor/meteor/blob/devel/History.md#meteor-accounts).
- Built-in support for authenticating to Meteor's Accounts system in has
been removed, due to changes in Meteor's Accounts system in 0.8.2
(https://github.com/meteor/meteor/blob/devel/History.md#meteor-accounts).
If you need login support, try https://github.com/vsivsi/ddp-login

@@ -11,3 +17,3 @@ - EJSON support now mandatory

- Update collection before emitting `message`.
- Update collection before emitting `message`.

@@ -24,7 +30,7 @@ 0.5.2 - 2014-06-01

- Use ddp-ejson instead of meteor-ejson. ddp-ejson is a repackage of
- Use ddp-ejson instead of meteor-ejson. ddp-ejson is a repackage of
Meteor's latest EJSON package
- Use ddp-srp insead of node-srp. ddp-srp is a repackage of Meteor's
- Use ddp-srp insead of node-srp. ddp-srp is a repackage of Meteor's
latest SRP package
- Added second callback to ddpclient.call, executed when the DDP
- Added second callback to ddpclient.call, executed when the DDP
`updated` message is received

@@ -48,4 +54,4 @@ - Allow automatic EJSON serialization/deserialization of ObjectIDs

- Fix a bug where if the server responded to an error on the first
step of SRP authentication it was not handled correctly (i.e when
- Fix a bug where if the server responded to an error on the first
step of SRP authentication it was not handled correctly (i.e when
the user is not found)

@@ -55,5 +61,5 @@

- Fix bug with socket reconnects tailspinning into an infinite loop
- Fix bug with socket reconnects tailspinning into an infinite loop
(#30 by @jagill)
- Fix bug when use_ejson was not always set properly by default.
- Fix bug when use_ejson was not always set properly by default.
(#29 by @jagill)

@@ -75,3 +81,3 @@

- fixed bug with default params when ignoring root certs (in case the
- fixed bug with default params when ignoring root certs (in case the
machine doesn't have the cert)

@@ -90,3 +96,3 @@ - Added DDP login with SRP authentication

- fixed bug where an exception could be thrown when sending a message on
- fixed bug where an exception could be thrown when sending a message on
a socket that is not opened anymore (issue #18)

@@ -101,3 +107,3 @@ - added some tests (work in progress)

- added a failed message to the connect callback if version negotiation
- added a failed message to the connect callback if version negotiation
fails.

@@ -104,0 +110,0 @@

var DDPClient = require("ddp");
var ddpclient = new DDPClient({
host: "localhost",
port: 3000,
/* optional: */
auto_reconnect: true,
auto_reconnect_timer: 500,
use_ssl: false,
maintain_collections: true // Set to false to maintain your own collections.
// All properties optional, defaults shown
host : "localhost",
port : 3000,
path : "websocket",
ssl : false,
autoReconnect : true,
autoReconnectTimer : 500,
maintainCollections : true,
ddpVersion : '1' // ['1', 'pre2', 'pre1'] available
});

@@ -17,3 +19,3 @@

ddpclient.connect(function(error) {
// If auto_reconnect is true, this callback will be invoked each time
// If autoReconnect is true, this callback will be invoked each time
// a server connection is re-established

@@ -77,2 +79,2 @@ if (error) {

);
});
});

@@ -1,6 +0,6 @@

var WebSocket = require('faye-websocket'),
_ = require('ddp-underscore-patched'),
util = require('util'),
events = require('events'),
EJSON = require('ddp-ejson'),
var util = require("util");
var events = require("events");
var WebSocket = require("faye-websocket");
var EJSON = require("ddp-ejson");
var _ = require("ddp-underscore-patched");

@@ -10,18 +10,23 @@ DDPClient = function(opts) {

opts = opts || {};
// backwards compatibility
if ("use_ssl" in opts) opts.ssl = opts.use_ssl;
if ("autoReconnect" in opts) opts.autoReconnect = opts.autoReconnect;
if ("auto_reconnect_timer" in opts) opts.autoReconnectTimer = opts.auto_reconnect_timer;
if ("maintain_collections" in opts) opts.maintainCollections = opts.maintain_collections;
if ("ddp_version" in opts) opts.ddpVersion = opts.ddp_version;
// default arguments
opts = opts || {};
self.host = opts.host || 'localhost';
self.host = opts.host || "localhost";
self.port = opts.port || 3000;
self.path = opts.path || 'websocket';
self.use_ssl = opts.use_ssl || self.port === 443;
self.auto_reconnect = ('auto_reconnect' in opts) ? opts.auto_reconnect : true;
self.auto_reconnect_timer = ('auto_reconnect_timer' in opts) ? opts.auto_reconnect_timer : 500;
self.maintain_collections = ('maintain_collections' in opts) ? opts.maintain_collections : true;
self.path = opts.path || "websocket";
self.ssl = opts.ssl || self.port === 443;
self.autoReconnect = ("autoReconnect" in opts) ? opts.autoReconnect : true;
self.autoReconnectTimer = ("autoReconnectTimer" in opts) ? opts.autoReconnectTimer : 500;
self.maintainCollections = ("maintainCollections" in opts) ? opts.maintainCollections : true;
//May not work with faye-websockets
self.use_ssl_strict = ('use_ssl_strict' in opts) ? opts.use_ssl_strict : true;
// support multiple ddp versions
self.ddp_version = ('ddp_version' in opts) ? opts.ddp_version : 'pre2';
self.supported_ddp_versions = ['pre2', 'pre1'];
self.ddpVersion = ("ddpVersion" in opts) ? opts.ddpVersion : "1";
self.supportedDdpVersions = ["1", "pre2", "pre1"];

@@ -32,7 +37,7 @@ // Expose EJSON object, so client can use EJSON.addType(...)

// very very simple collections (name -> [{id -> document}])
if (self.maintain_collections)
if (self.maintainCollections)
self.collections = {};
// internal stuff to track callbacks
self._next_id = 0;
self._nextId = 0;
self._callbacks = {};

@@ -51,23 +56,23 @@ self._updatedCallbacks = {};

self.socket.on('open', function() {
self.socket.on("open", function() {
// just go ahead and open the connection on connect
self._send({
msg: 'connect',
version: self.ddp_version,
support: self.supported_ddp_versions
self._send({
msg : "connect",
version : self.ddpVersion,
support : self.supportedDdpVersions
});
});
self.socket.on('error', function(error) {
self.emit('socket-error', error);
self.socket.on("error", function(error) {
self.emit("socket-error", error);
});
self.socket.on('close', function(event) {
self.emit('socket-close', event.code, event.reason);
self.socket.on("close", function(event) {
self.emit("socket-close", event.code, event.reason);
self._recoverNetworkError();
});
self.socket.on('message', function(event) {
self.socket.on("message", function(event) {
self._message(event.data);
self.emit('message', event.data);
self.emit("message", event.data);
});

@@ -86,5 +91,5 @@ };

var self = this;
if (self.auto_reconnect && ! self._connectionFailed && ! self._isClosing) {
if (self.autoReconnect && ! self._connectionFailed && ! self._isClosing) {
self._clearReconnectTimeout();
self.reconnectTimeout = setTimeout(function() { self.connect(); }, self.auto_reconnect_timer);
self.reconnectTimeout = setTimeout(function() { self.connect(); }, self.autoReconnectTimer);
}

@@ -113,17 +118,17 @@ };

} else if (data.msg === 'failed') {
if (self.supported_ddp_versions.indexOf(data.version) !== -1) {
this.ddp_version = data.version;
} else if (data.msg === "failed") {
if (self.supportedDdpVersions.indexOf(data.version) !== -1) {
this.ddpVersion = data.version;
self.connect();
} else {
self.auto_reconnect = false;
self.emit('error', 'cannot negotiate ddp version');
self.autoReconnect = false;
self.emit("failed", "Cannot negotiate DDP version");
}
} else if (data.msg === 'connected') {
} else if (data.msg === "connected") {
self.session = data.session;
self.emit('connected');
self.emit("connected");
// method result
} else if (data.msg === 'result') {
} else if (data.msg === "result") {
var cb = self._callbacks[data.id];

@@ -137,3 +142,3 @@

// method updated
} else if (data.msg === 'updated') {
} else if (data.msg === "updated") {

@@ -149,3 +154,3 @@ _.each(data.methods, function (method) {

// missing subscription
} else if (data.msg === 'nosub') {
} else if (data.msg === "nosub") {
var cb = self._callbacks[data.id];

@@ -159,9 +164,9 @@

// add document to collection
} else if (data.msg === 'added') {
if (self.maintain_collections && data.collection) {
} else if (data.msg === "added") {
if (self.maintainCollections && data.collection) {
var name = data.collection, id = data.id;
if (!self.collections[name])
if (! self.collections[name])
self.collections[name] = {};
if (!self.collections[name][id])
if (! self.collections[name][id])
self.collections[name][id] = {};

@@ -177,7 +182,7 @@

// remove document from collection
} else if (data.msg === 'removed') {
if (self.maintain_collections && data.collection) {
} else if (data.msg === "removed") {
if (self.maintainCollections && data.collection) {
var name = data.collection, id = data.id;
if (!self.collections[name][id])
if (! self.collections[name][id])
return;

@@ -189,8 +194,8 @@

// change document in collection
} else if (data.msg === 'changed') {
if (self.maintain_collections && data.collection) {
} else if (data.msg === "changed") {
if (self.maintainCollections && data.collection) {
var name = data.collection, id = data.id;
if (!self.collections[name]) return;
if (!self.collections[name][id]) return;
if (! self.collections[name]) return;
if (! self.collections[name][id]) return;

@@ -211,3 +216,3 @@ if (data.fields) {

// subscriptions ready
} else if (data.msg === 'ready') {
} else if (data.msg === "ready") {
_.each(data.subs, function(id) {

@@ -222,5 +227,5 @@ var cb = self._callbacks[id];

// minimal heartbeat response for ddp pre2
} else if (data.msg === 'ping') {
} else if (data.msg === "ping") {
self._send(
_.has(data, 'id') ? { msg : 'pong', id : data.id } : { msg : 'pong' }
_.has(data, "id") ? { msg : "pong", id : data.id } : { msg : "pong" }
);

@@ -233,3 +238,3 @@ }

return (this._next_id += 1).toString();
return (this._nextId += 1).toString();
};

@@ -242,5 +247,5 @@

/* open the connection to the server
*
*
* connected(): Called when the 'connected' message is received
* If auto_reconnect is true (default), the callback will be
* If autoReconnect is true (default), the callback will be
* called each time the connection is opened.

@@ -265,7 +270,8 @@ */

// websocket
var protocol = self.use_ssl ? 'wss://' : 'ws://';
self.socket = new WebSocket.Client(protocol + self.host + ':' + self.port + '/' + self.path);
var protocol = self.ssl ? "wss://" : "ws://";
self.socket = new WebSocket.Client(protocol + self.host + ":" + self.port + "/" + self.path);
self._prepareHandlers();
};
DDPClient.prototype.close = function() {

@@ -277,2 +283,3 @@ var self = this;

// call a method on the server,

@@ -289,7 +296,13 @@ //

if (updatedCallback)
self._updatedCallbacks[id] = updatedCallback;
self._updatedCallbacks[id] = updatedCallback;
self._send({msg: 'method', id: id, method: name, params: params});
self._send({
msg : "method",
id : id,
method : name,
params : params
});
};
DDPClient.prototype.callWithRandomSeed = function(name, params, randomSeed, callback, updatedCallback) {

@@ -303,5 +316,11 @@ var self = this;

if (updatedCallback)
self._updatedCallbacks[id] = updatedCallback;
self._updatedCallbacks[id] = updatedCallback;
self._send({msg: 'method', id: id, method: name, randomSeed: randomSeed, params: params});
self._send({
msg : "method",
id : id,
method : name,
randomSeed : randomSeed,
params : params
});
};

@@ -317,3 +336,8 @@

self._send({msg: 'sub', id: id, name: name, params: params});
self._send({
msg : "sub",
id : id,
name : name,
params : params
});

@@ -326,5 +350,8 @@ return id;

self._send({msg: 'unsub', id: id});
self._send({
msg : "unsub",
id : id
});
};
module.exports = DDPClient;
{
"name": "ddp",
"version": "0.7.0",
"version": "0.8.0",
"description": "Node.js module to connect to servers using DDP protocol.",

@@ -5,0 +5,0 @@ "author": "Tom Coleman <tom@thesnail.org> (http://tom.thesnail.org)",

@@ -34,2 +34,3 @@ var assert = require('assert'),

});
it('should connect to the provided host', function() {

@@ -39,2 +40,3 @@ new DDPClient({'host': 'myserver.com'}).connect();

});
it('should connect to the provided host and port', function() {

@@ -44,2 +46,3 @@ new DDPClient({'host': 'myserver.com', 'port': 42}).connect();

});
it('should use ssl if the port is 443', function() {

@@ -57,7 +60,7 @@ new DDPClient({'host': 'myserver.com', 'port': 443}).connect();

/* We should be able to get this test to work with clock.tick() but for some weird
/* We should be able to get this test to work with clock.tick() but for some weird
reasons it does not work. See: https://github.com/cjohansen/Sinon.JS/issues/283
*/
it('should reconnect when the connection fails', function(done) {
var ddpclient = new DDPClient({ auto_reconnect_timer: 10 });
var ddpclient = new DDPClient({ autoReconnectTimer: 10 });

@@ -78,3 +81,3 @@ ddpclient.connect();

it('should reconnect only once when the connection fails rapidly', function(done) {
var ddpclient = new DDPClient({ auto_reconnect_timer: 5 });
var ddpclient = new DDPClient({ autoReconnectTimer: 5 });

@@ -152,4 +155,4 @@ ddpclient.connect();

it('should maintain collections if maintain_collections is true', function() {
var ddpclient = new DDPClient({ maintain_collections : true });
it('should maintain collections if maintainCollections is true', function() {
var ddpclient = new DDPClient({ maintainCollections : true });
ddpclient._message(addedMessage);

@@ -160,4 +163,4 @@ // ensure collections exist and are populated by add messages

it('should not maintain collections if maintain_collections is false', function() {
var ddpclient = new DDPClient({ maintain_collections : false });
it('should not maintain collections if maintainCollections is false', function() {
var ddpclient = new DDPClient({ maintainCollections : false });
ddpclient._message(addedMessage);

@@ -164,0 +167,0 @@ // ensure there are no collections

Sorry, the diff of this file is not supported yet

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