Send message using strophe.js

function sendMsg(JID,MSG)
{
Chat.sendMessage(JID, MSG, "chat");
}


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 *