4
strophe MUCプラグインのメッセージハンドラを追加する方法。strophe muc pluginのonmessageハンドラを追加する方法
現在、私はジョインアクションのコールバック関数を追加しました。
Gab.connection.muc.join(room_name+"@muc.162.242.222.249", login_id,
function(message){
strophe MUCプラグインのメッセージハンドラを追加する方法。strophe muc pluginのonmessageハンドラを追加する方法
現在、私はジョインアクションのコールバック関数を追加しました。
Gab.connection.muc.join(room_name+"@muc.162.242.222.249", login_id,
function(message){
あなたは、一般的なメッセージハンドラ内のメッセージの種類を確認することができます。
connection.addHandler(onMessage, null, 'message', null, null, null);
...返信用
function onMessage(msg) {
var to = msg.getAttribute('to');
var from = msg.getAttribute('from');
var type = msg.getAttribute('type');
var elems = msg.getElementsByTagName('body');
if (type == "chat" && elems.length > 0) {
var body = elems[0];
console.log('CHAT: I got a message from ' + from + ': ' + Strophe.getText(body));
} else if (type == "groupchat" && elems.length > 0) {
var body = elems[0];
var room = Strophe.unescapeNode(Strophe.getNodeFromJid(from));
var nick = Strophe.getResourceFromJid(from);
console.log('GROUP CHAT: I got a message from ' + nick + ': ' + Strophe.getText(body) + ' in room: ' + room);
}
// we must return true to keep the handler alive.
// returning false would remove it after it finishes.
return true;
}
おかげで...この行を追加した後に作業を今すぐ受信メッセージを。 connection.addHandler(Gab.on_message、 null、 "message"、 "groupchat"); – user1752065
今、私が望む次のものは、ユーザーのメッセージ履歴です(ユーザーが参加したグループをクリックすると)。現在私はアーカイブを処理するための次のコードを持っています。 connection.mam.query( Strophe.getBareJidFromJid(Gab.connection.jid)、{ 有する:JID + "@のmuc.server"、 最大:50、前 ''、 \t \tのonMessage:関数(メッセージ){ – user1752065