You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在AdonisJS中使用simple-xmpp注册ejabberd用户遇IDN域名错误求助

解决AdonisJS中使用simple-xmpp注册ejabberd用户时的"Remote domain is not an IDN hostname"错误

问题核心原因

该错误主要源于两个关键点:IQ请求的XML结构不符合XMPP规范,导致ejabberd解析失败后返回误报;或是ejabberd的域名配置、IDN验证规则存在限制。

分步解决方案

1. 修正IQ请求结构

你当前代码错误地在IQ外层嵌套了stream:stream元素,而连接建立后发送的注册请求不需要外层流标签,直接构造IQ stanza即可:

xmpp.on("online", () => {
  console.log("online....");
  // 移除外层stream:stream,直接构造注册IQ
  const iq = new xmpp.Element("iq", {
    type: "set",
    id: "reg2",
    to: "localhost" // 替换为你的ejabberd实际域名
  })
    .c("query", {
      xmlns: "jabber:iq:register",
    })
    .c("username")
    .t(user.username)
    .up()
    .c("password")
    .t(user.password);

  xmpp.send(iq);
});

2. 修复错误处理逻辑

当前代码仅监听message类型错误,但注册失败的错误会通过iq类型的stanza返回,调整错误处理逻辑:

xmpp.on("stanza", (stanza) => {
  if (stanza.is("presence")) {
    console.log("Connection established successfully");
  } else if (stanza.is("iq") && stanza.attrs.type === "error") {
    const errorElement = stanza.getChild("error");
    const errorText = errorElement.getChildText("text");
    console.error("Error registering user:", errorText);
  }
});

3. 检查ejabberd配置

  • 确认hosts配置中的域名是合法IDN(localhost属于合法IDN,自定义域名需符合IDN规则)
  • 启用mod_register并允许注册,打开ejabberd.yml添加或修改配置:
    hosts:
      - "localhost"
    
    modules:
      mod_register:
        access_from: all
        allow_registration: true
    

4. 验证simple-xmpp连接参数

确保连接时的jid、host与ejabberd配置匹配,示例连接代码:

xmpp.connect({
  jid: "admin@localhost", // 替换为ejabberd管理员账号或组件JID
  password: "your_password",
  host: "127.0.0.1",
  port: 5222 // 客户端端口,连接组件则用5269
});

内容的提问来源于stack exchange,提问作者M.Edriss Aria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 03:45:25