From 968204f8bc0f15f7b9a9bca55065656a6484b2d9 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sun, 22 Dec 2024 16:42:18 +0100 Subject: [PATCH] fixes --- Makefile | 1 + packages/client/package.json | 2 +- packages/client/react-native.js | 94 ----------------------------- packages/stream-features/route.js | 5 +- packages/stream-management/index.js | 23 +++---- server/prosody.cfg.lua | 7 ++- 6 files changed, 15 insertions(+), 117 deletions(-) delete mode 100644 packages/client/react-native.js diff --git a/Makefile b/Makefile index c5910262..30abfe93 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ unit: e2e: $(warning e2e tests require prosody-trunk and luarocks) cd server && prosodyctl --config prosody.cfg.lua install mod_sasl2 > /dev/null +# https://github.com/xmppjs/xmpp.js/pull/1006 # cd server && prosodyctl --config prosody.cfg.lua install mod_sasl2_bind2 > /dev/null # cd server && prosodyctl --config prosody.cfg.lua install mod_sasl2_fast > /dev/null # cd server && prosodyctl --config prosody.cfg.lua install mod_sasl2_sm > /dev/null diff --git a/packages/client/package.json b/packages/client/package.json index 57b170c8..427fbb3f 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -29,7 +29,7 @@ "saslmechanisms": "^0.1.1" }, "browser": "./browser.js", - "react-native": "./react-native.js", + "react-native": "./browser.js", "engines": { "node": ">= 20" }, diff --git a/packages/client/react-native.js b/packages/client/react-native.js deleted file mode 100644 index baecf921..00000000 --- a/packages/client/react-native.js +++ /dev/null @@ -1,94 +0,0 @@ -import { xml, jid, Client } from "@xmpp/client-core"; -import getDomain from "./lib/getDomain.js"; -import SASLFactory from "saslmechanisms"; - -import _reconnect from "@xmpp/reconnect"; -import _websocket from "@xmpp/websocket"; -import _middleware from "@xmpp/middleware"; -import _streamFeatures from "@xmpp/stream-features"; -import _iqCaller from "@xmpp/iq/caller.js"; -import _iqCallee from "@xmpp/iq/callee.js"; -import _resolve from "@xmpp/resolve"; -import _sasl2 from "@xmpp/sasl2"; -import _sasl from "@xmpp/sasl"; -import _resourceBinding from "@xmpp/resource-binding"; -import _sessionEstablishment from "@xmpp/session-establishment"; -import _streamManagement from "@xmpp/stream-management"; - -import plain from "@xmpp/sasl-plain"; -import anonymous from "@xmpp/sasl-anonymous"; - -function client(options = {}) { - const { resource, credentials, username, password, ...params } = options; - const { clientId, software, device } = params; - - const { domain, service } = params; - if (!domain && service) { - params.domain = getDomain(service); - } - - const entity = new Client(params); - - const reconnect = _reconnect({ entity }); - const websocket = _websocket({ entity }); - - const middleware = _middleware({ entity }); - const streamFeatures = _streamFeatures({ middleware }); - const iqCaller = _iqCaller({ middleware, entity }); - const iqCallee = _iqCallee({ middleware, entity }); - const resolve = _resolve({ entity }); - // Stream features - order matters and define priority - - const saslFactory = new SASLFactory(); - // SASL mechanisms - order matters and define priority - const mechanisms = Object.entries({ - plain, - anonymous, - }).map(([k, v]) => ({ [k]: v(saslFactory) })); - - const sasl2 = _sasl2( - { streamFeatures, saslFactory }, - credentials || { username, password }, - { clientId, software, device }, - ); - - const sasl = _sasl( - { streamFeatures, saslFactory }, - credentials || { username, password }, - ); - - const streamManagement = _streamManagement({ - streamFeatures, - entity, - middleware, - sasl2, - }); - const resourceBinding = _resourceBinding( - { iqCaller, streamFeatures }, - resource, - ); - const sessionEstablishment = _sessionEstablishment({ - iqCaller, - streamFeatures, - }); - - return Object.assign(entity, { - entity, - reconnect, - websocket, - middleware, - streamFeatures, - iqCaller, - iqCallee, - resolve, - saslFactory, - sasl2, - sasl, - resourceBinding, - sessionEstablishment, - streamManagement, - mechanisms, - }); -} - -export { xml, jid, client }; diff --git a/packages/stream-features/route.js b/packages/stream-features/route.js index ee81628b..03e6ceb8 100644 --- a/packages/stream-features/route.js +++ b/packages/stream-features/route.js @@ -4,9 +4,6 @@ export default function route() { return next(); const prevent = await next(); - // BIND2 inline handler may have already set to online, eg inline SM resume - if (!prevent && entity.jid && entity.status !== "online") { - entity._status("online", entity.jid); - } + if (!prevent && entity.jid) entity._status("online", entity.jid); }; } diff --git a/packages/stream-management/index.js b/packages/stream-management/index.js index 51ce2351..4ec2bff7 100644 --- a/packages/stream-management/index.js +++ b/packages/stream-management/index.js @@ -53,7 +53,6 @@ export default function streamManagement({ outbound: 0, inbound: 0, max: null, - outbound_q: [], }; entity.on("online", (jid) => { @@ -87,29 +86,23 @@ export default function streamManagement({ // https://xmpp.org/extensions/xep-0198.html#enable // For client-to-server connections, the client MUST NOT attempt to enable stream management until after it has completed Resource Binding unless it is resuming a previous session - function resumeSuccess() { - sm.enabled = true; - if (address) entity.jid = address; - entity.status = "online"; - } - - function resumeFailed() { - sm.id = ""; - sm.enabled = false; - sm.outbound = 0; - } - streamFeatures.use("sm", NS, async (context, next) => { // Resuming if (sm.id) { try { - resumeSuccess(await resume(entity, sm.inbound, sm.id)); + await resume(entity, sm.inbound, sm.id); + sm.enabled = true; + entity.jid = address; + entity.status = "online"; return true; // If resumption fails, continue with session establishment } catch { - resumeFailed(); + sm.id = ""; + sm.enabled = false; + sm.outbound = 0; } } + // Enabling // Resource binding first diff --git a/server/prosody.cfg.lua b/server/prosody.cfg.lua index cb3eb0f8..499cda1f 100644 --- a/server/prosody.cfg.lua +++ b/server/prosody.cfg.lua @@ -23,9 +23,10 @@ modules_enabled = { "version"; "smacks"; "sasl2"; - "sasl2_bind2"; - "sasl2_fast"; - "sasl2_sm"; + -- https://github.com/xmppjs/xmpp.js/pull/1006 + -- "sasl2_bind2"; + -- "sasl2_fast"; + -- "sasl2_sm"; }; modules_disabled = {