【问题标题】:Know of Any Non-Deprecated Javascript XMPP Client Libraries?知道任何未弃用的 Javascript XMPP 客户端库吗?
【发布时间】:2020-02-18 03:07:22
【问题描述】:

您知道任何不推荐使用的 javascript XMPP 客户端库吗? 我尝试过的库是:

  1. node-xmpp-client

2.@xmpp/client

我在使用@xmpp/client 时遇到了困难。请看下面的代码和错误。

结果: 用户登录后打印“我在线”。

如果您知道任何学习资源,请提供任何学习资源

代码:

 var app = require('express')();
 //const xmpp = require('xmpp-ftw');
 //const BuddyCloud = require('xmpp-ftw-buddycloud');

 var server = require('http').createServer(app);

 var io = require('socket.io').listen(server);

 server.listen(process.env.PORT || 3000);

 app.get('/', function(req, res){
 res.sendFile(__dirname + '/index.html');
 });


 const {client, xml} = require('@xmpp/client')

const xmpp = client({
     service: 'ws://domain.com:5280/xmpp-websocket',
     domain:'domain.com',
     username: 'test',
     password:'pa$$word'
 });

 xmpp.on('online', ()=>{
 console.log('I am Online');
 });

 xmpp.on('stanza', async stanza => {
    if (stanza.is('message')) {
      await xmpp.send(xml('presence', {type: 'unavailable'}))
      await xmpp.stop()
    }
  });


 xmpp.start();

错误:

Error: Unexpected server response: 404
    at ClientRequest.req.on (/Users/my-name/xmmp-begin-2/node_modules/ws/lib/websocket.js:579:7)
    at ClientRequest.emit (events.js:198:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at Socket.socketOnData (_http_client.js:442:20)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:94:17)
Emitted 'error' event at:
    at Socket.listeners.error.error (/Users/my-name/xmmp-begin- 
    2/node_modules/@xmpp/connection/index.js:98:12)
    at Socket.emit (events.js:203:15)
    at WebSocket.listeners.error.event (/Users/my-name/xmmp-begin- 
    2/node_modules/@xmpp/websocket/lib/Socket.js:40:12)
    at WebSocket.onError (/Users/my-name/xmmp-begin-2/node_modules/ws/lib/event-target.js:128:16)
    at WebSocket.emit (events.js:198:13)
    at abortHandshake (/Users/my-name/xmmp-begin-2/node_modules/ws/lib/websocket.js:697:15)
    at ClientRequest.req.on (/Users/my-name/xmmp-begin-2/node_modules/ws/lib/websocket.js:579:7)
    [... lines matching original stack trace ...]
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)

my-name-MacBook-Pro:xmmp-begin-2 my-name$ 

韵律上的位置块:

server {
    listen  80;
    listen [::]:80;
    server_name my-domain.net;

    location /xmpp-websocket/
    {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass "http://localhost:5280/xmpp-websocket";

            proxy_set_header HOST $host;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_read_timeout  900s;
    }



    location / {
            proxy_pass "http://localhost:8000/";

    }

    error_page 404 /404.html;
            location = /40x.html {

    }

    error_page 500 502 503 504 /50x.html;
            location = /50x.html{

    }

}

【问题讨论】:

  • 404 错误表明服务器不期望该路径上的 websockets 请求。你用的是什么服务器?它的配置文件里有什么?
  • @legoscia 我正在使用韵律 v0.9.10。我刚刚更新了位置块(请参阅已编辑的问题),现在我从模块管理器中收到一个错误,即无法安装 websocket 模块

标签: javascript html node.js websocket xmpp


【解决方案1】:

node-xmpp-client 运行良好

我的 nginx 配置

stream {
map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

upstream websocket {
    server localhost:5280;
}

server {
    listen 80;
    location / {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}
}

我使用另一个子域来访问韵律。 尝试不使用nginx代理直接连接,看看问题是来自js/nginx还是prosody。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 2013-02-14
    • 2011-01-30
    • 1970-01-01
    相关资源
    最近更新 更多