From a29e515636ec620328f44f2191479fea2659f244 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Mon, 6 Jan 2025 20:11:21 +0100 Subject: [PATCH] Single place to import EventEmitter from --- package-lock.json | 6 +++++- packages/client/README.md | 6 ++++-- packages/client/example.js | 6 ++++-- packages/component/example.js | 2 +- packages/events/index.js | 2 +- packages/events/test/promise.test.js | 2 +- packages/tls/lib/Socket.js | 2 +- packages/tls/package.json | 3 ++- packages/xml/lib/Parser.js | 2 +- packages/xml/package.json | 1 + 10 files changed, 21 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5bc4318d..260773a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6821,6 +6821,8 @@ }, "node_modules/events": { "version": "3.3.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", "license": "MIT", "engines": { "node": ">=0.8.x" @@ -14458,7 +14460,8 @@ "license": "ISC", "dependencies": { "@xmpp/connection": "^0.14.0", - "@xmpp/connection-tcp": "^0.14.0" + "@xmpp/connection-tcp": "^0.14.0", + "@xmpp/events": "^0.14.0" }, "engines": { "node": ">= 20" @@ -14495,6 +14498,7 @@ "version": "0.14.0", "license": "ISC", "dependencies": { + "@xmpp/events": "^0.14.0", "ltx": "^3.1.1" }, "engines": { diff --git a/packages/client/README.md b/packages/client/README.md index 18804533..1a5191f8 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -55,12 +55,14 @@ xmpp.on("offline", () => { console.log("offline"); }); -xmpp.once("stanza", async (stanza) => { +xmpp.on("stanza", onStanza); +async function onStanza(stanza) { if (stanza.is("message")) { + xmpp.off("stanza", onStanza); await xmpp.send(xml("presence", { type: "unavailable" })); await xmpp.stop(); } -}); +} xmpp.on("online", async (address) => { console.log("online as", address.toString()); diff --git a/packages/client/example.js b/packages/client/example.js index f0b342bd..9d56999c 100644 --- a/packages/client/example.js +++ b/packages/client/example.js @@ -25,12 +25,14 @@ xmpp.on("offline", () => { console.log("offline"); }); -xmpp.once("stanza", async (stanza) => { +xmpp.on("stanza", onStanza); +async function onStanza(stanza) { if (stanza.is("message")) { + xmpp.off("stanza", onStanza); await xmpp.send(xml("presence", { type: "unavailable" })); await xmpp.stop(); } -}); +} xmpp.on("online", async (address) => { console.log("online as", address.toString()); diff --git a/packages/component/example.js b/packages/component/example.js index 2c8bec4a..ce5847b5 100644 --- a/packages/component/example.js +++ b/packages/component/example.js @@ -18,7 +18,7 @@ xmpp.on("offline", () => { console.log("offline"); }); -xmpp.once("stanza", async (stanza) => { +xmpp.on("stanza", async (stanza) => { if (stanza.is("message")) { await xmpp.stop(); } diff --git a/packages/events/index.js b/packages/events/index.js index 55f59a9a..e952ad71 100644 --- a/packages/events/index.js +++ b/packages/events/index.js @@ -1,4 +1,4 @@ -import EventEmitter from "events"; +import { EventEmitter } from "events"; import timeout from "./lib/timeout.js"; import delay from "./lib/delay.js"; diff --git a/packages/events/test/promise.test.js b/packages/events/test/promise.test.js index 9568d5c3..d51cca4d 100644 --- a/packages/events/test/promise.test.js +++ b/packages/events/test/promise.test.js @@ -1,5 +1,5 @@ import promise from "../lib/promise.js"; -import EventEmitter from "node:events"; +import { EventEmitter } from "../index.js"; class Socket extends EventEmitter { constructor(fn) { diff --git a/packages/tls/lib/Socket.js b/packages/tls/lib/Socket.js index 1e3f2a64..e0bbfa27 100644 --- a/packages/tls/lib/Socket.js +++ b/packages/tls/lib/Socket.js @@ -1,5 +1,5 @@ import tls from "tls"; -import { EventEmitter } from "events"; +import { EventEmitter } from "@xmpp/events"; class Socket extends EventEmitter { constructor() { diff --git a/packages/tls/package.json b/packages/tls/package.json index 3639fcef..d3811246 100644 --- a/packages/tls/package.json +++ b/packages/tls/package.json @@ -10,7 +10,8 @@ "main": "index.js", "dependencies": { "@xmpp/connection": "^0.14.0", - "@xmpp/connection-tcp": "^0.14.0" + "@xmpp/connection-tcp": "^0.14.0", + "@xmpp/events": "^0.14.0" }, "keywords": [ "XMPP", diff --git a/packages/xml/lib/Parser.js b/packages/xml/lib/Parser.js index 69138e18..a8ef6f1c 100644 --- a/packages/xml/lib/Parser.js +++ b/packages/xml/lib/Parser.js @@ -1,6 +1,6 @@ import LtxParser from "ltx/lib/parsers/ltx.js"; import Element from "ltx/lib/Element.js"; -import EventEmitter from "events"; +import { EventEmitter } from "@xmpp/events"; import XMLError from "./XMLError.js"; class Parser extends EventEmitter { diff --git a/packages/xml/package.json b/packages/xml/package.json index c37d4739..bb7eb11f 100644 --- a/packages/xml/package.json +++ b/packages/xml/package.json @@ -16,6 +16,7 @@ "presence" ], "dependencies": { + "@xmpp/events": "^0.14.0", "ltx": "^3.1.1" }, "engines": {