【问题标题】:Openfire XMPP Client Connection via Ionic App通过 Ionic App 的 Openfire XMPP 客户端连接
【发布时间】:2021-01-17 05:58:08
【问题描述】:

为了测试客户端与我们的 Openfire XMPP 服务器的连接性,最初测试了以下测试脚本 (nodejs),它运行成功。

async function connectX() {
    try {
        const keyPair = await XmppUser.generateKeys()
        XmppUser.connect(username, password, keyPairs).then(
           async user => {
                        user.getFriends().then(friends => {
                            console.log("List of Friends: ");
                            console.log(friends);
                            user.getChatHistory().then(history => {
                                console.log("Chat History: ")
                                console.log(history);
                                user.closeConnection();
                            }).catch(e => console.log(e));
                        }).catch(e => console.log(e));
            }
        ).catch(e => console.log(e));
    } catch(e) {
        console.log(e)
    }
}

connectX()

输出:

List of Friends:
[ 'test1.test@chat.company.io', 'test2.test@chat.company.io' ]

Chat History:
{ messages:
   [ { date: 2020-08-11T12:18:34.314Z,
       from: 'test1.test@chat.company.io',
       to: 'test6.test@chat.company.io',
       message: 'Hello! Received.',
       id: 'D255Q-132' }
] }
lastId: '1',
firstId: '1',
count: '1' }

但是,当我使用相同的 ChatService 类在 ionic Angular 应用程序中运行脚本时,它会导致出现以下 CORS 错误。

Access to fetch at 'https://chat.company.io/.well-known/host-meta' from origin 'http://localhost:8100' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

供参考,https://chat.company.io/.well-known/host-meta 存在并具有以下内容:

<?xml version='1.0' encoding='utf-8'?>
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
  <Link rel="urn:xmpp:alt-connections:httppoll"
        href="https://chat.company.io:443" />
</XRD>

后端基础设施包括 Nginx 服务器,聊天服务器在其后面运行,开放端口如下:443、7070、5222、5223。

请帮助找出问题所在。

【问题讨论】:

    标签: ionic-framework xmpp ionic4 openfire


    【解决方案1】:

    可能的 CORS 问题, 在 Openfire 中启用对 CORS 的支持,服务器 -> 服务器设置 -> http 绑定 -> CORS 部分。

    【讨论】:

      猜你喜欢
      • 2013-08-27
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多