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:

2 thoughts on “Send message in group/room using strophe.js

  1. Dario

    What if group name contains space between words. For example "group number one", i could not send message to this group, and a tried to replace space with '_', '-' and ''.

Leave a Reply

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