Comparing version 1.0.0 to 1.0.1
@@ -73,2 +73,8 @@ var util = require('util') | ||
} | ||
Channel.prototype._close = function() { | ||
if (this.cursor) { | ||
this.cursor.close(); | ||
this.cursor = null; | ||
} | ||
} | ||
@@ -78,13 +84,20 @@ Channel.prototype.send = function(type, data) { | ||
return self.collection.then(function(collection) { | ||
var data = { | ||
ts: new Date(), | ||
channel: self.name, | ||
from: self.client.id, | ||
type: type, | ||
data: data | ||
}; | ||
return q.ninvoke(collection, 'insert', data); | ||
return Channel.send(collection, self.client.id, self.name, type, data); | ||
}); | ||
} | ||
Channel.prototype.leave = function() { | ||
self.client.leave(this); | ||
} | ||
Channel.send = function(collection, client, channel, type, data) { | ||
var data = { | ||
ts: new Date(), | ||
channel: channel, | ||
from: client, | ||
type: type, | ||
data: data | ||
}; | ||
return q.ninvoke(collection, 'insert', data); | ||
} | ||
module.exports = Channel; |
@@ -14,3 +14,3 @@ var q = require('q') | ||
} | ||
Client.prototype.channel = function(name, lastMessage) { | ||
Client.prototype.channel = Client.prototype.join = function(name, lastMessage) { | ||
if (this.channels[name]) { | ||
@@ -21,5 +21,17 @@ return this.channels[name]; | ||
this.channels[name] = channel; | ||
this.db.collection('clients').update({ _id: this.id }, { $set: { "channels." + channel.name: new Date() }}); | ||
return channel; | ||
} | ||
} | ||
Client.prototype.leave = function(channel) { | ||
this.db.collection('clients').update({ _id: this.id }, { $unset: { "channels." + channel.name: true }}); | ||
channel._close(); | ||
delete this.channels[name]; | ||
} | ||
Client.prototype.send = function(channel, type, data) { | ||
return exports.send(this.db, this.namespace, this.id, channel, type, data); | ||
} | ||
Client.prototype.sendns = function(namespace, channel, type, data) { | ||
return exports.send(this.db, namespace, this.id, channel, type, data); | ||
} | ||
@@ -54,1 +66,5 @@ var clients = {}; | ||
} | ||
exports.send = function(db, namespace, client, channel, type, data) { | ||
return Channel.send(db.collection('ns_' + namespace), client, channel, type, data); | ||
} | ||
{ | ||
"name": "vubsub", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Pub/Sub for Node.js and MongoDB", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/vivocha/vubsub", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8944
160