@dxos/client-services 0.3.11-main.bd26370 → 0.3.11-main.c244d7e

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.
Files changed (42) hide show
  1. package/dist/lib/browser/{chunk-X5Z3WL7N.mjs → chunk-XLOJ4YJA.mjs} +49 -28
  2. package/dist/lib/browser/chunk-XLOJ4YJA.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +42 -33
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-OLCLRX7U.cjs → chunk-ABS6362A.cjs} +49 -28
  9. package/dist/lib/node/chunk-ABS6362A.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +77 -68
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  14. package/dist/lib/node/packlets/testing/index.cjs.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +3 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  18. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +2 -0
  19. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  20. package/dist/types/src/packlets/vault/index.d.ts +1 -1
  21. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  22. package/dist/types/src/packlets/vault/{iframe-proxy-runtime.d.ts → shared-worker-connection.d.ts} +12 -5
  23. package/dist/types/src/packlets/vault/shared-worker-connection.d.ts.map +1 -0
  24. package/dist/types/src/packlets/vault/worker-runtime.d.ts +10 -3
  25. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  26. package/dist/types/src/packlets/vault/worker-session.d.ts +2 -2
  27. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  28. package/dist/types/src/version.d.ts +1 -1
  29. package/package.json +35 -35
  30. package/src/packlets/identity/identity-service.test.ts +1 -1
  31. package/src/packlets/identity/identity-service.ts +6 -3
  32. package/src/packlets/invitations/invitations-handler.ts +1 -1
  33. package/src/packlets/services/service-host.ts +27 -12
  34. package/src/packlets/vault/iframe-host-runtime.ts +2 -0
  35. package/src/packlets/vault/index.ts +1 -1
  36. package/src/packlets/vault/{iframe-proxy-runtime.ts → shared-worker-connection.ts} +18 -6
  37. package/src/packlets/vault/worker-runtime.ts +27 -9
  38. package/src/packlets/vault/worker-session.ts +11 -8
  39. package/src/version.ts +1 -1
  40. package/dist/lib/browser/chunk-X5Z3WL7N.mjs.map +0 -7
  41. package/dist/lib/node/chunk-OLCLRX7U.cjs.map +0 -7
  42. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +0 -1
@@ -18,7 +18,13 @@ import { ClientServicesHost } from '../services';
18
18
  export type CreateSessionParams = {
19
19
  appPort: RpcPort;
20
20
  systemPort: RpcPort;
21
- shellPort: RpcPort;
21
+ shellPort?: RpcPort;
22
+ };
23
+
24
+ export type WorkerRuntimeCallbacks = {
25
+ acquireLock: () => Promise<void>;
26
+ releaseLock: () => void;
27
+ onReset: () => Promise<void>;
22
28
  };
23
29
 
24
30
  /**
@@ -27,6 +33,8 @@ export type CreateSessionParams = {
27
33
  * Tabs make requests to the `ClientServicesHost`, and provide a WebRTC gateway.
28
34
  */
29
35
  export class WorkerRuntime {
36
+ private readonly _acquireLock: () => Promise<void>;
37
+ private readonly _releaseLock: () => void;
30
38
  private readonly _transportFactory = new SimplePeerTransportProxyFactory();
31
39
  private readonly _ready = new Trigger<Error | undefined>();
32
40
  private readonly _sessions = new Set<WorkerSession>();
@@ -34,12 +42,15 @@ export class WorkerRuntime {
34
42
  private _sessionForNetworking?: WorkerSession; // TODO(burdon): Expose to client QueryStatusResponse.
35
43
  private _config!: Config;
36
44
 
37
- constructor(private readonly _configProvider: () => MaybePromise<Config>) {
45
+ constructor(
46
+ private readonly _configProvider: () => MaybePromise<Config>,
47
+ { acquireLock, releaseLock, onReset }: WorkerRuntimeCallbacks,
48
+ ) {
49
+ this._acquireLock = acquireLock;
50
+ this._releaseLock = releaseLock;
38
51
  this._clientServices = new ClientServicesHost({
39
52
  callbacks: {
40
- onReset: async () => {
41
- self.close();
42
- },
53
+ onReset: async () => onReset(),
43
54
  },
44
55
  });
45
56
  }
@@ -51,6 +62,7 @@ export class WorkerRuntime {
51
62
  async start() {
52
63
  log('starting...');
53
64
  try {
65
+ await this._acquireLock();
54
66
  this._config = await this._configProvider();
55
67
  const signals = this._config.get('runtime.services.signaling');
56
68
  this._clientServices.initialize({
@@ -71,7 +83,8 @@ export class WorkerRuntime {
71
83
  }
72
84
 
73
85
  async stop() {
74
- // TODO(dmaretskyi): Terminate active sessions.
86
+ // Release the lock to notify remote clients that the worker is terminating.
87
+ this._releaseLock();
75
88
  await this._clientServices.close();
76
89
  }
77
90
 
@@ -87,10 +100,15 @@ export class WorkerRuntime {
87
100
  readySignal: this._ready,
88
101
  });
89
102
 
90
- // When tab is closed.
103
+ // When tab is closed or client is destroyed.
91
104
  session.onClose.set(async () => {
92
105
  this._sessions.delete(session);
93
- this._reconnectWebrtc();
106
+ if (this._sessions.size === 0) {
107
+ // Terminate the worker when all sessions are closed.
108
+ self.close();
109
+ } else {
110
+ this._reconnectWebrtc();
111
+ }
94
112
  });
95
113
 
96
114
  await session.open();
@@ -100,7 +118,7 @@ export class WorkerRuntime {
100
118
  }
101
119
 
102
120
  /**
103
- * Selects one of the existing session fro WebRTC networking.
121
+ * Selects one of the existing session for WebRTC networking.
104
122
  */
105
123
  private _reconnectWebrtc() {
106
124
  log('reconnecting webrtc...');
@@ -21,7 +21,8 @@ export type WorkerSessionParams = {
21
21
  serviceHost: ClientServicesHost;
22
22
  systemPort: RpcPort;
23
23
  appPort: RpcPort;
24
- shellPort: RpcPort;
24
+ // TODO(wittjosiah): Remove shellPort.
25
+ shellPort?: RpcPort;
25
26
  readySignal: Trigger<Error | undefined>;
26
27
  };
27
28
 
@@ -30,7 +31,7 @@ export type WorkerSessionParams = {
30
31
  */
31
32
  export class WorkerSession {
32
33
  private readonly _clientRpc: ClientRpcServer;
33
- private readonly _shellClientRpc: ClientRpcServer;
34
+ private readonly _shellClientRpc?: ClientRpcServer;
34
35
  private readonly _iframeRpc: ProtoRpcPeer<IframeServiceBundle>;
35
36
  private readonly _startTrigger = new Trigger();
36
37
  private readonly _serviceHost: ClientServicesHost;
@@ -74,11 +75,13 @@ export class WorkerSession {
74
75
  ...middleware,
75
76
  });
76
77
 
77
- this._shellClientRpc = new ClientRpcServer({
78
- serviceRegistry: this._serviceHost.serviceRegistry,
79
- port: shellPort,
80
- ...middleware,
81
- });
78
+ this._shellClientRpc = shellPort
79
+ ? new ClientRpcServer({
80
+ serviceRegistry: this._serviceHost.serviceRegistry,
81
+ port: shellPort,
82
+ ...middleware,
83
+ })
84
+ : undefined;
82
85
 
83
86
  this._iframeRpc = createProtoRpcPeer({
84
87
  requested: iframeServiceBundle,
@@ -138,7 +141,7 @@ export class WorkerSession {
138
141
 
139
142
  private async _maybeOpenShell() {
140
143
  try {
141
- await asyncTimeout(this._shellClientRpc.open(), 1_000);
144
+ this._shellClientRpc && (await asyncTimeout(this._shellClientRpc.open(), 1_000));
142
145
  } catch {
143
146
  log.info('No shell connected.');
144
147
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.3.11-main.bd26370";
1
+ export const DXOS_VERSION = "0.3.11-main.c244d7e";