@dxos/client-services 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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/dist/lib/browser/{chunk-FZDVFED2.mjs → chunk-KW4WMU5R.mjs} +2698 -4599
- package/dist/lib/browser/chunk-KW4WMU5R.mjs.map +7 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
- package/dist/lib/browser/chunk-XJRPB3GA.mjs +22 -0
- package/dist/lib/browser/chunk-XJRPB3GA.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +490 -228
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/browser.mjs +86 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +48 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +60 -90
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-2DT3MZRL.mjs +22 -0
- package/dist/lib/node-esm/chunk-2DT3MZRL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-JDTIU3EP.mjs → chunk-NDMKP2CH.mjs} +2621 -4391
- package/dist/lib/node-esm/chunk-NDMKP2CH.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +490 -228
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs +86 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +48 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +60 -90
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +2 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +2 -2
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +2 -3
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +6 -6
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +8 -7
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +8 -11
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +7 -4
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +4 -3
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/index.d.ts +1 -1
- package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +5 -4
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
- package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +13 -9
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +20 -7
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
- package/dist/types/src/packlets/services/util.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
- package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/index.d.ts +4 -1
- package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +28 -17
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +26 -9
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -9
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +10 -7
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/util.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +6 -5
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
- package/dist/types/src/testing/setup.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +70 -55
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +8 -5
- package/src/packlets/agents/edge-agent-service.ts +15 -3
- package/src/packlets/devices/devices-service.test.ts +0 -1
- package/src/packlets/devices/devices-service.ts +1 -1
- package/src/packlets/devtools/devtools.ts +2 -3
- package/src/packlets/diagnostics/diagnostics.ts +1 -2
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.ts +2 -2
- package/src/packlets/identity/contacts-service.ts +0 -1
- package/src/packlets/identity/identity-manager.test.ts +5 -5
- package/src/packlets/identity/identity-manager.ts +23 -22
- package/src/packlets/identity/identity-recovery-manager.ts +22 -18
- package/src/packlets/identity/identity-service.test.ts +6 -27
- package/src/packlets/identity/identity-service.ts +13 -81
- package/src/packlets/identity/identity.test.ts +6 -6
- package/src/packlets/identity/identity.ts +11 -34
- package/src/packlets/invitations/device-invitation-protocol.ts +8 -7
- package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
- package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
- package/src/packlets/invitations/invitation-host-extension.ts +13 -14
- package/src/packlets/invitations/invitation-protocol.ts +7 -4
- package/src/packlets/invitations/invitation-state.ts +1 -15
- package/src/packlets/invitations/invitations-handler.test.ts +4 -5
- package/src/packlets/invitations/invitations-handler.ts +74 -22
- package/src/packlets/invitations/invitations-manager.ts +40 -15
- package/src/packlets/invitations/invitations-service.ts +9 -9
- package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -16
- package/src/packlets/locks/index.ts +1 -1
- package/src/packlets/logging/logging-service.ts +20 -16
- package/src/packlets/network/network-service.test.ts +0 -1
- package/src/packlets/network/network-service.ts +10 -8
- package/src/packlets/services/client-rpc-server.ts +19 -16
- package/src/packlets/services/feed-syncer.test.ts +340 -0
- package/src/packlets/services/feed-syncer.ts +337 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +3 -2
- package/src/packlets/services/service-context.ts +138 -56
- package/src/packlets/services/service-host.test.ts +8 -8
- package/src/packlets/services/service-host.ts +70 -40
- package/src/packlets/services/service-registry.test.ts +0 -1
- package/src/packlets/space-export/archive-format.ts +42 -0
- package/src/packlets/space-export/index.ts +4 -1
- package/src/packlets/space-export/serialized-space-reader.ts +111 -0
- package/src/packlets/space-export/serialized-space-writer.ts +253 -0
- package/src/packlets/space-export/space-archive-reader.ts +64 -3
- package/src/packlets/space-export/space-archive-writer.ts +41 -3
- package/src/packlets/space-export/space-archive.test.ts +461 -0
- package/src/packlets/spaces/data-space-manager.test.ts +79 -13
- package/src/packlets/spaces/data-space-manager.ts +115 -115
- package/src/packlets/spaces/data-space.ts +58 -33
- package/src/packlets/spaces/edge-feed-replicator.test.ts +2 -2
- package/src/packlets/spaces/edge-feed-replicator.ts +12 -10
- package/src/packlets/spaces/epoch-migrations.ts +5 -5
- package/src/packlets/spaces/genesis.ts +6 -1
- package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.ts +10 -9
- package/src/packlets/spaces/spaces-service.test.ts +18 -11
- package/src/packlets/spaces/spaces-service.ts +123 -24
- package/src/packlets/storage/storage.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +10 -6
- package/src/packlets/testing/test-builder.ts +36 -10
- package/src/packlets/worker/worker-runtime.ts +188 -17
- package/src/packlets/worker/worker-session.ts +12 -18
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-FZDVFED2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JDTIU3EP.mjs.map +0 -7
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
- package/src/packlets/identity/default-space-state-machine.ts +0 -44
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Reactivity from '@effect/experimental/Reactivity';
|
|
6
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Layer from 'effect/Layer';
|
|
9
|
+
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
10
|
+
|
|
5
11
|
import { Trigger } from '@dxos/async';
|
|
6
12
|
import { DEFAULT_WORKER_BROADCAST_CHANNEL } from '@dxos/client-protocol';
|
|
7
13
|
import { type Config } from '@dxos/config';
|
|
@@ -16,17 +22,21 @@ import {
|
|
|
16
22
|
} from '@dxos/messaging';
|
|
17
23
|
import { RtcTransportProxyFactory } from '@dxos/network-manager';
|
|
18
24
|
import { type RpcPort } from '@dxos/rpc';
|
|
25
|
+
import * as OpfsWorker from '@dxos/sql-sqlite/OpfsWorker';
|
|
26
|
+
import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
|
|
27
|
+
import * as SqliteClient from '@dxos/sql-sqlite/SqliteClient';
|
|
28
|
+
import * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
19
29
|
import { type MaybePromise } from '@dxos/util';
|
|
20
30
|
|
|
21
31
|
import { ClientServicesHost } from '../services';
|
|
22
|
-
|
|
23
32
|
import { WorkerSession } from './worker-session';
|
|
24
33
|
|
|
25
34
|
// NOTE: Keep as RpcPorts to avoid dependency on @dxos/rpc-tunnel so we don't depend on browser-specific apis.
|
|
26
|
-
export type
|
|
35
|
+
export type CreateSessionProps = {
|
|
27
36
|
appPort: RpcPort;
|
|
28
37
|
systemPort: RpcPort;
|
|
29
38
|
shellPort?: RpcPort;
|
|
39
|
+
onClose?: () => Promise<void>;
|
|
30
40
|
};
|
|
31
41
|
|
|
32
42
|
export type WorkerRuntimeOptions = {
|
|
@@ -35,10 +45,20 @@ export type WorkerRuntimeOptions = {
|
|
|
35
45
|
acquireLock: () => Promise<void>;
|
|
36
46
|
releaseLock: () => void;
|
|
37
47
|
onStop?: () => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
automaticallyConnectWebrtc?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Optional SQLite layer for Effect. Defaults to LocalSqliteOpfsLayer.
|
|
55
|
+
* For testing in Node.js, use `sqliteLayerMemory` from `@dxos/sql-sqlite/platform`.
|
|
56
|
+
*/
|
|
57
|
+
sqliteLayer?: Layer.Layer<SqlClient.SqlClient | SqlExport.SqlExport, unknown>;
|
|
38
58
|
};
|
|
39
59
|
|
|
40
60
|
/**
|
|
41
|
-
* Runtime for the shared worker.
|
|
61
|
+
* Runtime for the shared and dedciated worker.
|
|
42
62
|
* Manages connections from proxies (in tabs).
|
|
43
63
|
* Tabs make requests to the `ClientServicesHost`, and provide a WebRTC gateway.
|
|
44
64
|
*/
|
|
@@ -52,11 +72,17 @@ export class WorkerRuntime {
|
|
|
52
72
|
private readonly _sessions = new Set<WorkerSession>();
|
|
53
73
|
private readonly _clientServices!: ClientServicesHost;
|
|
54
74
|
private readonly _channel: string;
|
|
75
|
+
private readonly _automaticallyConnectWebrtc: boolean;
|
|
76
|
+
private readonly _livenessLock = new WebLockWrapper(`@dxos/client-services/WorkerRuntime/${crypto.randomUUID()}`);
|
|
55
77
|
private _broadcastChannel?: BroadcastChannel;
|
|
56
78
|
private _sessionForNetworking?: WorkerSession; // TODO(burdon): Expose to client QueryStatusResponse.
|
|
57
79
|
private _config!: Config;
|
|
58
80
|
private _signalMetadataTags: any = { runtime: 'worker-runtime' };
|
|
59
81
|
private _signalTelemetryEnabled: boolean = false;
|
|
82
|
+
private _runtime!: ManagedRuntime.ManagedRuntime<
|
|
83
|
+
SqlTransaction.SqlTransaction | SqlClient.SqlClient | SqlExport.SqlExport,
|
|
84
|
+
never
|
|
85
|
+
>;
|
|
60
86
|
|
|
61
87
|
constructor({
|
|
62
88
|
channel = DEFAULT_WORKER_BROADCAST_CHANNEL,
|
|
@@ -64,37 +90,72 @@ export class WorkerRuntime {
|
|
|
64
90
|
acquireLock,
|
|
65
91
|
releaseLock,
|
|
66
92
|
onStop,
|
|
93
|
+
automaticallyConnectWebrtc = true,
|
|
94
|
+
sqliteLayer,
|
|
67
95
|
}: WorkerRuntimeOptions) {
|
|
68
96
|
this._configProvider = configProvider;
|
|
69
97
|
this._acquireLock = acquireLock;
|
|
70
98
|
this._releaseLock = releaseLock;
|
|
71
99
|
this._onStop = onStop;
|
|
72
100
|
this._channel = channel;
|
|
101
|
+
if (sqliteLayer) {
|
|
102
|
+
log.warn('Using testing SQLite layer');
|
|
103
|
+
}
|
|
104
|
+
this._runtime = ManagedRuntime.make(
|
|
105
|
+
SqlTransaction.layer
|
|
106
|
+
.pipe(Layer.provideMerge(sqliteLayer ?? LocalSqliteOpfsLayer), Layer.provideMerge(Reactivity.layer))
|
|
107
|
+
.pipe(Layer.orDie),
|
|
108
|
+
);
|
|
73
109
|
this._clientServices = new ClientServicesHost({
|
|
74
110
|
callbacks: {
|
|
75
111
|
onReset: async () => this.stop(),
|
|
76
112
|
},
|
|
113
|
+
runtime: this._runtime.runtimeEffect,
|
|
114
|
+
runtimeProps: {
|
|
115
|
+
// Auto-activate spaces that were previously active after leader changeover.
|
|
116
|
+
autoActivateSpaces: true,
|
|
117
|
+
},
|
|
77
118
|
});
|
|
119
|
+
this._automaticallyConnectWebrtc = automaticallyConnectWebrtc;
|
|
78
120
|
}
|
|
79
121
|
|
|
80
122
|
get host() {
|
|
81
123
|
return this._clientServices;
|
|
82
124
|
}
|
|
83
125
|
|
|
126
|
+
get livenessLockKey(): string {
|
|
127
|
+
return this._livenessLock.key;
|
|
128
|
+
}
|
|
129
|
+
|
|
84
130
|
async start(): Promise<void> {
|
|
85
131
|
log('starting...');
|
|
86
132
|
try {
|
|
133
|
+
log('worker-runtime: acquiring liveness lock (background)');
|
|
134
|
+
void this._livenessLock.acquire();
|
|
135
|
+
|
|
136
|
+
// Steal the lock from the other worker.
|
|
137
|
+
log('worker-runtime: broadcasting stop to displace previous worker');
|
|
87
138
|
this._broadcastChannel = new BroadcastChannel(this._channel);
|
|
88
139
|
this._broadcastChannel.postMessage({ action: 'stop' });
|
|
89
140
|
this._broadcastChannel.onmessage = async (event) => {
|
|
90
141
|
if (event.data?.action === 'stop') {
|
|
142
|
+
log('worker-runtime: received stop broadcast');
|
|
91
143
|
await this.stop();
|
|
92
144
|
}
|
|
93
145
|
};
|
|
94
146
|
|
|
147
|
+
log('worker-runtime: acquiring storage lock');
|
|
95
148
|
await this._acquireLock();
|
|
149
|
+
log('worker-runtime: storage lock acquired, resolving config');
|
|
96
150
|
this._config = await this._configProvider();
|
|
151
|
+
log('worker-runtime: config resolved');
|
|
152
|
+
this._signalTelemetryEnabled = this._config.get('runtime.client.signalTelemetryEnabled') ?? false;
|
|
153
|
+
const observabilityGroup = this._config.get('runtime.client.observabilityGroup');
|
|
154
|
+
if (observabilityGroup) {
|
|
155
|
+
this._signalMetadataTags.group = observabilityGroup;
|
|
156
|
+
}
|
|
97
157
|
const signals = this._config.get('runtime.services.signaling');
|
|
158
|
+
log('worker-runtime: initializing client services host');
|
|
98
159
|
this._clientServices.initialize({
|
|
99
160
|
config: this._config,
|
|
100
161
|
signalManager: this._config.get('runtime.client.edgeFeatures')?.signaling
|
|
@@ -104,8 +165,10 @@ export class WorkerRuntime {
|
|
|
104
165
|
: new MemorySignalManager(new MemorySignalManagerContext()), // TODO(dmaretskyi): Inject this context.
|
|
105
166
|
transportFactory: this._transportFactory,
|
|
106
167
|
});
|
|
168
|
+
log('worker-runtime: client services host initialized, opening');
|
|
107
169
|
|
|
108
170
|
await this._clientServices.open(new Context());
|
|
171
|
+
log('worker-runtime: client services host opened, signalling ready');
|
|
109
172
|
this._ready.wake(undefined);
|
|
110
173
|
log('started');
|
|
111
174
|
setIdentityTags({
|
|
@@ -126,14 +189,40 @@ export class WorkerRuntime {
|
|
|
126
189
|
this._releaseLock();
|
|
127
190
|
this._broadcastChannel?.close();
|
|
128
191
|
this._broadcastChannel = undefined;
|
|
129
|
-
await this._clientServices.close();
|
|
192
|
+
await this._clientServices.close(Context.default());
|
|
193
|
+
await this._runtime.dispose();
|
|
130
194
|
await this._onStop?.();
|
|
195
|
+
await this._livenessLock.release();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Update signaling telemetry tags from a client-supplied config overlay.
|
|
200
|
+
*
|
|
201
|
+
* The worker services outlive individual client connections, so the first client seeds the
|
|
202
|
+
* worker's core config (storage, signaling, edge features). For fields that can legitimately
|
|
203
|
+
* differ per tab — `observabilityGroup` and `signalTelemetryEnabled` — this method lets later
|
|
204
|
+
* connections refresh the signal metadata the worker attaches to its signaling requests
|
|
205
|
+
* (last-writer-wins, matching the pre-DX-930 per-session RPC behaviour).
|
|
206
|
+
*/
|
|
207
|
+
updateSignalMetadata(config: Config): void {
|
|
208
|
+
const observabilityGroup = config.get('runtime.client.observabilityGroup');
|
|
209
|
+
if (observabilityGroup) {
|
|
210
|
+
this._signalMetadataTags.group = observabilityGroup;
|
|
211
|
+
} else {
|
|
212
|
+
// Clear stale group so a later config that removes observabilityGroup stops attributing
|
|
213
|
+
// telemetry to the previous client's group (last-writer-wins).
|
|
214
|
+
delete this._signalMetadataTags.group;
|
|
215
|
+
}
|
|
216
|
+
const signalTelemetryEnabled = config.get('runtime.client.signalTelemetryEnabled');
|
|
217
|
+
if (signalTelemetryEnabled !== undefined) {
|
|
218
|
+
this._signalTelemetryEnabled = signalTelemetryEnabled;
|
|
219
|
+
}
|
|
131
220
|
}
|
|
132
221
|
|
|
133
222
|
/**
|
|
134
223
|
* Create a new session.
|
|
135
224
|
*/
|
|
136
|
-
async createSession({ appPort, systemPort, shellPort }:
|
|
225
|
+
async createSession({ appPort, systemPort, shellPort, onClose }: CreateSessionProps): Promise<WorkerSession> {
|
|
137
226
|
const session = new WorkerSession({
|
|
138
227
|
serviceHost: this._clientServices,
|
|
139
228
|
appPort,
|
|
@@ -149,8 +238,11 @@ export class WorkerRuntime {
|
|
|
149
238
|
// Terminate the worker when all sessions are closed.
|
|
150
239
|
await this.stop();
|
|
151
240
|
} else {
|
|
152
|
-
this.
|
|
241
|
+
if (this._automaticallyConnectWebrtc) {
|
|
242
|
+
this._reconnectWebrtc();
|
|
243
|
+
}
|
|
153
244
|
}
|
|
245
|
+
await onClose?.();
|
|
154
246
|
});
|
|
155
247
|
|
|
156
248
|
await session.open();
|
|
@@ -159,14 +251,27 @@ export class WorkerRuntime {
|
|
|
159
251
|
!this._signalMetadataTags.origin || this._signalMetadataTags.origin === session.origin,
|
|
160
252
|
`worker origin changed from ${this._signalMetadataTags.origin} to ${session.origin}?`,
|
|
161
253
|
);
|
|
162
|
-
if (session.observabilityGroup) {
|
|
163
|
-
this._signalMetadataTags.group = session.observabilityGroup;
|
|
164
|
-
}
|
|
165
|
-
this._signalTelemetryEnabled = session.signalTelemetryEnabled ?? false;
|
|
166
254
|
this._signalMetadataTags.origin = session.origin;
|
|
167
255
|
this._sessions.add(session);
|
|
168
256
|
|
|
169
|
-
this.
|
|
257
|
+
if (this._automaticallyConnectWebrtc) {
|
|
258
|
+
this._reconnectWebrtc();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return session;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Connects the WebRTC bridge to the specified session.
|
|
266
|
+
* If no session is provided, disconnects the WebRTC bridge.
|
|
267
|
+
*
|
|
268
|
+
* Called automatically if `automaticallyConnectWebrtc` is true.
|
|
269
|
+
*
|
|
270
|
+
* @param session The session to connect the WebRTC bridge to.
|
|
271
|
+
*/
|
|
272
|
+
connectWebrtcBridge(session: WorkerSession | undefined): void {
|
|
273
|
+
this._sessionForNetworking = session;
|
|
274
|
+
this._transportFactory.setBridgeService(session?.bridgeService);
|
|
170
275
|
}
|
|
171
276
|
|
|
172
277
|
/**
|
|
@@ -184,12 +289,78 @@ export class WorkerRuntime {
|
|
|
184
289
|
// Select existing session.
|
|
185
290
|
if (!this._sessionForNetworking) {
|
|
186
291
|
const selected = Array.from(this._sessions).find((session) => session.bridgeService);
|
|
187
|
-
|
|
188
|
-
this._sessionForNetworking = selected;
|
|
189
|
-
this._transportFactory.setBridgeService(selected.bridgeService);
|
|
190
|
-
} else {
|
|
191
|
-
this._transportFactory.setBridgeService(undefined);
|
|
192
|
-
}
|
|
292
|
+
this.connectWebrtcBridge(selected);
|
|
193
293
|
}
|
|
194
294
|
}
|
|
195
295
|
}
|
|
296
|
+
|
|
297
|
+
const DB_NAME = 'DXOS';
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* SqlExport layer that wraps SqliteClient to provide export functionality.
|
|
301
|
+
*/
|
|
302
|
+
const SqlExportLayer: Layer.Layer<SqlExport.SqlExport, never, SqliteClient.SqliteClient> = Layer.effect(
|
|
303
|
+
SqlExport.SqlExport,
|
|
304
|
+
Effect.gen(function* () {
|
|
305
|
+
const sql = yield* SqliteClient.SqliteClient;
|
|
306
|
+
return {
|
|
307
|
+
export: sql.export,
|
|
308
|
+
} satisfies SqlExport.Service;
|
|
309
|
+
}),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Local SQLite layer for the worker.
|
|
314
|
+
* Uses OPFS sync API as an FS backend.
|
|
315
|
+
* Does NOT spawn a new worker.
|
|
316
|
+
* NOTE: Only usable within a worker.
|
|
317
|
+
* TODO(mykola): This does not work right now. Fix.
|
|
318
|
+
*/
|
|
319
|
+
const LocalSqliteOpfsLayer = Layer.unwrapScoped(
|
|
320
|
+
Effect.gen(function* () {
|
|
321
|
+
const { port1: clientPort, port2: serverPort } = new MessageChannel();
|
|
322
|
+
clientPort.start();
|
|
323
|
+
serverPort.start();
|
|
324
|
+
yield* Effect.addFinalizer(() =>
|
|
325
|
+
Effect.sync(() => {
|
|
326
|
+
clientPort.close();
|
|
327
|
+
serverPort.close();
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
yield* Effect.forkScoped(OpfsWorker.run({ port: serverPort, dbName: DB_NAME }));
|
|
332
|
+
return SqlExportLayer.pipe(Layer.provideMerge(SqliteClient.layer({ worker: Effect.succeed(clientPort) })));
|
|
333
|
+
}),
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
// TODO(wittjosiah): Factor out to a separate module.
|
|
337
|
+
class WebLockWrapper {
|
|
338
|
+
readonly #key: string;
|
|
339
|
+
#release?: () => void;
|
|
340
|
+
|
|
341
|
+
constructor(key: string) {
|
|
342
|
+
this.#key = key;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
get key(): string {
|
|
346
|
+
return this.#key;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
acquire(options: LockOptions = {}) {
|
|
350
|
+
return navigator.locks.request(this.#key, options, async () => {
|
|
351
|
+
await new Promise<void>((resolve) => {
|
|
352
|
+
this.#release = resolve;
|
|
353
|
+
}); // Blocks for the duration of the worker's lifetime.
|
|
354
|
+
this.#release = undefined;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
release() {
|
|
359
|
+
this.#release?.();
|
|
360
|
+
this.#release = undefined;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
[Symbol.dispose]() {
|
|
364
|
+
this.release();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
@@ -15,9 +15,9 @@ import { type BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
|
15
15
|
import { type ProtoRpcPeer, type RpcPort, createProtoRpcPeer } from '@dxos/rpc';
|
|
16
16
|
import { Callback, type MaybePromise } from '@dxos/util';
|
|
17
17
|
|
|
18
|
-
import { ClientRpcServer, type
|
|
18
|
+
import { ClientRpcServer, type ClientRpcServerProps, type ClientServicesHost } from '../services';
|
|
19
19
|
|
|
20
|
-
export type
|
|
20
|
+
export type WorkerSessionProps = {
|
|
21
21
|
serviceHost: ClientServicesHost;
|
|
22
22
|
systemPort: RpcPort;
|
|
23
23
|
appPort: RpcPort;
|
|
@@ -41,35 +41,31 @@ export class WorkerSession {
|
|
|
41
41
|
@logInfo
|
|
42
42
|
public origin?: string;
|
|
43
43
|
|
|
44
|
-
// TODO(nf): factor out?
|
|
45
|
-
public observabilityGroup?: string;
|
|
46
|
-
public signalTelemetryEnabled?: boolean;
|
|
47
|
-
|
|
48
44
|
@logInfo
|
|
49
45
|
public lockKey?: string;
|
|
50
46
|
|
|
51
47
|
public bridgeService?: BridgeService;
|
|
52
48
|
|
|
53
|
-
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }:
|
|
49
|
+
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }: WorkerSessionProps) {
|
|
54
50
|
invariant(serviceHost);
|
|
55
51
|
this._serviceHost = serviceHost;
|
|
56
52
|
|
|
57
|
-
const middleware: Pick<
|
|
58
|
-
handleCall: async (method, params, handler) => {
|
|
53
|
+
const middleware: Pick<ClientRpcServerProps, 'handleCall' | 'handleStream'> = {
|
|
54
|
+
handleCall: async (method, params, handler, options) => {
|
|
59
55
|
const error = await readySignal.wait({ timeout: PROXY_CONNECTION_TIMEOUT });
|
|
60
56
|
if (error) {
|
|
61
57
|
throw error;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
return handler(method, params);
|
|
60
|
+
return handler(method, params, options);
|
|
65
61
|
},
|
|
66
|
-
handleStream: async (method, params, handler) => {
|
|
62
|
+
handleStream: async (method, params, handler, options) => {
|
|
67
63
|
const error = await readySignal.wait({ timeout: PROXY_CONNECTION_TIMEOUT });
|
|
68
64
|
if (error) {
|
|
69
65
|
throw error;
|
|
70
66
|
}
|
|
71
67
|
|
|
72
|
-
return handler(method, params);
|
|
68
|
+
return handler(method, params, options);
|
|
73
69
|
},
|
|
74
70
|
};
|
|
75
71
|
|
|
@@ -95,8 +91,6 @@ export class WorkerSession {
|
|
|
95
91
|
start: async (request) => {
|
|
96
92
|
this.origin = request.origin;
|
|
97
93
|
this.lockKey = request.lockKey;
|
|
98
|
-
this.observabilityGroup = request.observabilityGroup;
|
|
99
|
-
this.signalTelemetryEnabled = request.signalTelemetryEnabled;
|
|
100
94
|
this._startTrigger.wake();
|
|
101
95
|
},
|
|
102
96
|
|
|
@@ -119,7 +113,7 @@ export class WorkerSession {
|
|
|
119
113
|
}
|
|
120
114
|
|
|
121
115
|
async open(): Promise<void> {
|
|
122
|
-
log
|
|
116
|
+
log('opening...');
|
|
123
117
|
await Promise.all([this._clientRpc.open(), this._iframeRpc.open(), this._maybeOpenShell()]);
|
|
124
118
|
|
|
125
119
|
// Wait until the worker's RPC service has started.
|
|
@@ -130,11 +124,11 @@ export class WorkerSession {
|
|
|
130
124
|
void this._afterLockReleases(this.lockKey, () => this.close());
|
|
131
125
|
}
|
|
132
126
|
|
|
133
|
-
log
|
|
127
|
+
log('opened');
|
|
134
128
|
}
|
|
135
129
|
|
|
136
130
|
async close(): Promise<void> {
|
|
137
|
-
log.
|
|
131
|
+
log.debug('closing...');
|
|
138
132
|
try {
|
|
139
133
|
await this.onClose.callIfSet();
|
|
140
134
|
} catch (err: any) {
|
|
@@ -142,7 +136,7 @@ export class WorkerSession {
|
|
|
142
136
|
}
|
|
143
137
|
|
|
144
138
|
await Promise.all([this._clientRpc.close(), this._iframeRpc.close()]);
|
|
145
|
-
log.
|
|
139
|
+
log.debug('closed');
|
|
146
140
|
}
|
|
147
141
|
|
|
148
142
|
private async _maybeOpenShell(): Promise<void> {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "0.8.4-main.
|
|
1
|
+
export const DXOS_VERSION = "0.8.4-main.abd8ff62ef";
|