1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1 KiB

var sys = require("sys"),
xmpp = require("node-xmpp"),
colors = require("colors"),
events = require("events");
var NS_MUC = "http://jabber.org/protocol/muc";
14 years ago
var Room = function(client, name, callback) {
events.EventEmitter.call(this);
this._isReady = false;
this.client = client;
this.room = name;
this.to = this.room + "/" + this.client.params.nickname;
14 years ago
var room = this;
this.addListener("presence", function(from, stanza) {
14 years ago
var jfrom = new xmpp.JID(from);
if(name == jfrom.user + "@" + jfrom.domain) {
var x = stanza.getChild("x", NS_MUC + "#user");
14 years ago
if(x != null) {
var item = x.getChild("item");
14 years ago
if(item != null) {
room.affiliation = item.attrs.affiliation;
room.role = item.attrs.role;
}
var status = x.getChild("status");
14 years ago
if(! room._isReady) {
room._isReady = true;
callback.call(room, (status != null) ? status.attrs.code : "200");
14 years ago
}
}
}
});
this.presence("dnd", "Loading...");
this.client.emit("muc:binded");
14 years ago
};
sys.inherits(Room, events.EventEmitter);
exports.Room = Room;
Room.prototype.getPresences = function()
{
return this.client.presences.muc;
};
Room.prototype.presence = function(status, message)
{
if (typeof status === "undefined")
{
var status = "";
}
if (typeof message === "undefined")
{
var message = "";
}
this.client.xmpp.send(new xmpp.Element("presence", {
14 years ago
to: this.to
})
.c("priority").t("5").up()
.c("show").t(status).up()
.c("status").t(message).up()
.c("x", {xmlns: NS_MUC})
.tree()
);
};
Room.prototype.changenick = function(newnick)
{
this.client.params.nickname = newnick;
this.client.unidle();
this.client.xmpp.send(new xmpp.Element("presence", {
to: this.to.split("/")[0]+"/"+this.client.params.nickname
})
.c("x", {xmlns: NS_MUC})
14 years ago
.tree()
);
};
Room.prototype.message = function(message) {
this.client.unidle();
this.client.xmpp.send(new xmpp.Element("message", {
14 years ago
to: this.room,
type: "groupchat",
14 years ago
id: this.client._iq++
})
// .c("nick", {xmlns: "http://jabber.org/protocol/nick"}).t(this.client.jid.username).up()
.c("body").t(message).up()
14 years ago
.tree()
);
};