ejabberd MAM 不适用于 Strophe js
ejabberd MAM doesn't work with Strophe js
即使在用户注销和登录后,我仍试图显示两个用户之间的对话。我的意思是当 user1 注销并再次登录时,他应该看到与 user2 进行的对话。我正在使用 Ejabberd XMPP 服务器和 Strophe Js 来检索消息。
我发现这个 strophe.mam.js 插件可以执行此操作,但出现错误并且无法获取消息。
这是我的代码:
function onConnect(status)
{
// Functions runs while users trys to login to the XMPP server
var iq = null;
switch (status)
{
case Strophe.Status.CONNECTING:
log('Connecting.');
break;
case Strophe.Status.CONNFAIL:
log('Failed to connect.');
$('#connect').get(0).value = 'connect';
break;
case Strophe.Status.DISCONNECTING:
log('Disconnecting.');
break;
case Strophe.Status.DISCONNECTED:
log('Disconnected.');
$('#connect').get(0).value = 'connect';
break;
case Strophe.Status.CONNECTED:
log('Connected.');
connection.addHandler(onMessage, null, 'message', null, null, null);
connection.addHandler(onPresence, null, 'presence', null, null, null);
iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
connection.sendIQ(iq, onRoster);
break;
default:
break;
}
}
function onMessage(msg) {
debugger;
var fromJid = msg.getAttribute("from"),
bareFromJid = Strophe.getBareJidFromJid(fromJid),
type = msg.getAttribute("type"),
elems = msg.getElementsByTagName("body");
if (type == "chat" && elems.length > 0) {
var body = elems[0],
message = Strophe.getText(body);
showMessage(bareFromJid + ": " + message);
connection.mam.query("yashwanth@localhost", {
"with": bareFromJid,
onMessage: function(message) {
console.log("Message from " + bareFromJid,
": " + message);
return true;
},
onComplete: function(response) {
console.log("Got all the messages");
}
});
}
return true;
}
function send() {
// Handles with sending the message
var to = $('#to-jid').get(0).value,
myBareJid = Strophe.getBareJidFromJid(connection.jid);
message = $('#message').get(0).value,
reply = $msg({to: to, type: 'chat'})
.c("body")
.t(message);
connection.send(reply.tree());
showMessage(myBareJid + ": " + message);
}
$(document).ready(function () {
connection = new Strophe.Connection(BOSH_SERVICE);
messagebox = $("#messages");
messagebox.val("");
logbox = $("#log-messages");
logbox.val("");
rosterbox = $("#roster");
rosterbox.val("");
connection.rawInput = function (data) { log('RECV: ' + data); };
connection.rawOutput = function (data) { log('SEND: ' + data); };
Strophe.log = function (level, msg) { log('LOG: ' + msg); };
login();
$('#send').bind('click', send);
});
所以每当用户收到消息时,控制台中都会有一些东西。但是 returns 我的日志中出现了这个错误
RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client'
from='yashwanth@localhost' to='yashwanth@localhost/22064184271436881211352579'
id='yashwanth@localhost' type='error'><query xmlns='urn:xmpp:mam:0'><x xmlns='jabber:x:data'><field
var='FORM_TYPE'><value>urn:xmpp:mam:0</value></field><field var='with'>
<value>shabda@localhost</value></field></x><set xmlns='http://jabber.org/protocol/rsm'/></query>
<error code='400' type='modify'><bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>
</iq></body>
请帮我解决这个问题
您的 MAM 查询格式不正确。
您在具有 xmlns jabber:x:data
功能的 x 元素上缺少属性 type="submit"
。在 XEP-0004 Data Forms
中必须输入类型
你的智商应该是:
<iq type='set' id='juliet1'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:mam:0</value>
</field>
<field var='with'>
<value>shabda@localhost</value>
</field>
</x>
<set xmlns='http://jabber.org/protocol/rsm'/>
</query>
</iq>
参见 XEP-0313 Message Archive Management 中的示例 6。
MAM strophe 插件有一个错误。我们在这里准备了修复:https://github.com/processone/strophejs-plugins/commit/5a7857e2ab625c0521c68719d7e220f00c32c593
并提交了这个拉取请求:https://github.com/strophe/strophejs-plugins/pull/65
我对 MAM 有疑问。看到这个 link:https://www.ejabberd.im/forum/25028/solved-how-configure-and-test-modmam-message-archive-management
我解决了将类型 'set' 更改为 'get'
的问题
即使在用户注销和登录后,我仍试图显示两个用户之间的对话。我的意思是当 user1 注销并再次登录时,他应该看到与 user2 进行的对话。我正在使用 Ejabberd XMPP 服务器和 Strophe Js 来检索消息。
我发现这个 strophe.mam.js 插件可以执行此操作,但出现错误并且无法获取消息。
这是我的代码:
function onConnect(status)
{
// Functions runs while users trys to login to the XMPP server
var iq = null;
switch (status)
{
case Strophe.Status.CONNECTING:
log('Connecting.');
break;
case Strophe.Status.CONNFAIL:
log('Failed to connect.');
$('#connect').get(0).value = 'connect';
break;
case Strophe.Status.DISCONNECTING:
log('Disconnecting.');
break;
case Strophe.Status.DISCONNECTED:
log('Disconnected.');
$('#connect').get(0).value = 'connect';
break;
case Strophe.Status.CONNECTED:
log('Connected.');
connection.addHandler(onMessage, null, 'message', null, null, null);
connection.addHandler(onPresence, null, 'presence', null, null, null);
iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
connection.sendIQ(iq, onRoster);
break;
default:
break;
}
}
function onMessage(msg) {
debugger;
var fromJid = msg.getAttribute("from"),
bareFromJid = Strophe.getBareJidFromJid(fromJid),
type = msg.getAttribute("type"),
elems = msg.getElementsByTagName("body");
if (type == "chat" && elems.length > 0) {
var body = elems[0],
message = Strophe.getText(body);
showMessage(bareFromJid + ": " + message);
connection.mam.query("yashwanth@localhost", {
"with": bareFromJid,
onMessage: function(message) {
console.log("Message from " + bareFromJid,
": " + message);
return true;
},
onComplete: function(response) {
console.log("Got all the messages");
}
});
}
return true;
}
function send() {
// Handles with sending the message
var to = $('#to-jid').get(0).value,
myBareJid = Strophe.getBareJidFromJid(connection.jid);
message = $('#message').get(0).value,
reply = $msg({to: to, type: 'chat'})
.c("body")
.t(message);
connection.send(reply.tree());
showMessage(myBareJid + ": " + message);
}
$(document).ready(function () {
connection = new Strophe.Connection(BOSH_SERVICE);
messagebox = $("#messages");
messagebox.val("");
logbox = $("#log-messages");
logbox.val("");
rosterbox = $("#roster");
rosterbox.val("");
connection.rawInput = function (data) { log('RECV: ' + data); };
connection.rawOutput = function (data) { log('SEND: ' + data); };
Strophe.log = function (level, msg) { log('LOG: ' + msg); };
login();
$('#send').bind('click', send);
});
所以每当用户收到消息时,控制台中都会有一些东西。但是 returns 我的日志中出现了这个错误
RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client'
from='yashwanth@localhost' to='yashwanth@localhost/22064184271436881211352579'
id='yashwanth@localhost' type='error'><query xmlns='urn:xmpp:mam:0'><x xmlns='jabber:x:data'><field
var='FORM_TYPE'><value>urn:xmpp:mam:0</value></field><field var='with'>
<value>shabda@localhost</value></field></x><set xmlns='http://jabber.org/protocol/rsm'/></query>
<error code='400' type='modify'><bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>
</iq></body>
请帮我解决这个问题
您的 MAM 查询格式不正确。
您在具有 xmlns jabber:x:data
功能的 x 元素上缺少属性 type="submit"
。在 XEP-0004 Data Forms
你的智商应该是:
<iq type='set' id='juliet1'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:mam:0</value>
</field>
<field var='with'>
<value>shabda@localhost</value>
</field>
</x>
<set xmlns='http://jabber.org/protocol/rsm'/>
</query>
</iq>
参见 XEP-0313 Message Archive Management 中的示例 6。
MAM strophe 插件有一个错误。我们在这里准备了修复:https://github.com/processone/strophejs-plugins/commit/5a7857e2ab625c0521c68719d7e220f00c32c593
并提交了这个拉取请求:https://github.com/strophe/strophejs-plugins/pull/65
我对 MAM 有疑问。看到这个 link:https://www.ejabberd.im/forum/25028/solved-how-configure-and-test-modmam-message-archive-management
我解决了将类型 'set' 更改为 'get'
的问题