如何使用Strophe lib为JS获取我的"朋友"的在线状态?不是名单,甚至是单一的存在(或者我要在名册中做1个req /用户?)通常我只会在每个资源的"状态变化"时收到通知,但我想知道用户是在线还是离线(像Pidgin),没有考虑每个用户可以同时在线记录的许多资源.
在第一组消息之后,strophe.muc插件不会对以下消息做出反应.我从房间里获得了第一个存在,消息和名单,但所有后续消息和存在节都不会触发这些功能.我认为这些线路有问题:
this.rooms[room].addHandler('message', msg_handler_cb);
this.rooms[room].addHandler('presence', pres_handler_cb);
this.rooms[room].addHandler('roster', roster_cb);
Run Code Online (Sandbox Code Playgroud)
我的代码:
join: function(){
console.log("joining room");
var self = this;
connection.muc.join("room@conference.server", "john", self.onMessage, self.onPresence, self.onRoster);
},
onMessage: function(message){
var self = this;
var body = $(message).text();
var from = $(message).attr("from");
console.log(body);
console.log(from);
},
onPresence: function(presence){
console.log("onPresence");
console.log(presence);
},
onRoster: function(roster){
console.log("onRoster");
console.log(roster);
},
Run Code Online (Sandbox Code Playgroud) 我目前正致力于"添加名册联系"功能.
1)我添加了一个新的联系人到我的名册:
var iq = $iq({type: "set"}).c("query", {xmlns: "jabber:iq:roster"}).c("item" {jid:"test@hostname.de/test",name:"test"});
Chat.connection.sendIQ(iq);
Run Code Online (Sandbox Code Playgroud)
联系人已成功添加到我的名册.
2)将"subscribe"类型的在线节发送到新联系人('test'):
var subscribe = $pres({to: test@hostname.de/test, type: "subscribe"});
Chat.connection.send(subscribe);
Run Code Online (Sandbox Code Playgroud)
这有效,但不是每次都有效:
当我添加到我的名单('test')的人当前没有活动会话(未登录)时,我获得了发件人的订阅类型'none',并且还获得了'none'的订阅类型测试'.
所以:
接收者'测试':订阅'无'
发件人'我':订阅'无'
当我添加到我的名单的人有一个活动会话时,预期的订阅类型'到'和'从'成功设置.
任何的想法 ?
我正在创建一个聊天网站,我正在使用Strophe.js和Strophe.muc.js插件.单个聊天功能工作正常,但我也不想实现群聊功能,用户可以创建房间并邀请其他用户到他们的房间.使用muc插件,我可以创建一个房间,但问题是,直到我不配置它(我猜),其他用户无法加入,房间不持久.我知道muc插件有配置方法,但我不知道如何创建配置Form对象,我不知道它应该怎么样.这将是我的第一个问题.第二:我有可能加入一个以上的房间并从我所在的所有房间收到消息吗?如果没有,那么就没有必要回答我的第一个问题......
如何使用strophejs连接到XMPP服务器时获取SID和RID?我使用Ejabbered作为XMPP服务器.
这是我的代码
$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection('http://localhost:5280/http-bind');
conn.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
});
Gab.connection = conn;
});
$(document).bind('connected', function () {
---------------------------------
---------------------------------
console.log(Gab.connection.jid); // Got jid
console.log(Gab.connection.rid); // Value is undefined
console.log(Gab.connection.sid); // value is undefined
});
Run Code Online (Sandbox Code Playgroud)
我试过上面的代码.但是未定义为价值.
我已经检查了这个问题, XMPP:检索BOSH会话ID和RID
但在那里的评论中,'undefined'就是结果!
我已经安装并配置了Prosody服务器.它侦听标准localhost:5222.在配置文件中添加了admin - user1@example.com.对服务器的每个请求都以错误结束:
<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="" version="1.0">
<stream:error>
<not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
</stream:error>
</stream:stream>
Run Code Online (Sandbox Code Playgroud)
作为客户,我想使用strophe.js.我只发送存在节($ pres).这是我的代码.
'use strict';
angular.module('xmppTestApp')
.controller('ChatCtrl', function () {
var vm = this;
var url = "http://localhost:5222";
var connection = null;
var output = document.getElementById("output");
function log(message) {
var line = document.createElement("div");
line.textContent = message;
output.appendChild(line);
}
function connectHandler(cond) {
if (cond == Strophe.Status.CONNECTED) {
log("connected");
connection.send($pres());
}
else {
log("not connected");
}
}
vm.connectB = function() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
console.info(url); …Run Code Online (Sandbox Code Playgroud) 我使用strophe.js javascript客户端库使用下面的代码连接到xmpp服务器(openfire).
var BOSH_SERVICE = 'http://127.0.0.1:7070/http-bind/';
connection = new Strophe.Connection(BOSH_SERVICE);
connection.connect("jid",
"password",
onConnect);
Run Code Online (Sandbox Code Playgroud)
和回调函数(onConnect)如下:
function onConnect(status)
{
if (status == Strophe.Status.CONNECTING) {
log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
log('Strophe failed to connect.');
$('#connect').get(0).value = 'connect';
} else if (status == Strophe.Status.DISCONNECTING) {
log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
log('Strophe is disconnected.');
$('#connect').get(0).value = 'connect';
} else if (status == Strophe.Status.CONNECTED) {
log('Strophe is connected.');
log('ECHOBOT: Send a …Run Code Online (Sandbox Code Playgroud) 如果问题可能太宽泛,我深表歉意,这肯定是因为我是 XMPP 的新手。
我正在开发 Angular6 应用程序并希望在其中集成 Jabber 聊天。我用谷歌搜索了很多,但似乎没有找到任何明确的答案。
显然 strophe.js 看起来很有希望,但我找不到任何关于如何将它集成到 Angular5/6 项目的文档。
任何提示将不胜感激
谢谢
我们有一个网站,并使用 strope.js 库和 ejabberd XMPP 服务器为其开发了一个聊天系统。我们使用通过 PHP 启动的会话附件(使用内部库)。我们所做的就是从 PHP 脚本中获取 RID 和 SID,然后使用 strope 的会话附件。所述 RID 和 SID 存储在 cookie 中,每次 strope.js 上的 RID 更新时,cookie 上的 RID 值都会更新。
这工作正常,登录后我们会收到每个联系人的在线状态。这样做的问题是,当您转到站点上的另一个页面并使用所述 RID(我们使用 strope 生成的增量值)和 SID 进行附加时,服务器将不再发送您的联系人的状态信息,而不是当您登录时。这导致我们的联系人区域显示为完全不可见,即使他们在线。仅当您(或您的联系人)注销聊天然后再次登录时,它们才会在线显示(因为您将从 XMPP 服务器收到状态更新)。
我编写了一种解决方法,当从服务器接收到在线状态时,您的联系人的在线状态将保存在 cookie 中(所有在线联系人的 JID 都会保存在 cookie 中)。每次页面加载时都会检查此功能,如果设置了 cookie,则会读取该 cookie,并且 cookie 上的所有 JID 将被标记为在线。这工作正常,但可能有一些更好的方法来解决这个问题,使用 XMPP 的默认行为。
这是我在 javascript 中的代码:
var user = {};
var handlerReference = null;
var myMessages = myApp.messages('.messages', {
autoLayout: true
});
function setListener(name, jid) {
user.name = name;
user.jid = jid;
$("#chatScreenTitle").text(user.name);
handlerReference = connection.addHandler(onMsgReceive, null, 'message', "chat", null, user.jid, {matchBare: true});
}
function onMsgReceive(stanza) {
console.log($(stanza).children("body").text());
myMessages.addMessage({
text: $(stanza).children("body").text(),
type: "received"
}, 'append', true);
}
function sendMessage(message) {
if (message.length == 0) {
myApp.alert("please enter some text", "alert");
}
else {
var uniqueID = connection.getUniqueId("my:code");
var reqChannelsItems = $msg({id: uniqueID, to: …Run Code Online (Sandbox Code Playgroud) strophe ×10
xmpp ×8
javascript ×6
openfire ×3
ejabberd ×2
angular ×1
angular5 ×1
backbone.js ×1
prosody-im ×1