Skip to content

Commit 3a523b2

Browse files
committed
change code styling and update README
1 parent 89996e4 commit 3a523b2

File tree

7 files changed

+103
-8
lines changed

7 files changed

+103
-8
lines changed

README.markdown

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ var ddpclient = new DDPClient({
4545
// All properties optional, defaults shown
4646
host : "localhost",
4747
port : 3000,
48-
path : "websocket",
4948
ssl : false,
5049
autoReconnect : true,
5150
autoReconnectTimer : 500,
5251
maintainCollections : true,
53-
ddpVersion : '1' // ['1', 'pre2', 'pre1'] available
52+
ddpVersion : '1', // ['1', 'pre2', 'pre1'] available
53+
// uses the SockJs protocol to create the connection
54+
// this still uses websockets, but allows to get the benefits
55+
// from projects like meteorhacks:cluster
56+
// (for load balancing and service discovery)
57+
// do not use `path` option when you are using useSockJs
58+
useSockJs: true
5459
});
5560

5661
/*
@@ -173,6 +178,22 @@ ddpclient.on('socket-error', function(error) {
173178
var oid = new ddpclient.EJSON.ObjectID();
174179
```
175180

181+
SockJS Mode
182+
===============
183+
184+
By using the `useSockJs` option like below, DDP connection will use [SockJs](https://github.com/sockjs) protocol to establish the WebSocket connection.
185+
186+
```js
187+
var ddpClient = new DDPClient({ useSockJs: true });
188+
```
189+
190+
Meteor server uses SockJs to implement it's DDP server. With this mode, we can get the benefits provided by [meteorhacks:cluster](https://github.com/meteorhacks/cluster). Some of those are load balancing and service discovery.
191+
192+
* For load balancing you don't need to anything.
193+
* For service discovery, just use the `path` option to identify the service you are referring to.
194+
195+
> With this mode, `path` option has a special meaning. So, thing twice before using `path` option when you are using this option.
196+
176197
Unimplemented Features
177198
====
178199
The node DDP client does not implement ordered collections, something that while in the DDP spec has not been implemented in Meteor yet.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file contains information which helps Meteor properly upgrade your
2+
# app when you run 'meteor update'. You should check it into version control
3+
# with your project.
4+
5+
notices-for-0.9.0
6+
notices-for-0.9.1
7+
0.9.4-platform-file
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file contains a token that is unique to your project.
2+
# Check it into your repository along with the rest of this directory.
3+
# It can be used for purposes such as:
4+
# - ensuring you don't accidentally deploy one app on top of another
5+
# - providing package authors with aggregated statistics
6+
7+
16h678x1r5dkr01i9xj33
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server
2+
browser

examples/example.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ var ddpclient = new DDPClient({
66
// All properties optional, defaults shown
77
host : "localhost",
88
port : 3000,
9-
path : "websocket",
109
ssl : false,
1110
autoReconnect : true,
1211
autoReconnectTimer : 500,
1312
maintainCollections : true,
14-
ddpVersion : "1" // ["1", "pre2", "pre1"] available
13+
ddpVersion : "1", // ["1", "pre2", "pre1"] available,
14+
// uses the sockJs protocol to create the connection
15+
// this still uses websockets, but allows to get the benefits
16+
// from projects like meteorhacks:cluster
17+
// (load balancing and service discovery)
18+
// do not use `path` option when you are using useSockJs
19+
useSockJs: true
1520
});
1621

1722
/*

lib/ddp-client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ DDPClient.prototype.connect = function(connected) {
312312
});
313313
}
314314

315-
if(self.useSockJs) {
315+
if (self.useSockJs) {
316316
self._makeSockJSConnection();
317317
} else {
318318
var url = self._buildWsUrl();
@@ -330,15 +330,15 @@ DDPClient.prototype._makeSockJSConnection = function() {
330330
var url = protocol + self.host + ":" + self.port + path;
331331

332332
request.get(url, function(err, res, body) {
333-
if(err) {
333+
if (err) {
334334
self._recoverNetworkError();
335-
} else if(body) {
335+
} else if (body) {
336336
var info = JSON.parse(body);
337337
if(!info.base_url) {
338338
// no base_url, then use pure WS handling
339339
var url = self._buildWsUrl();
340340
self._makeWebSocketConnection(url);
341-
} else if(info.base_url.indexOf("http") === 0) {
341+
} else if (info.base_url.indexOf("http") === 0) {
342342
// base url for a different host
343343
var url = info.base_url + "/websocket";
344344
url = url.replace(/^http/, "ws");

0 commit comments

Comments
 (0)