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.

91 lines
2.0 KiB

var sys = require("sys"),
xmpp = require("node-xmpp"),
colors = require("colors"),
events = require("events");
var NS_MUC = "http://jabber.org/protocol/muc";
15 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;
15 years ago
var room = this;
this.addListener("presence", function(from, stanza) {
15 years ago
var jfrom = new xmpp.JID(from);
if(name == jfrom.user + "@" + jfrom.domain) {
var x = stanza.getChild("x", NS_MUC + "#user");
15 years ago
if(x != null) {
var item = x.getChild("item");
15 years ago
if(item != null) {
room.affiliation = item.attrs.affiliation;
room.role = item.attrs.role;
}
var status = x.getChild("status");
15 years ago
if(! room._isReady) {
room._isReady = true;
callback.call(room, (status != null) ? status.attrs.code : "200");
15 years ago
}
}
}
});
this.presence("dnd", "Loading...");
this.client.emit("muc:binded");
15 years ago
};
sys.inherits(Room, events.EventEmitter);
exports.Room = Room;
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", {
15 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})
15 years ago
.tree()
);
};
Room.prototype.message = function(message) {
this.client.unidle();
this.client.xmpp.send(new xmpp.Element("message", {
15 years ago
to: this.room,
type: "groupchat",
15 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()
15 years ago
.tree()
);
};