Skip to content

Commit

Permalink
Merge branch 'release-0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Tavares committed May 10, 2013
2 parents 2d1e43f + 4a95bce commit be8009b
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 113 deletions.
27 changes: 27 additions & 0 deletions .jshintrc
@@ -0,0 +1,27 @@
{
"bitwise": true,
"camelcase": true,
"curly": false,
"eqeqeq": false,
"forin": true,
"immed": true,
"indent": 2,
"latedef": true,
"maxparams": false,
"maxdepth": false,
"maxstatements": false,
"maxcomplexity": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"regexp": true,
"sub": true,
"strict": false,
"trailing": true,
"undef": true,
"unused": true
}
9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
language: node_js
node_js:
- "0.10"
- "0.8"
- "0.6"
matrix:
allow_failures:
- node_js: "0.10"

11 changes: 9 additions & 2 deletions README.md
@@ -1,17 +1,24 @@
# socket.io-servicebus - socket.io store using Windows Azure Service Bus

[![Build Status](https://travis-ci.org/WindowsAzure/socket.io-servicebus.png?branch=dev)](https://travis-ci.org/WindowsAzure/socket.io-servicebus)

This project provides a Node.js package that lets you use Windows Azure Service Bus as a back-end communications
channel for socket.io applications.

# Library Features

* Service Bus Store
* Easily connect multiple socket.io server instances over Service Bus

# What's new in this release

## 0.0.3
Fixes to the presence system in the chat application. Not 100% there, but working much better
in the multi-server case.

## 0.0.2
Service Bus topics and subscriptions are now created automatically if they don't already exist. Subscriptions
are created with a five minute idle expiration time, so they won't stick around once the server is no longer
are created with a five minute idle expiration time, so they won't stick around once the server is no longer
polling them.

The cross-server presence indicators in the chat sample has been updated to properly handle the multi-server
Expand Down
13 changes: 11 additions & 2 deletions examples/chat/presence.js
Expand Up @@ -47,8 +47,17 @@ function initPresenceServer(io, port) {
}

function initPresenceClient(io, port) {
presence = cio.connect('http://localhost:' + port + '/presence');
presence.on('connect', function () {
var presenceUrl = process.env.PRESENCE_URL;

if (!presenceUrl) {
presenceUrl = 'http://localhost:' + port;
}

presenceUrl += '/presence';

log && log.info('Connecting to presence client', 'url:' + presenceUrl);

presence = cio.connect(presenceUrl); presence.on('connect', function () {
log && log.info('Connected to presence client');
});

Expand Down
16 changes: 9 additions & 7 deletions lib/messagebatcher.js
Expand Up @@ -15,10 +15,8 @@

'use strict';

var events = require('events')
, util = require('util');

module.exports = MessageBatcher;
var events = require('events');
var util = require('util');

var DEFAULT_FLUSH_INTERVAL_MS = 250;

Expand All @@ -33,6 +31,8 @@ function MessageBatcher(options, inner) {

util.inherits(MessageBatcher, events.EventEmitter);

module.exports = MessageBatcher;

MessageBatcher.prototype.start = function(callback) {
var self = this;
if (!this.started) {
Expand All @@ -41,7 +41,9 @@ MessageBatcher.prototype.start = function(callback) {
if (!err) {
self.started = true;
}
callback && callback(err);
if (callback) {
callback(err);
}
});
}
};
Expand All @@ -52,7 +54,7 @@ MessageBatcher.prototype.stop = function (cb) {
clearInterval(this.flushCancellationToken);
this.sb.stop(cb);
}
}
};

/*
* Send side of interface
Expand All @@ -76,7 +78,7 @@ MessageBatcher.prototype.flush = function() {
MessageBatcher.prototype.receiveMessage = function(nodeId, name, batch) {
for(var i = 0, len = batch.length; i < len; ++i) {
this.emit('message', nodeId, batch[i][0], batch[i][1]);
}
}
};

/*
Expand Down
16 changes: 8 additions & 8 deletions lib/messagesequencer.js
Expand Up @@ -15,10 +15,8 @@

'use strict';

var EventEmitter = require('events').EventEmitter
, util = require('util');

module.exports = MessageSequencer;
var EventEmitter = require('events').EventEmitter;
var util = require('util');

function MessageSequencer(options, inner) {
this.inner = inner;
Expand All @@ -31,18 +29,20 @@ function MessageSequencer(options, inner) {
}

util.inherits(MessageSequencer, EventEmitter);
module.exports = MessageSequencer;

MessageSequencer.prototype.start = function(callback) {
var self = this;
callback = callback || function () { };
if (!this.started) {
this.inner.start(function (err) {
if (!err) {
self.started = true;
}
callback && callback(err);
callback(err);
});
} else {
callback && callback();
callback();
}
};

Expand Down Expand Up @@ -80,8 +80,8 @@ MessageSequencer.prototype.processMessage = function(message) {
};

MessageSequencer.prototype.addPendingMessage = function(message) {
this.pendingMessages.push(message);
this.pendingMessages.sort(function (a, b) { return a[3] - b[3]; });
this.pendingMessages.push(message);
this.pendingMessages.sort(function (a, b) { return a[3] - b[3]; });
};

MessageSequencer.prototype.sendPendingMessages = function() {
Expand Down
47 changes: 23 additions & 24 deletions lib/sbclient.js
Expand Up @@ -14,23 +14,35 @@
*/
'use strict';

var io = require('socket.io')
, util = require('util');

module.exports = Client;
var io = require('socket.io');
var util = require('util');

function Client() {
io.Store.Client.apply(this, arguments);
this.data = {};
}

util.inherits(Client, io.Store.Client);
module.exports = Client;

// Helper function to invoke callbacks
// Invoke on next event loop turn in case
// we expand to storing this data off the box
// and need actual async.
function invoke(fn) {
if (fn) {
var args = Array.prototype.slice.call(arguments, 1);
process.nextTick(function() {
fn.apply(null, args);
});
}
}

/**
* Get data stored under a key
*
* @param {Object} key key to retrieve data for
* @param {function(err, value)} fn
* @param {function(err, value)} fn
* callback function that received the retrieved value
*
* @return {Client} this client object
Expand All @@ -39,7 +51,7 @@ Client.prototype.get = function (key, fn) {
var self = this;
invoke(fn, null, self.data[key] || null);
return this;
}
};

/**
* Store client data for a key
Expand All @@ -51,16 +63,15 @@ Client.prototype.get = function (key, fn) {
* @return {Client} this client object.
*/
Client.prototype.set = function (key, value, fn) {
var self = this;
this.data[key] = value;
invoke(fn, null);
return this;
}
};

/**
* Check if data for a key has been stored
*
* @param {Object} key
* @param {Object} key
* key to check for
*
* @param {function(err, hasKey)} fn
Expand All @@ -71,7 +82,7 @@ Client.prototype.set = function (key, value, fn) {
Client.prototype.has = function (key, fn) {
invoke(fn, null, key in this.data);
return this;
}
};

/**
* Delete data for a key
Expand All @@ -89,7 +100,7 @@ Client.prototype.del = function (key, fn) {
delete this.data[key];
invoke(fn, null);
return this;
}
};

/**
* Delete all data stored by this client
Expand All @@ -111,17 +122,5 @@ Client.prototype.destroy = function (expiration) {
}, expiration * 1000);
}
return this;
}
};

// Helper function to invoke callbacks
// Invoke on next event loop turn in case
// we expand to storing this data off the box
// and need actual async.
function invoke(fn) {
if (fn) {
var args = Array.prototype.slice.call(arguments, 1);
process.nextTick(function() {
fn.apply(null, args);
});
}
}

0 comments on commit be8009b

Please sign in to comment.