Skip to content

Commit

Permalink
fast: Emit error events on entity
Browse files Browse the repository at this point in the history
At least on the web, emitting an error on fast will stop processing.
Unless there is an error event listener on it but adding error listener on all "plugins" is a bit cumbersome.
So let's always emit errors on entity instead.
  • Loading branch information
sonnyp committed Jan 12, 2025
1 parent 006ddb6 commit ff263d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/client-core/src/fast/fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SASLFactory from "saslmechanisms";

const NS = "urn:xmpp:fast:0";

export default function fast({ sasl2 }) {
export default function fast({ sasl2, entity }) {
const saslFactory = new SASLFactory();

let token;
Expand All @@ -24,14 +24,14 @@ export default function fast({ sasl2 }) {
try {
await this.saveToken(token);
} catch (err) {
fast.emit("error", err);
entity.emit("error", err);
}
},
async fetch() {
try {
return this.fetchToken();
} catch (err) {
fast.emit("error", err);
entity.emit("error", err);
}
},
saslFactory,
Expand Down Expand Up @@ -68,7 +68,7 @@ export default function fast({ sasl2 }) {
});
return true;
} catch (err) {
fast.emit("error", err);
entity.emit("error", err);
return false;
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function client(options = {}) {

const fast = _fast({
sasl2,
entity,
});
sasl2.setup({ fast });

Expand Down

0 comments on commit ff263d7

Please sign in to comment.