Skip to content

Commit

Permalink
updated package.json to include all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
prgsmall committed Jan 31, 2012
1 parent 9b5d529 commit 163c250
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lib/acequia.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function startServers() {

for (i = 0; i < oscMsgs.length; i += 1) {
oscMsg = oscMsgs[i];
logger.trace("OSC:" + oscMsg);

if (oscMsg.address.indexOf("/tuio") === 0) {
message = tuio.toAcequiaMessage(oscMsg);
} else {
message = new msg.AcequiaMessage("", oscMsg.address, oscMsg.data);
}

logger.debug(message.toString());
logger.trace(message.toString());

clients.onMessage(ac.TYP_OSC, message, oscServer, rinfo);
}
Expand All @@ -66,7 +66,7 @@ function startServers() {
logger.debug("OSC Server is listening on %j", oscServer.address());

// Broadcast the presence of this server
osc_ad = mdns.createAdvertisement(mdns.udp('acequia', 'osc'), OSC_PORT, {name:"Acequia OSC Server", port: OSC_PORT});
osc_ad = mdns.createAdvertisement(mdns.udp('acequia', 'osc'), OSC_PORT, {name: "Acequia OSC Server"});
osc_ad.start();
});

Expand All @@ -91,7 +91,7 @@ function startServers() {
res.end(out);
};

console.log("HTTP server received " + pathName);
console.log("HTTP server received " + req.url);

if (pathName === "/acequia/acequia.js") {
serveClientCode(clientCode.full);
Expand Down Expand Up @@ -177,7 +177,7 @@ function startServers() {
logger.debug("TCP Server is listening on %j", tcpServer.address());

// Broadcast the presence of this server
tcp_ad = mdns.createAdvertisement(mdns.tcp('acequia'), TCP_PORT, {name:"Acequia TCP Server", port: TCP_PORT});
tcp_ad = mdns.createAdvertisement(mdns.tcp('acequia'), TCP_PORT, {name: "Acequia TCP Server"});
tcp_ad.start();
});

Expand Down
16 changes: 13 additions & 3 deletions lib/acequiaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var AcequiaClient = function (uri, userName) {
this.setConnected = function (connected) {
var idx;
m_connected = connected;
for (idx in m_connectionChangeHandlers) {
for (idx = 0; idx < m_connectionChangeHandlers.length; idx += 1) {
m_connectionChangeHandlers[idx](connected);
}
};
Expand Down Expand Up @@ -76,6 +76,16 @@ AcequiaClient.prototype.addListener = function (msgName, callback) {
this.subscribes.push(msgName);
};

/**
* Adds a listener for the message with the message name.
* @param {String} msgName The name of the message to listen to.
* @param {Function} callback The callback function which will be called when the
* message arrives.
*/
AcequiaClient.prototype.on = function (msgName, callback) {
this.addListener(msgName, callback);
};

/**
* Adds a listener for the message with the message name.
* @param {String} msgName The name of the message to listen to.
Expand All @@ -93,7 +103,7 @@ AcequiaClient.prototype.removeListener = function (msgName, callback) {
AcequiaClient.prototype.connect = function () {
var onload = function (that) {
return function (evt) {
that.socket = io.connect(that.uri, {reconnect:false});
that.socket = io.connect(that.uri, {reconnect: false});
that.socket.on("connect", objCallback(that, "onConnect"));
};
};
Expand Down Expand Up @@ -188,7 +198,7 @@ AcequiaClient.prototype.onMessage = function (data) {
}

if (message.name in this.listeners) {
for (i in this.listeners[message.name]) {
for (i = 0; i < this.listeners[message.name].length; i += 1) {
this.listeners[message.name][i](message, this);
}
}
Expand Down
24 changes: 15 additions & 9 deletions lib/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var ac = require("./client"),
body: [
{
status: SUCCESS/FAIL
namespace: "a namespace value",
name: param name
}
]
Expand Down Expand Up @@ -61,22 +63,26 @@ var datastoreFile = path.join(process.cwd(), "datastore", "acequia.ds");

var acequiaClients = null;

var onWriteFile = function (err, to) {
var onWriteFile = function (err, inMessage) {
if (err) {
console.error("onWriteFile error %s", err);
}

// Send the response message
var message, response = {};
response.status = err ? "FAIL" : "SUCCESS";
message = new msg.AcequiaMessage("datastore", "setDataStoreValueResponse", response, to);
var response = {
namespace: inMessage.namespace,
name: inMessage.name,
status: err ? "FAIL" : "SUCCESS"
},

message = new msg.AcequiaMessage("datastore", "setDataStoreValueResponse", response, inMessage.to);

acequiaClients.sendTo(message);
};

var onSetDataStoreValue = function (message) {
var i, data, callback;
for (i in message.body) {
for (i = 0; i < message.body.length; i += 1) {
data = message.body[i];
if (!(data.namespace in datastore)) {
datastore[data.namespace] = {};
Expand All @@ -87,18 +93,18 @@ var onSetDataStoreValue = function (message) {

// Write the local datastore to the file system. Create a callback that will send
// a response when the datastore has been written.
callback = (function (to) {
callback = (function (inMessage) {
return function (err) {
onWriteFile(err, to);
onWriteFile(err, inMessage);
};
}(message.from));
}(message));

fs.writeFile(datastoreFile, JSON.stringify(datastore), "utf8", callback);
};

var onGetDataStoreValue = function (message) {
var i, data, body = [], response, reply;
for (i in message.body) {
for (i = 0; i < message.body.length; i += 1) {
data = message.body[i];
response = {};
response.name = data.name;
Expand Down
34 changes: 26 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
{
"name" : "Acequia"
,"description":"Message router for node.js supporting multiple protocols"
, "main": "index"
, "directories": {"lib": "./lib"}
, "engines":{"node":">=0.6.0-0"}
, "repository":{"type":"git","url":"https://prgsmall@github.com/prgsmall/acequia.git"}
, "scripts": { "start": "node ." }
, "version" : "0.1.0"
"name" : "acequia",
"version" : "0.1.0",
"description":"Message router for node supporting multiple protocols",
"author": "Peter R. G. Small",
"homepage": "https://github.com/prgsmall/acequia",
"preferGlobal": "true",
"main": "lib/acequia.js",
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">=0.6"
},
"repository": {
"type": "git",
"url": "https://prgsmall@github.com/prgsmall/acequia.git"
},
"scripts": {
"start": "node ."
},
"dependencies" : {
"log4js" : ">0.4.1",
"socket-io": ">0.8.7",
"uglify-js": ">1.2.5",
"mdns": "0.0.5-dev"
}
}

0 comments on commit 163c250

Please sign in to comment.