@jskit-ai/realtime 0.1.65 → 0.1.66

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.
@@ -1,7 +1,7 @@
1
1
  export default Object.freeze({
2
2
  packageVersion: 1,
3
3
  packageId: "@jskit-ai/realtime",
4
- version: "0.1.65",
4
+ version: "0.1.66",
5
5
  kind: "runtime",
6
6
  description: "Thin, generic realtime runtime wrappers for socket.io server and client.",
7
7
  options: {
@@ -95,7 +95,7 @@ export default Object.freeze({
95
95
  mutations: {
96
96
  dependencies: {
97
97
  runtime: {
98
- "@jskit-ai/kernel": "0.1.66",
98
+ "@jskit-ai/kernel": "0.1.67",
99
99
  "@socket.io/redis-adapter": "^8.3.0",
100
100
  "redis": "^5.8.2",
101
101
  "socket.io": "^4.8.3",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/realtime",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@socket.io/redis-adapter": "^8.3.0",
19
- "@jskit-ai/kernel": "0.1.66",
19
+ "@jskit-ai/kernel": "0.1.67",
20
20
  "redis": "^5.8.2",
21
21
  "socket.io": "^4.8.3",
22
22
  "socket.io-client": "^4.8.3"
@@ -10,6 +10,18 @@ const REALTIME_RUNTIME_CLIENT_API = Object.freeze({
10
10
  disconnectSocketIoClient
11
11
  });
12
12
 
13
+ function isCapacitorRuntimeAvailable(app) {
14
+ if (!app || typeof app.has !== "function" || typeof app.make !== "function") {
15
+ return false;
16
+ }
17
+ if (app.has("mobile.capacitor.adapter.client") !== true) {
18
+ return false;
19
+ }
20
+
21
+ const adapter = app.make("mobile.capacitor.adapter.client");
22
+ return adapter?.available === true;
23
+ }
24
+
13
25
  function resolveRealtimeClientConfig(app) {
14
26
  const appConfig = normalizeObject(getClientAppConfig());
15
27
  const env = app && typeof app.has === "function" && app.has("jskit.client.env") ? normalizeObject(app.make("jskit.client.env")) : {};
@@ -18,7 +30,9 @@ function resolveRealtimeClientConfig(app) {
18
30
  const mobileConfig = resolveMobileConfig({
19
31
  mobile: normalizeObject(appConfig.mobile)
20
32
  });
21
- const url = normalizeText(realtimeClient.url || (mobileConfig.enabled === true ? mobileConfig.apiBaseUrl : ""));
33
+ const url = normalizeText(
34
+ realtimeClient.url || (mobileConfig.enabled === true && isCapacitorRuntimeAvailable(app) ? mobileConfig.apiBaseUrl : "")
35
+ );
22
36
  const options = normalizeObject(realtimeClient.options);
23
37
  const explicitDebugEnabled =
24
38
  typeof realtimeClient.debug === "boolean"
@@ -248,7 +248,7 @@ test("RealtimeClientProvider registers runtime realtime client api", () => {
248
248
  assert.equal(typeof api.disconnectSocketIoClient, "function");
249
249
  });
250
250
 
251
- test("RealtimeClientProvider uses mobile.apiBaseUrl when realtimeClient.url is unset", () => {
251
+ test("RealtimeClientProvider uses mobile.apiBaseUrl only inside the Capacitor runtime", () => {
252
252
  const previousAppConfig = globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
253
253
  const calls = [];
254
254
  const socket = {
@@ -265,6 +265,9 @@ test("RealtimeClientProvider uses mobile.apiBaseUrl when realtimeClient.url is u
265
265
  });
266
266
 
267
267
  const app = createSingletonApp();
268
+ app.instance("mobile.capacitor.adapter.client", {
269
+ available: true
270
+ });
268
271
  app.instance("runtime.realtime.client", {
269
272
  createSocketIoClient(input = {}) {
270
273
  calls.push(input);
@@ -292,6 +295,53 @@ test("RealtimeClientProvider uses mobile.apiBaseUrl when realtimeClient.url is u
292
295
  }
293
296
  });
294
297
 
298
+ test("RealtimeClientProvider keeps web socket connections URL-less when mobile is installed outside Capacitor", () => {
299
+ const previousAppConfig = globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
300
+ const calls = [];
301
+ const socket = {
302
+ on() {},
303
+ off() {},
304
+ disconnect() {}
305
+ };
306
+ try {
307
+ setClientAppConfig({
308
+ mobile: {
309
+ enabled: true,
310
+ apiBaseUrl: "http://127.0.0.1:3000"
311
+ }
312
+ });
313
+
314
+ const app = createSingletonApp();
315
+ app.instance("mobile.capacitor.adapter.client", {
316
+ available: false
317
+ });
318
+ app.instance("runtime.realtime.client", {
319
+ createSocketIoClient(input = {}) {
320
+ calls.push(input);
321
+ return socket;
322
+ },
323
+ disconnectSocketIoClient() {}
324
+ });
325
+
326
+ const provider = new RealtimeClientProvider();
327
+ provider.register(app);
328
+
329
+ assert.equal(app.make("runtime.realtime.client.socket"), socket);
330
+ assert.deepEqual(calls, [
331
+ {
332
+ url: "",
333
+ options: {}
334
+ }
335
+ ]);
336
+ } finally {
337
+ if (previousAppConfig === undefined) {
338
+ delete globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY];
339
+ } else {
340
+ globalThis[CLIENT_APP_CONFIG_GLOBAL_KEY] = previousAppConfig;
341
+ }
342
+ }
343
+ });
344
+
295
345
  test("RealtimeClientProvider boots socket listeners and disconnects on shutdown", async () => {
296
346
  const app = createSingletonApp();
297
347
  const provider = new RealtimeClientProvider();