Skip to content

Commit e300eab

Browse files
committed
Merge commit '5fa04d8877d1f37e3ee20b0dac9a12389b935e23' into expose-ejson
Conflicts: README.markdown
2 parents 2a857d7 + 5fa04d8 commit e300eab

File tree

5 files changed

+50
-45
lines changed

5 files changed

+50
-45
lines changed

README.markdown

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ var ddpclient = new DDPClient({
2828
/* optional: */
2929
auto_reconnect: true,
3030
auto_reconnect_timer: 500,
31-
use_ejson: true, // default is false
32-
use_ssl: false, //connect to SSL server,
33-
use_ssl_strict: true, //Set to false if you have root ca trouble.
34-
maintain_collections: true //Set to false to maintain your own collections.
31+
use_ejson: true, // Use Meteor's EJSON to preserve certain data types.
32+
use_ssl: false,
33+
maintain_collections: true // Set to false to maintain your own collections.
3534
});
3635

3736
ddpclient.connect(function(error) {
@@ -42,31 +41,31 @@ ddpclient.connect(function(error) {
4241

4342
console.log('connected!');
4443

45-
ddpclient.loginWithUsername("myusername","ddp-rocks",function(err, result) {
46-
//Do stuff after login
47-
});
44+
ddpclient.loginWithUsername("username", "password", function (err, result) {
45+
// result contains your auth token
4846

49-
ddpclient.call('test-function', ['foo', 'bar'], function(err, result) {
50-
console.log('called function, result: ' + result);
51-
})
47+
ddpclient.call('test-function', ['foo', 'bar'], function (err, result) {
48+
console.log('called function, result: ' + result);
49+
});
5250

53-
ddpclient.subscribe('posts', [], function() {
54-
console.log('posts complete:');
55-
console.log(ddpclient.collections.posts);
56-
})
51+
ddpclient.subscribe('posts', [], function () {
52+
console.log('posts complete:');
53+
console.log(ddpclient.collections.posts);
54+
});
55+
});
5756
});
5857

5958
/*
6059
* Useful for debugging and learning the ddp protocol
6160
*/
62-
ddpclient.on('message', function(msg) {
61+
ddpclient.on('message', function (msg) {
6362
console.log("ddp message: " + msg);
6463
});
6564

6665
/*
6766
* If you need to do something specific on close or errors.
68-
* (You can also disable auto_reconnect and call ddpclient.connect()
69-
* when you are ready to re-connect.)
67+
* You can also disable auto_reconnect and
68+
* call ddpclient.connect() when you are ready to re-connect.
7069
*/
7170
ddpclient.on('socket-close', function(code, message) {
7271
console.log("Close: %s %s", code, message);
@@ -86,14 +85,15 @@ var oid = new ddpclient.EJSON.ObjectID();
8685

8786
Unimplemented Features
8887
====
88+
The node DDP client does not implement ordered collections, something that while in the DDP spec has not been implemented in Meteor yet.
89+
8990
* Server to Client messages
9091
* 'addedBefore'
9192
* 'movedBefore'
9293
* 'error'
9394
* 'updated'
9495

9596

96-
9797
Thanks
9898
======
9999

examples/example.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
var DDPClient = require("../lib/ddp-client");
22

33
var ddpclient = new DDPClient({
4-
host: "localhost",
4+
host: "localhost",
55
port: 3000,
66
/* optional: */
77
auto_reconnect: true,
88
auto_reconnect_timer: 500,
9-
use_ejson: true // default is false
9+
use_ejson: true, // Use Meteor's EJSON to preserve certain data types.
10+
use_ssl: false,
11+
maintain_collections: true // Set to false to maintain your own collections.
1012
});
1113

1214
ddpclient.connect(function(error) {
13-
console.log('connected!');
14-
1515
if (error) {
1616
console.log('DDP connection error!');
1717
return;
1818
}
1919

20-
ddpclient.call('test-function', ['foo', 'bar'], function(err, result) {
21-
console.log('called function, result: ' + result);
22-
});
20+
console.log('connected!');
21+
22+
ddpclient.loginWithUsername("username", "password", function (err, result) {
23+
// result contains your auth token
24+
25+
ddpclient.call('test-function', ['foo', 'bar'], function (err, result) {
26+
console.log('called function, result: ' + result);
27+
});
2328

24-
ddpclient.subscribe('posts', [], function() {
25-
console.log('posts complete:');
26-
console.log(ddpclient.collections.posts);
29+
ddpclient.subscribe('posts', [], function () {
30+
console.log('posts complete:');
31+
console.log(ddpclient.collections.posts);
32+
});
2733
});
2834
});
2935

3036
/*
3137
* Useful for debugging and learning the ddp protocol
3238
*/
33-
ddpclient.on('message', function(msg) {
39+
ddpclient.on('message', function (msg) {
3440
console.log("ddp message: " + msg);
3541
});
3642

lib/ddp-client.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ var WebSocket = require('faye-websocket'),
22
_ = require('underscore'),
33
util = require('util'),
44
events = require('events'),
5-
EJSON = require('meteor-ejson'),
6-
SRP = require('node-srp'),
5+
EJSON = require('ddp-ejson'),
6+
SRP = require('ddp-srp'),
7+
Random = require('ddp-random'),
78

89
DDPClient = function(opts) {
910
var self = this;
@@ -86,7 +87,7 @@ DDPClient.prototype._clearReconnectTimeout = function() {
8687
clearTimeout(self.reconnectTimeout);
8788
self.reconnectTimeout = null;
8889
}
89-
}
90+
};
9091

9192
DDPClient.prototype._recoverNetworkError = function() {
9293
var self = this;
@@ -251,9 +252,6 @@ DDPClient.prototype.connect = function(connected) {
251252

252253
// websocket
253254
var protocol = self.use_ssl ? 'wss://' : 'ws://';
254-
//XXX: These aren't in faye-websocket. Are they still needed?
255-
//var options = self.use_ssl ? {rejectUnauthorized: self.use_ssl_strict} : {};
256-
//self.socket = new WebSocket.Client(protocol + self.host + ':' + self.port + '/' + self.path, options);
257255
self.socket = new WebSocket.Client(protocol + self.host + ':' + self.port + '/' + self.path);
258256
self._prepareHandlers();
259257
};
@@ -285,25 +283,25 @@ DDPClient.prototype._login = function(loginParams, password, callback) {
285283
if (conf) {
286284
callback(null, result);
287285
} else {
288-
callback({error:"The HAMK doesn't match. Possible MITM attack"});
286+
callback({ error : "The HAMK doesn't match. Possible MITM attack" });
289287
}
290288

291289
});
292290
});
293-
}
291+
};
294292

295293
DDPClient.prototype.loginWithEmail = function(email, password, callback) {
296294
this._login({email: email}, password, callback);
297-
}
295+
};
298296

299297
DDPClient.prototype.loginWithUsername = function(username, password, callback) {
300298
this._login({username: username}, password, callback);
301-
}
299+
};
302300

303301
DDPClient.prototype.loginWithToken = function(token, callback) {
304302
var self = this;
305303
self.call("login", [{resume: token}], callback);
306-
}
304+
};
307305

308306
DDPClient.prototype.close = function() {
309307
var self = this;

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ddp",
3-
"version": "0.4.6",
3+
"version": "0.4.7",
44
"description": "Node.js module to connect to servers using DDP protocol.",
55
"author": "Tom Coleman <[email protected]> (http://tom.thesnail.org)",
66
"contributors": [
@@ -21,9 +21,10 @@
2121
"url": "https://github.com/oortcloud/node-ddp-client.git"
2222
},
2323
"dependencies": {
24-
"underscore": ">=1.3.3",
25-
"meteor-ejson": ">=0.6.3",
26-
"node-srp": ">=0.0.1",
24+
"underscore": "1.5.2",
25+
"ddp-ejson": "0.8.1-2",
26+
"ddp-srp": "0.8.1-1",
27+
"ddp-random": "0.8.1-1",
2728
"faye-websocket": "~0.7.1"
2829
},
2930
"devDependencies": {

test/ddp-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var assert = require('assert'),
22
sinon = require('sinon'),
33
rewire = require('rewire'),
44
events = require('events'),
5-
EJSON = require('meteor-ejson');
5+
EJSON = require('ddp-ejson');
66

77
var DDPClient = rewire("../lib/ddp-client");
88

0 commit comments

Comments
 (0)