Send message in group/room using strophe.js

function sendGroupMsg()
{
var room_name = $('#room').val() + '@conference.localhost';
var msg = $('#msg').val();
Chat.sendMessage(room_name, msg, "groupchat");
}


var Chat = {
sendMessage: function (messgeTo, message, type) {
var messagetype = (type) ? type : 'chat';
var reply;
if (messagetype === 'groupchat') {
reply = $msg({to: messgeTo,
from: Chat.connection.jid,
type: messagetype,
id: Chat.connection.getUniqueId()
}).c("body", {xmlns: Strophe.NS.CLIENT}).t(message);
}
else {
reply = $msg({to: messgeTo,
from: Chat.connection.jid,
type: messagetype
}).c("body").t(message);
}
Chat.connection.send(reply.tree());
Chat.log('I sent ' + messgeTo + ': ' + message, reply.tree());
}
}

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *