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 - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

3

CHANGELOG.md

@@ -0,1 +1,4 @@

0.3.4 - 2013-08-28
- added EJSON support (default is off) with a couple tests
0.3.3 - 2013-05-29

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

20

examples/example.js
var DDPClient = require("../lib/ddp-client");
var ddpclient = new DDPClient({
host: "localhost",
port: 3000,
/* optional: */
auto_reconnect: true,
auto_reconnect_timer: 500
});
host: "localhost",
port: 3000,
/* optional: */
auto_reconnect: true,
auto_reconnect_timer: 500,
use_ejson: true // default is false
});
ddpclient.connect(function(error) {
console.log('connected!');
if (error) {

@@ -33,3 +34,3 @@ console.log('DDP connection error!');

ddpclient.on('message', function(msg) {
console.log("ddp message: " + msg);
console.log("ddp message: " + msg);
});

@@ -45,4 +46,5 @@

});
ddpclient.on('socket-error', function(error) {
console.log("Error: %j", error);
});
});
var WebSocket = require('ws'),
_ = require('underscore'),
util = require('util'),
events = require('events');
events = require('events'),
EJSON = require('meteor-ejson');

@@ -18,2 +19,5 @@ DDPClient = function(opts) {

// add support for EJSON, off by default to avoid breaking change
self.use_ejson = opts.use_ejson || false;
// very very simple collections (name -> [{id -> document}])

@@ -44,3 +48,3 @@ self.collections = {};

// if reconnecting, try existing DDP session
// removed for now, per conversatino with sixolet on IRC,
// removed for now, per conversation with sixolet on IRC,
// reconnect on server side still needs work

@@ -77,3 +81,3 @@

}
}
};

@@ -83,6 +87,15 @@ ///////////////////////////////////////////////////////////////////////////

DDPClient.prototype._send = function(data) {
this.socket.send(JSON.stringify(data), function(error) {
var self = this;
if (self.use_ejson) {
data = EJSON.stringify(data);
} else {
data = JSON.stringify(data);
}
this.socket.send(data, function(error) {
// This callback to avoid an exception being thrown.
// if an error happened, the socket will throw an event and we will recover.
});
};

@@ -94,4 +107,7 @@

// TODO: EJSON parsing
var data = JSON.parse(data);
if (self.use_ejson) {
data = EJSON.parse(data);
} else {
data = JSON.parse(data);
}

@@ -105,6 +121,6 @@ // TODO: 'error'

return;
} else if (data.msg === 'failed') {
self.emit('failed', data);
} else if (data.msg === 'connected') {

@@ -218,6 +234,6 @@ self.session = data.session;

self._connectionFailed = true;
connected(error)
connected(error);
});
}
// websocket

@@ -224,0 +240,0 @@ var protocol = self.use_ssl ? 'wss://' : 'ws://';

{
"name": "ddp",
"version": "0.3.3",
"description": "Node.js module to connect to servers using DDP protocol.",
"author": "Tom Coleman <tom@thesnail.org> (http://tom.thesnail.org), Mike Bannister <notimpossiblemike@gmail.com> (http://po.ssibiliti.es)",
"main": "lib/ddp-client",
"keywords": ["ddp", "meteor", "protocol"],
"repository" : {
"type": "git",
"url": "https://github.com/oortcloud/node-ddp-client.git"
},
"dependencies": {
"ws": ">=0.4.23",
"underscore": ">=1.3.3"
},
"devDependencies": {
"mocha": "1.9.x",
"sinon": "1.7.x",
"rewire": "1.1.x"
},
"scripts": {
"test": "./node_modules/mocha/bin/mocha test"
},
"engines": { "node": "*" }
}
"name": "ddp",
"version": "0.3.4",
"description": "Node.js module to connect to servers using DDP protocol.",
"author": "Tom Coleman <tom@thesnail.org> (http://tom.thesnail.org)",
"contributors": [
"Thomas Sarlandie <thomas@sarlandie.net> (http://www.sarfata.org)",
"Mason Gravitt <emgee@gravitronic.com>",
"Mike Bannister <notimpossiblemike@gmail.com> (http://po.ssibiliti.es)",
"Chris Mather <mather.chris@gmail.com> (http://eventedmind.com)"
],
"main": "lib/ddp-client",
"keywords": [
"ddp",
"meteor",
"protocol"
],
"repository": {
"type": "git",
"url": "https://github.com/oortcloud/node-ddp-client.git"
},
"dependencies": {
"ws": ">=0.4.23",
"underscore": ">=1.3.3",
"meteor-ejson": ">=0.6.3"
},
"devDependencies": {
"mocha": "1.9.x",
"sinon": "1.7.x",
"rewire": "1.1.x",
"meteor-ejson": ">=0.6.3"
},
"scripts": {
"test": "./node_modules/mocha/bin/mocha test"
},
"engines": {
"node": "*"
},
"bugs": "https://github.com/oortcloud/node-ddp-client/issues"
}
var assert = require('assert'),
sinon = require('sinon'),
sinon = require('sinon'),
rewire = require('rewire'),
events = require('events');
events = require('events'),
EJSON = require('meteor-ejson');

@@ -29,3 +30,3 @@ var DDPClient = rewire("../lib/ddp-client");

assert(wsConstructor.calledWithNew());
assert(wsConstructor.call)
assert(wsConstructor.call);
assert.deepEqual(wsConstructor.args, [['ws://localhost:3000/websocket']]);

@@ -76,3 +77,3 @@ });

prepareMocks();
})
});

@@ -111,1 +112,76 @@ // For some weird reasons (hard to reproduce) it happens that we try to send a message and

});
describe('EJSON', function() {
var DDPMessage = '{"msg":"added","collection":"posts","id":"2trpvcQ4pn32ZYXco","fields":{"date":{"$date":1371591394454},"bindata":{"$binary":"QUJDRA=="}}}';
var EJSONObject = EJSON.parse(DDPMessage);
it('should not be enabled by default', function(done) {
var ddpclient = new DDPClient();
assert(!ddpclient.use_ejson);
done();
});
it('should not be used when disabled', function(done) {
var ddpclient = new DDPClient({ use_ejson : false });
assert(!ddpclient.use_ejson);
ddpclient._message(DDPMessage);
// ensure received dates not decoded from EJSON
assert.deepEqual(ddpclient.collections.posts['2trpvcQ4pn32ZYXco'].date, {"$date":1371591394454});
// ensure received binary data not decoded from EJSON date
assert.deepEqual(ddpclient.collections.posts['2trpvcQ4pn32ZYXco'].bindata, {"$binary":"QUJDRA=="});
ddpclient.socket = {};
ddpclient.socket.send = function (opts) {
// ensure sent dates not encoded into EJSON
assert(opts.indexOf("date") !== -1);
assert(opts.indexOf("$date") === -1);
assert(opts.indexOf("1371591394454") === -1);
// ensure sent binary data not encoded into EJSON
assert(opts.indexOf("bindata") !== -1);
assert(opts.indexOf("$binary") === -1);
assert(opts.indexOf("QUJDRA==") === -1);
};
ddpclient._send(EJSONObject.fields);
done();
});
it('should be used if specifically enabled', function(done) {
var ddpclient = new DDPClient({ use_ejson : true });
assert(ddpclient.use_ejson);
ddpclient._message(DDPMessage);
assert.deepEqual(ddpclient.collections.posts['2trpvcQ4pn32ZYXco'].date, new Date(1371591394454));
assert.deepEqual(ddpclient.collections.posts['2trpvcQ4pn32ZYXco'].bindata, new Uint8Array([65, 66, 67, 68]));
ddpclient.socket = {};
ddpclient.socket.send = function (opts) {
assert(opts.indexOf("date") !== -1);
assert(opts.indexOf("$date") !== -1);
assert(opts.indexOf("1371591394454") !== -1);
assert(opts.indexOf("bindata") !== -1);
assert(opts.indexOf("$binary") !== -1);
assert(opts.indexOf("QUJDRA==") !== -1);
};
ddpclient._send(EJSONObject.fields);
done();
});
});

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