require(['converse'], function (converse) {
converse.plugins.add('myplugin', {
initialize: function () {
this._converse.api.archive.query({'with': 'admin2@localhost'});
}
});
converse.initialize({
jid: 'admin3@localhost',
authentication: 'prebind',
prebind_url: 'bind/bind.php',
allow_logout: false,
debug : true,
whitelisted_plugins: ['converse-inverse','converese-mam','converse-singleton','converse-muc-embedded','myplugin'],
archived_messages_page_size : 20,
message_archiving : "always",
auto_list_rooms: false,
show_chatstate_notifications:true,
message_carbons : true,
sounds_path : "sounds/",
auto_reconnect : true,
use_vcard : true,
auto_subscribe: false,
keepalive : true,
show_send_button:true,
archived_messages_page_size : 20,
bosh_service_url: 'http://localhost:5280/http-bind',
hide_muc_server: false,
play_sounds : true,
show_controlbox_by_default: false,
xhr_user_search: false
});
});
我试试,但我收到了这个错误:
Cannot read property 'getUniqueId' of undefined
at Object._converse.queryForArchivedMessages (converse-mam.js:266)
at Object.initialize (dev.html:30)
at PluginSocket.initializePlugin (pluggable.js:196)
at arrayEach (lodash.js:537)
at Object.forEach (lodash.js:9359)
at PluginSocket.initializePlugins (pluggable.js:227)
at Object.initPlugins (converse-core.js:1854)
at Object._converse.initialize (converse-core.js:1875)
at Object.initialize (converse-core.js:2037)
at dev.html:36
我很抱歉,如果这个问题有点简单或愚蠢,但我真的很喜欢使用converse.js,我真的很想在未来使用和了解更多关于converse.js的信息,因为它有完整的功能和文档。
答案 0 :(得分:0)
当Converse.js本身被初始化时,会调用Converse.js插件的initialize
方法。
这发生在用户登录之前(无论是自动还是手动)。
因此,在用户登录并建立XMPP连接和会话之前,您正在调用this._converse.api.archive.query({'with': 'admin2@localhost'});
。
相反,您应首先听取connection
事件,然后进行查询。
converse.plugins.add('myplugin', {
initialize: function () {
var _converse = this._converse;
_converse.on('connected', function () {
_converse.api.archive.query({'with': 'admin2@localhost'});
});
}
});