Skip to content

Commit

Permalink
Single place to import EventEmitter from
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jan 6, 2025
1 parent b835091 commit a29e515
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 11 deletions.
6 changes: 5 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions packages/client/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion packages/component/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/events/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "events";
import { EventEmitter } from "events";

import timeout from "./lib/timeout.js";
import delay from "./lib/delay.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/events/test/promise.test.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/tls/lib/Socket.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tls from "tls";
import { EventEmitter } from "events";
import { EventEmitter } from "@xmpp/events";

class Socket extends EventEmitter {
constructor() {
Expand Down
3 changes: 2 additions & 1 deletion packages/tls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/xml/lib/Parser.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/xml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"presence"
],
"dependencies": {
"@xmpp/events": "^0.14.0",
"ltx": "^3.1.1"
},
"engines": {
Expand Down

0 comments on commit a29e515

Please sign in to comment.