@dxos/client-services 0.6.5 → 0.6.6-main.e1a6e1f
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-GIAH3RXX.mjs → chunk-DR3GOD3O.mjs} +907 -442
- package/dist/lib/browser/chunk-DR3GOD3O.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +28 -13
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +21 -4
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-NDXK2NIM.cjs → chunk-DRNEKKQP.cjs} +1065 -607
- package/dist/lib/node/chunk-DRNEKKQP.cjs.map +7 -0
- package/dist/lib/node/index.cjs +77 -62
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +27 -8
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +6 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +1 -0
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +29 -12
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +7 -0
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +35 -0
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/index.d.ts +1 -0
- package/dist/types/src/packlets/spaces/index.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +2 -0
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +3 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +8 -3
- package/dist/types/src/packlets/worker/worker-runtime.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/package.json +38 -36
- package/src/packlets/invitations/invitations-handler.test.ts +1 -0
- package/src/packlets/invitations/invitations-handler.ts +12 -0
- package/src/packlets/invitations/space-invitation-protocol.test.ts +23 -1
- package/src/packlets/services/service-context.ts +44 -12
- package/src/packlets/services/service-host.ts +26 -4
- package/src/packlets/spaces/data-space-manager.test.ts +6 -0
- package/src/packlets/spaces/data-space-manager.ts +80 -36
- package/src/packlets/spaces/data-space.ts +36 -2
- package/src/packlets/spaces/edge-feed-replicator.ts +249 -0
- package/src/packlets/spaces/index.ts +1 -0
- package/src/packlets/testing/invitation-utils.ts +2 -2
- package/src/packlets/testing/test-builder.ts +20 -12
- package/src/packlets/worker/worker-runtime.ts +32 -10
- package/src/version.ts +1 -5
- package/dist/lib/browser/chunk-GIAH3RXX.mjs.map +0 -7
- package/dist/lib/node/chunk-NDXK2NIM.cjs.map +0 -7
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Trigger } from '@dxos/async';
|
|
6
|
+
import { DEFAULT_WORKER_BROADCAST_CHANNEL } from '@dxos/client-protocol';
|
|
6
7
|
import { type Config } from '@dxos/config';
|
|
7
8
|
import { Context } from '@dxos/context';
|
|
8
9
|
import { invariant } from '@dxos/invariant';
|
|
@@ -27,10 +28,12 @@ export type CreateSessionParams = {
|
|
|
27
28
|
shellPort?: RpcPort;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
export type
|
|
31
|
+
export type WorkerRuntimeOptions = {
|
|
32
|
+
channel?: string;
|
|
33
|
+
configProvider: () => MaybePromise<Config>;
|
|
31
34
|
acquireLock: () => Promise<void>;
|
|
32
35
|
releaseLock: () => void;
|
|
33
|
-
|
|
36
|
+
onStop?: () => Promise<void>;
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
/**
|
|
@@ -39,26 +42,36 @@ export type WorkerRuntimeCallbacks = {
|
|
|
39
42
|
* Tabs make requests to the `ClientServicesHost`, and provide a WebRTC gateway.
|
|
40
43
|
*/
|
|
41
44
|
export class WorkerRuntime {
|
|
45
|
+
private readonly _configProvider: () => MaybePromise<Config>;
|
|
42
46
|
private readonly _acquireLock: () => Promise<void>;
|
|
43
47
|
private readonly _releaseLock: () => void;
|
|
48
|
+
private readonly _onStop?: () => Promise<void>;
|
|
44
49
|
private readonly _transportFactory = new SimplePeerTransportProxyFactory();
|
|
45
50
|
private readonly _ready = new Trigger<Error | undefined>();
|
|
46
51
|
private readonly _sessions = new Set<WorkerSession>();
|
|
47
52
|
private readonly _clientServices!: ClientServicesHost;
|
|
53
|
+
private readonly _channel: string;
|
|
54
|
+
private _broadcastChannel?: BroadcastChannel;
|
|
48
55
|
private _sessionForNetworking?: WorkerSession; // TODO(burdon): Expose to client QueryStatusResponse.
|
|
49
56
|
private _config!: Config;
|
|
50
57
|
private _signalMetadataTags: any = { runtime: 'worker-runtime' };
|
|
51
58
|
private _signalTelemetryEnabled: boolean = false;
|
|
52
59
|
|
|
53
|
-
constructor(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
constructor({
|
|
61
|
+
channel = DEFAULT_WORKER_BROADCAST_CHANNEL,
|
|
62
|
+
configProvider,
|
|
63
|
+
acquireLock,
|
|
64
|
+
releaseLock,
|
|
65
|
+
onStop,
|
|
66
|
+
}: WorkerRuntimeOptions) {
|
|
67
|
+
this._configProvider = configProvider;
|
|
57
68
|
this._acquireLock = acquireLock;
|
|
58
69
|
this._releaseLock = releaseLock;
|
|
70
|
+
this._onStop = onStop;
|
|
71
|
+
this._channel = channel;
|
|
59
72
|
this._clientServices = new ClientServicesHost({
|
|
60
73
|
callbacks: {
|
|
61
|
-
onReset: async () =>
|
|
74
|
+
onReset: async () => this.stop(),
|
|
62
75
|
},
|
|
63
76
|
});
|
|
64
77
|
}
|
|
@@ -70,6 +83,14 @@ export class WorkerRuntime {
|
|
|
70
83
|
async start() {
|
|
71
84
|
log('starting...');
|
|
72
85
|
try {
|
|
86
|
+
this._broadcastChannel = new BroadcastChannel(this._channel);
|
|
87
|
+
this._broadcastChannel.postMessage({ action: 'stop' });
|
|
88
|
+
this._broadcastChannel.onmessage = async (event) => {
|
|
89
|
+
if (event.data?.action === 'stop') {
|
|
90
|
+
await this.stop();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
73
94
|
await this._acquireLock();
|
|
74
95
|
this._config = await this._configProvider();
|
|
75
96
|
const signals = this._config.get('runtime.services.signaling');
|
|
@@ -100,7 +121,10 @@ export class WorkerRuntime {
|
|
|
100
121
|
async stop() {
|
|
101
122
|
// Release the lock to notify remote clients that the worker is terminating.
|
|
102
123
|
this._releaseLock();
|
|
124
|
+
this._broadcastChannel?.close();
|
|
125
|
+
this._broadcastChannel = undefined;
|
|
103
126
|
await this._clientServices.close();
|
|
127
|
+
await this._onStop?.();
|
|
104
128
|
}
|
|
105
129
|
|
|
106
130
|
/**
|
|
@@ -120,9 +144,7 @@ export class WorkerRuntime {
|
|
|
120
144
|
this._sessions.delete(session);
|
|
121
145
|
if (this._sessions.size === 0) {
|
|
122
146
|
// Terminate the worker when all sessions are closed.
|
|
123
|
-
|
|
124
|
-
self.close();
|
|
125
|
-
}
|
|
147
|
+
await this.stop();
|
|
126
148
|
} else {
|
|
127
149
|
this._reconnectWebrtc();
|
|
128
150
|
}
|
package/src/version.ts
CHANGED