Skip to content

Error when using example code #1107

@Jak2k

Description

@Jak2k

The code:

import { client, xml } from "@xmpp/client";

const xmpp = client({
  service: "ws://localhost:5280/xmpp-websocket", // my own server and so on here
  domain: "localhost",
  resource: "example",
  username: "username",
  password: "password",
});

xmpp.on("error", (err) => {
  console.error(err);
});

xmpp.on("offline", () => {
  console.log("offline");
});

xmpp.on("stanza", onStanza);
async function onStanza(stanza) {
  if (stanza.is("message")) {
    xmpp.removeListener("stanza", onStanza);
    await xmpp.send(xml("presence", { type: "unavailable" }));
    await xmpp.stop();
  }
}

xmpp.on("online", async (address) => {
  console.log("online as", address.toString());

  // Makes itself available
  await xmpp.send(xml("presence"));

  // Sends a chat message to itself
  const message = xml(
    "message",
    { type: "chat", to: address },
    xml("body", {}, "hello world"),
  );
  await xmpp.send(message);
});

await xmpp.start();

The error I get in the browser console:

Uncaught (in promise) TypeError: can't set private field: object is not the right class
    _attachSocket index.js:75
    connect index.js:235
    connect Client.js:38
    connect index.js:63
    start index.js:220
    useXmppStore xmpp.js:52
    createHook runtime-core.esm-bundler.js:2881
    callWithErrorHandling runtime-core.esm-bundler.js:199
    callWithAsyncErrorHandling runtime-core.esm-bundler.js:206
    __weh runtime-core.esm-bundler.js:2861
    flushPostFlushCbs runtime-core.esm-bundler.js:385
    render2 runtime-core.esm-bundler.js:6720
    mount runtime-core.esm-bundler.js:4004
    mount runtime-dom.esm-bundler.js:1826
    <anonymous> main.ts:12
[index.js:75:5](http://localhost:5173/node_modules/.pnpm/@[email protected]/node_modules/@xmpp/connection/index.js)
    start index.js:220
    AsyncFunctionThrow self-hosted:805
    (Async: async)

I'm using Firefox to open it and vite as bundler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions