2014-09-26 8 views
0

로컬 ejabberd 2 서버를 실행 중이며 2 명의 사용자가 있습니다. [email protected][email protected]. 두 사용자는 모두 ejabberd admin webportal에서 추가 된 명부에 서로 있습니다.node-xmpp를 사용하여 Adium을 통해 사용자를 온라인으로 표시

나는 jeremy 계정으로 로그인 한 OSX에서 adium을 사용하고 있습니다. 노드 콘솔을 사용하여 온라인으로 billy 계정 표시를보고 싶습니다. adium의 메시지 빌리와 노드 REPL의 jeremy 메시지를 허용하고 싶습니다.

var Client = require('node-xmpp-client'), 
    ltx = require('node-xmpp-core').ltx; 

var client = new Client({jid: '[email protected]', password: 'password'}); 

client.on('online', function(data) { 
    console.log('Connected as ' + data.jid.user + '@' + data.jid.domain + '/' + data.jid.resource) 
    var presence = new ltx.Element('presence', { type: 'available' }).c('show').t('chat'); 
    client.send(presence); 
}); 

client.on('stanza', function(stanza) { 
    console.log('RECEIVED STANZA', stanza); 
}); 

client.on('offline', function() { 
    console.log('Client is offline'); 
}); 

client.on('connect', function() { 
    console.log('Client is connected'); 
}); 

// log in 
client.connect(); 

var message = new ltx.Element('message',{to: '[email protected]', type: 'chat'}).c('body').t('sup?'); 

// send message 
client.send(message); 

var roster = new ltx.Element('iq',{id: 'roster_0',type: 'get'}).c('query', { xmlns: 'jabber:iq:roster'}); 

// get roster 
client.send(roster); 

// log out 
client.end(); 

나는 제레미 계정에 빌리 계정에서 메시지를 전송하고, 그 반대의 경우도 마찬가지 잘 할 수 있습니다. 그러나 빌리가 Adium에서 온라인으로 볼 수는 없습니다.

두 번 테스트하려면 "별표"라는 세 번째 사용자를 만들었습니다. 제레미 로스터에 "별표"를 추가 한 다음이 사용자를 Asterisk를 통해 설정합니다. I 이 사용자는 Adium을 통해 온라인으로 볼 수 있습니다.

누락 된 부분에 대한 의견이 있으십니까?

답변

0

좋아, 약간 파고 난 후에 나는 그것이 작동하게했다. 나는 Simple XMPP을 만나 노드 -xmpp를 감싸고 모든 것이 작동하도록했다.

내 빌리 사용자가 구독을 수락하지 않았거나 jeremy 사용자를 구독하지 못했습니다. 전체 내용은 다음과 같습니다.

xmpp.connect({jid: '[email protected]', password: 'password', host: 'pbx.dev',port: 5222}); 
xmpp.on('online', function(data) { 
    xmpp.acceptSubscription('[email protected]'); 
    xmpp.subscribe('[email protected]'); 
    xmpp.getRoster(); 
}); 

xmpp.on('stanza', function(stanza) { 
    var rosterRequest = stanza.name == 'iq' && stanza.attrs.type == 'result' && stanza.attrs.id == 'roster_0' 
    if(rosterRequest) { 
    var buddies = stanza.children[0].children; 
    // do stuff with buddies 
    } 
}); 

// change status with 
xmpp.setPresence('away', 'BRB AFK IRL'); 

좀 더 자세히 알아 보려면 간단한 xmpp 코드를 찾아 보시기 바랍니다. 꽤 작아서 node-xmpp 만 감싸줍니다.