Permalink
Browse files

move channel sends to where they belong

  • Loading branch information...
1 parent 6c4521a commit cd36c5d864cbeb621eb8a19ccb8a6429fd89c313 @aredridel committed Nov 11, 2010
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/xmpp-muc.js
View
@@ -8,11 +8,12 @@ try {
}
-function Channel(jid) {
+function Channel(jid, router) {
events.EventEmitter.call(this)
this.users = {}
this.jid = jid
this.by_jid = {}
+ this.router = router
}
util.inherits(Channel, events.EventEmitter)
@@ -21,13 +22,21 @@ Channel.prototype.toString = function() {
return "<xmpp:muc name='"+this.jid+"'/>"
}
+Channel.prototype.send = function send(stanza) {
+ for(var k in this.users) {
+ stanza.attrs.to = this.users[k]
+ console.log("XMPP> "+stanza.toString())
+ this.router.send(stanza)
+ }
+}
+
var MUC = function(router) {
var Channels = {}
var muc = this
this.getChannel = function(jid) {
if(!Channels[jid]) {
- Channels[jid] = new Channel(jid);
+ Channels[jid] = new Channel(jid, router);
muc.emit('channel', Channels[jid])
}
return Channels[jid]
@@ -65,11 +74,7 @@ var MUC = function(router) {
}
stanza.attrs.from = to.user + '@' + to.domain +'/'+(channel.by_jid[stanza.attrs.from]);
- for(var k in channel.users) {
- stanza.attrs.to = channel.users[k]
- console.log("XMPP> "+stanza.toString());
- router.send(stanza);
- }
+ channel.send(stanza)
if(stanza.attrs.type =='unavailable') {
// Clear presence

0 comments on commit cd36c5d

Please sign in to comment.