2016-07-19 17 views

답변

4

당신은 당신의 일반 메시지 핸들러에서 메시지 유형을 확인할 수 있습니다 : 이제 회신에 대한

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; 
} 
+0

감사합니다 ..이 줄을 추가 한 후 작업 수신 메시지를. connection.addHandler (Gab.on_message, null, "message", "groupchat"); – user1752065

+0

이제 다음으로 원하는 것은 사용자의 메시지 기록입니다 (사용자가 그룹에 가입 한 경우). 현재 나는 아카이브를 다루기 위해 다음과 같은 코드를 가지고있다. connection.mam.query ( Strophe.getBareJidFromJid (Gab.connection.jid) { 와 : JID + "@의 muc.server" 최대 50 전에 '' \t \t 의 onMessage : 기능 (메시지) { – user1752065