@jskit-ai/realtime 0.2.59 → 0.2.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -627,7 +627,7 @@ test("socket audience bootstrap rejects unauthenticated handshakes when the auth
|
|
|
627
627
|
assert.deepEqual(socket.joinedRooms, ["clients", "users", "user:17"]);
|
|
628
628
|
});
|
|
629
629
|
|
|
630
|
-
async function startRealtimeClient({ mobile = null } = {}) {
|
|
630
|
+
async function startRealtimeClient(t, { mobile = null, appConfig = {} } = {}) {
|
|
631
631
|
const registrations = new Map();
|
|
632
632
|
const provided = new Map();
|
|
633
633
|
let realtime = null;
|
|
@@ -656,16 +656,27 @@ async function startRealtimeClient({ mobile = null } = {}) {
|
|
|
656
656
|
if (mobile) {
|
|
657
657
|
inputs["client.mobile"] = mobile;
|
|
658
658
|
}
|
|
659
|
+
const previousAppConfig = globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
|
|
660
|
+
// The provider's Socket.IO client connects as it is made (autoConnect): the app config's own option keeps it closed.
|
|
661
|
+
setClientAppConfig({ ...appConfig, realtimeClient: { options: { autoConnect: false } } });
|
|
659
662
|
const runtime = createCapabilityRuntime({
|
|
660
663
|
inputs,
|
|
661
664
|
providers: [RealtimeClientProvider, probe]
|
|
662
665
|
});
|
|
666
|
+
t.after(async () => {
|
|
667
|
+
await runtime.shutdown();
|
|
668
|
+
if (previousAppConfig === undefined) delete globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
|
|
669
|
+
else globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY] = previousAppConfig;
|
|
670
|
+
});
|
|
663
671
|
await runtime.start();
|
|
664
|
-
|
|
672
|
+
// In Node there is no page to connect back to: a URL-less socket would look up the host "undefined", and the
|
|
673
|
+
// Capacitor URL is whatever listens on 127.0.0.1:3000.
|
|
674
|
+
assert.equal(realtime.socket.active, false, "The client provider opened a connection from the test.");
|
|
675
|
+
return { provided, realtime, registrations };
|
|
665
676
|
}
|
|
666
677
|
|
|
667
|
-
test("RealtimeClientProvider publishes one explicit client capability", async () => {
|
|
668
|
-
const fixture = await startRealtimeClient();
|
|
678
|
+
test("RealtimeClientProvider publishes one explicit client capability", async (t) => {
|
|
679
|
+
const fixture = await startRealtimeClient(t);
|
|
669
680
|
assert.deepEqual(Object.keys(fixture.realtime).sort(), [
|
|
670
681
|
"config", "dispose", "initialize", "onServedClientBuild", "setBeforeReconnect", "socket"
|
|
671
682
|
]);
|
|
@@ -675,25 +686,17 @@ test("RealtimeClientProvider publishes one explicit client capability", async ()
|
|
|
675
686
|
fixture.provided.get("jskit.realtime.runtime.client.socket"),
|
|
676
687
|
fixture.realtime.socket
|
|
677
688
|
);
|
|
678
|
-
await fixture.runtime.shutdown();
|
|
679
689
|
});
|
|
680
690
|
|
|
681
691
|
for (const [name, available, expectedUrl] of [
|
|
682
692
|
["uses the configured API URL inside Capacitor", true, "http://127.0.0.1:3000"],
|
|
683
693
|
["keeps web socket connections URL-less outside Capacitor", false, ""]
|
|
684
694
|
]) {
|
|
685
|
-
test(`RealtimeClientProvider ${name}`, async () => {
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
});
|
|
692
|
-
assert.equal(fixture.realtime.config.url, expectedUrl);
|
|
693
|
-
await fixture.runtime.shutdown();
|
|
694
|
-
} finally {
|
|
695
|
-
if (previousAppConfig === undefined) delete globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
|
|
696
|
-
else globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY] = previousAppConfig;
|
|
697
|
-
}
|
|
695
|
+
test(`RealtimeClientProvider ${name}`, async (t) => {
|
|
696
|
+
const fixture = await startRealtimeClient(t, {
|
|
697
|
+
mobile: { adapter: { available } },
|
|
698
|
+
appConfig: { mobile: { enabled: true, apiBaseUrl: "http://127.0.0.1:3000" } }
|
|
699
|
+
});
|
|
700
|
+
assert.equal(fixture.realtime.config.url, expectedUrl);
|
|
698
701
|
});
|
|
699
702
|
}
|