我无法理解如何在 node-xmpp(GTalk 帐户)中检索 XMPP 花名册(以及最终每个联系人的状态)。
我的示例代码可以登录和连接,但我对发送和监听的内容有点迷失:
var xmpp = require('node-xmpp')
jid = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="36534e575b465a5376515b575f5a1855595b" rel="noreferrer noopener nofollow">[email protected]</a>'
password = 'xxxxxxxxxxxxxx'
// Establish a connection
var conn = new xmpp.Client({
jid: jid,
password: password,
host: 'talk.google.com',
port: 5222
})
conn.on('online', function() {
console.log('ONLINE')
var roster = new xmpp.Element('iq', {
type: 'get',
from: jid,
id: new Date().getTime()
}).c('query', { xmlns: 'jabber:iq:roster' })
conn.send(roster) // Now what?
})
conn.on('error', function(e) {
console.log(e)
})
最佳答案
看起来我的花名册查询的结构是错误的,但它工作正常:
conn.on('online', function() {
console.log('ONLINE')
var roster = new xmpp.Element('iq', {
id: 'roster_0',
type: 'get'
}).c('query', {
xmlns: 'jabber:iq:roster'
})
conn.send(roster)
})
关于node.js - 在node-xmpp中检索名册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13735648/