Comparing version 0.1.1 to 0.2.0
41
index.js
@@ -48,10 +48,16 @@ var EventEmitter, NET, Stream, | ||
this.connections = []; | ||
this.channels = []; | ||
server = this; | ||
this.tcpServer = NET.createServer(aSpec, function(connection) { | ||
var parser; | ||
var channel, parser, _i, _len, _ref; | ||
server.connections.push(connection); | ||
parser = new exports.IncomingConnection({ | ||
server: server | ||
emitter: server | ||
}); | ||
connection.pipe(parser); | ||
_ref = server.channels; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
channel = _ref[_i]; | ||
channel.pipe(connection); | ||
} | ||
}); | ||
@@ -73,2 +79,16 @@ this.tcpServer.on('error', function(err) { | ||
Server.prototype.createChannel = function(aName) { | ||
var channel, connection, _i, _len, _ref; | ||
channel = new exports.Channel({ | ||
name: aName | ||
}); | ||
_ref = this.connections; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
connection = _ref[_i]; | ||
channel.pipe(connection); | ||
} | ||
this.channels.push(channel); | ||
return channel; | ||
}; | ||
Server.prototype.address = function() { | ||
@@ -99,3 +119,3 @@ return this.tcpServer.address(); | ||
function IncomingConnection(aSpec) { | ||
this.server = aSpec.server; | ||
this.emitter = aSpec.emitter; | ||
this.writable = true; | ||
@@ -106,5 +126,5 @@ this.buffer = ''; | ||
IncomingConnection.prototype.flush = function(aChannel, aMessage) { | ||
this.server.emit(aChannel, aMessage); | ||
if (typeof this.server.listener === 'function') { | ||
this.server.listener(aChannel, aMessage); | ||
this.emitter.emit(aChannel, aMessage); | ||
if (typeof this.emitter.listener === 'function') { | ||
this.emitter.listener(aChannel, aMessage); | ||
} | ||
@@ -148,4 +168,9 @@ }; | ||
function Connection(args) { | ||
var _this = this; | ||
var parser, | ||
_this = this; | ||
this.tcpConnection = NET.connect.apply(NET, args); | ||
parser = new exports.IncomingConnection({ | ||
emitter: this | ||
}); | ||
this.tcpConnection.pipe(parser); | ||
this.tcpConnection.on('close', function() { | ||
@@ -173,2 +198,4 @@ return _this.emit('close'); | ||
exports.Connection.prototype.subscribe = exports.Connection.prototype.addListener; | ||
exports.Channel = (function(_super) { | ||
@@ -175,0 +202,0 @@ |
{ | ||
"name": "telegram", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Publish Subscribe (pubsub) over TCP" | ||
} |
8682
221