Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

move channel sends to where they belong

  • Loading branch information...
commit cd36c5d864cbeb621eb8a19ccb8a6429fd89c313 1 parent 6c4521a
Aria Stewart authored

Showing 1 changed file with 12 additions and 7 deletions. Show diff stats Hide diff stats

  1. +12 7 lib/xmpp-muc.js
19 lib/xmpp-muc.js
@@ -8,11 +8,12 @@ try {
8 8 }
9 9
10 10
11   -function Channel(jid) {
  11 +function Channel(jid, router) {
12 12 events.EventEmitter.call(this)
13 13 this.users = {}
14 14 this.jid = jid
15 15 this.by_jid = {}
  16 + this.router = router
16 17 }
17 18
18 19 util.inherits(Channel, events.EventEmitter)
@@ -21,13 +22,21 @@ Channel.prototype.toString = function() {
21 22 return "<xmpp:muc name='"+this.jid+"'/>"
22 23 }
23 24
  25 +Channel.prototype.send = function send(stanza) {
  26 + for(var k in this.users) {
  27 + stanza.attrs.to = this.users[k]
  28 + console.log("XMPP> "+stanza.toString())
  29 + this.router.send(stanza)
  30 + }
  31 +}
  32 +
24 33 var MUC = function(router) {
25 34 var Channels = {}
26 35 var muc = this
27 36
28 37 this.getChannel = function(jid) {
29 38 if(!Channels[jid]) {
30   - Channels[jid] = new Channel(jid);
  39 + Channels[jid] = new Channel(jid, router);
31 40 muc.emit('channel', Channels[jid])
32 41 }
33 42 return Channels[jid]
@@ -65,11 +74,7 @@ var MUC = function(router) {
65 74 }
66 75
67 76 stanza.attrs.from = to.user + '@' + to.domain +'/'+(channel.by_jid[stanza.attrs.from]);
68   - for(var k in channel.users) {
69   - stanza.attrs.to = channel.users[k]
70   - console.log("XMPP> "+stanza.toString());
71   - router.send(stanza);
72   - }
  77 + channel.send(stanza)
73 78
74 79 if(stanza.attrs.type =='unavailable') {
75 80 // Clear presence

0 comments on commit cd36c5d

Please sign in to comment.
Something went wrong with that request. Please try again.