@dxos/client-services 0.1.49 → 0.1.50-next.1bfebf8

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 (35) hide show
  1. package/dist/lib/browser/{chunk-YLH4UYUT.mjs → chunk-UL74TKNZ.mjs} +497 -1095
  2. package/dist/lib/browser/chunk-UL74TKNZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +601 -9
  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/node/index.cjs +1098 -1158
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +238 -726
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/index.d.ts +1 -0
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/packlets/locks/browser.d.ts +16 -0
  15. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -0
  16. package/dist/types/src/packlets/locks/index.d.ts +3 -0
  17. package/dist/types/src/packlets/locks/index.d.ts.map +1 -0
  18. package/dist/types/src/packlets/locks/node.d.ts +13 -0
  19. package/dist/types/src/packlets/locks/node.d.ts.map +1 -0
  20. package/dist/types/src/packlets/locks/resource-lock.d.ts +16 -0
  21. package/dist/types/src/packlets/locks/resource-lock.d.ts.map +1 -0
  22. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  23. package/dist/types/src/packlets/vault/index.d.ts +0 -1
  24. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  25. package/package.json +33 -30
  26. package/src/index.ts +1 -0
  27. package/src/packlets/{vault/vault-resource-lock.ts → locks/browser.ts} +12 -11
  28. package/src/packlets/locks/index.ts +6 -0
  29. package/src/packlets/locks/node.ts +52 -0
  30. package/src/packlets/locks/resource-lock.ts +24 -0
  31. package/src/packlets/services/service-host.ts +13 -13
  32. package/src/packlets/vault/index.ts +0 -1
  33. package/dist/lib/browser/chunk-YLH4UYUT.mjs.map +0 -7
  34. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +0 -20
  35. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +0 -1
@@ -6,27 +6,22 @@ import {
6
6
  DeviceInvitationProtocol,
7
7
  DevtoolsHostEvents,
8
8
  DevtoolsServiceImpl,
9
- IFrameHostRuntime,
10
- IFrameProxyRuntime,
11
9
  Identity,
12
10
  IdentityManager,
13
11
  IdentityServiceImpl,
14
12
  InvitationsHandler,
15
13
  InvitationsServiceImpl,
16
14
  LocalClientServices,
17
- MemoryShellRuntime,
15
+ Lock,
18
16
  ServiceContext,
19
17
  ServiceRegistry,
20
- ShellRuntimeImpl,
21
18
  SpaceInvitationProtocol,
22
19
  SpacesServiceImpl,
23
20
  TrustedKeySetAuthVerifier,
24
- VaultResourceLock,
25
- WorkerRuntime,
26
- WorkerSession,
27
21
  createAuthProvider,
28
22
  createStorageObjects,
29
23
  getNetworkPeers,
24
+ isLocked,
30
25
  subscribeToFeedBlocks,
31
26
  subscribeToFeeds,
32
27
  subscribeToNetworkStatus,
@@ -34,7 +29,603 @@ import {
34
29
  subscribeToSignal,
35
30
  subscribeToSpaces,
36
31
  subscribeToSwarmInfo
37
- } from "./chunk-YLH4UYUT.mjs";
32
+ } from "./chunk-UL74TKNZ.mjs";
33
+
34
+ // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
35
+ import { Trigger } from "@dxos/async";
36
+ import { PROXY_CONNECTION_TIMEOUT } from "@dxos/client-protocol";
37
+ import { log, logInfo } from "@dxos/log";
38
+ import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
39
+ import { createWebRTCTransportFactory } from "@dxos/network-manager";
40
+ import { getAsyncValue } from "@dxos/util";
41
+
42
+ // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
43
+ import { Stream } from "@dxos/codec-protobuf";
44
+ import { raise } from "@dxos/debug";
45
+ import { parseMethodName, RpcPeer } from "@dxos/rpc";
46
+ var ClientRpcServer = class {
47
+ constructor(params) {
48
+ this._handlerCache = /* @__PURE__ */ new Map();
49
+ const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
50
+ this._handleCall = handleCall;
51
+ this._handleStream = handleStream;
52
+ this._serviceRegistry = serviceRegistry;
53
+ this._rpcPeer = new RpcPeer({
54
+ ...rpcOptions,
55
+ callHandler: (method, params2) => {
56
+ const [serviceName, methodName] = parseMethodName(method);
57
+ const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
58
+ if (this._handleCall) {
59
+ return this._handleCall(methodName, params2, handler);
60
+ } else {
61
+ return handler(methodName, params2);
62
+ }
63
+ },
64
+ streamHandler: (method, params2) => {
65
+ const [serviceName, methodName] = parseMethodName(method);
66
+ const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
67
+ if (this._handleStream) {
68
+ return Stream.unwrapPromise(this._handleStream(methodName, params2, handler));
69
+ } else {
70
+ return handler(methodName, params2);
71
+ }
72
+ }
73
+ });
74
+ }
75
+ async open() {
76
+ await this._rpcPeer.open();
77
+ }
78
+ async close() {
79
+ await this._rpcPeer.close();
80
+ }
81
+ _getServiceHandler(serviceName) {
82
+ var _a;
83
+ if (!this._handlerCache.has(serviceName)) {
84
+ const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : raise(new Error(`Service not available: ${serviceName}`));
85
+ const service = this._serviceRegistry.services[key];
86
+ if (!service) {
87
+ throw new Error(`Service not available: ${serviceName}`);
88
+ }
89
+ this._handlerCache.set(serviceName, descriptor.createServer(service));
90
+ }
91
+ return this._handlerCache.get(serviceName);
92
+ }
93
+ };
94
+
95
+ // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
96
+ import assert from "@dxos/node-std/assert";
97
+ import { Event } from "@dxos/async";
98
+ import { appServiceBundle, shellServiceBundle } from "@dxos/client-protocol";
99
+ import { ShellLayout } from "@dxos/protocols/proto/dxos/iframe";
100
+ import { createProtoRpcPeer } from "@dxos/rpc";
101
+ var ShellRuntimeImpl = class {
102
+ constructor(_port) {
103
+ this._port = _port;
104
+ this.layoutUpdate = new Event();
105
+ this._layout = ShellLayout.DEFAULT;
106
+ }
107
+ get layout() {
108
+ return this._layout;
109
+ }
110
+ get invitationCode() {
111
+ return this._invitationCode;
112
+ }
113
+ get spaceKey() {
114
+ return this._spaceKey;
115
+ }
116
+ setLayout(layout, options = {}) {
117
+ this._layout = layout;
118
+ this._invitationCode = options.invitationCode;
119
+ this._spaceKey = options.spaceKey;
120
+ this.layoutUpdate.emit({
121
+ layout,
122
+ ...options
123
+ });
124
+ }
125
+ async setAppContext(context) {
126
+ assert(this._appRpc, "runtime not open");
127
+ await this._appRpc.rpc.AppService.setContext(context);
128
+ }
129
+ async open() {
130
+ this._appRpc = createProtoRpcPeer({
131
+ requested: appServiceBundle,
132
+ exposed: shellServiceBundle,
133
+ handlers: {
134
+ ShellService: {
135
+ setLayout: async (request) => {
136
+ this._layout = request.layout;
137
+ this._invitationCode = request.invitationCode;
138
+ this._spaceKey = request.spaceKey;
139
+ this.layoutUpdate.emit(request);
140
+ }
141
+ }
142
+ },
143
+ port: this._port
144
+ });
145
+ await this._appRpc.open();
146
+ }
147
+ async close() {
148
+ var _a;
149
+ await ((_a = this._appRpc) == null ? void 0 : _a.close());
150
+ this._appRpc = void 0;
151
+ }
152
+ };
153
+ var MemoryShellRuntime = class {
154
+ constructor({ layout, invitationCode, spaceKey } = {}) {
155
+ this.layoutUpdate = new Event();
156
+ this.contextUpdate = new Event();
157
+ this._layout = layout != null ? layout : ShellLayout.DEFAULT;
158
+ this._invitationCode = invitationCode;
159
+ this._spaceKey = spaceKey;
160
+ }
161
+ get layout() {
162
+ return this._layout;
163
+ }
164
+ get invitationCode() {
165
+ return this._invitationCode;
166
+ }
167
+ get spaceKey() {
168
+ return this._spaceKey;
169
+ }
170
+ setLayout(layout, options = {}) {
171
+ this._layout = layout;
172
+ this._invitationCode = options.invitationCode;
173
+ this._spaceKey = options.spaceKey;
174
+ this.layoutUpdate.emit({
175
+ layout,
176
+ ...options
177
+ });
178
+ }
179
+ async setAppContext(context) {
180
+ this.contextUpdate.emit(context);
181
+ }
182
+ };
183
+
184
+ // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
185
+ var __decorate = function(decorators, target, key, desc) {
186
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
187
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
188
+ r = Reflect.decorate(decorators, target, key, desc);
189
+ else
190
+ for (var i = decorators.length - 1; i >= 0; i--)
191
+ if (d = decorators[i])
192
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
193
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
194
+ };
195
+ var LOCK_KEY = "DXOS_RESOURCE_LOCK";
196
+ var IFrameHostRuntime = class {
197
+ constructor({ config, origin, appPort, shellPort }) {
198
+ this._ready = new Trigger();
199
+ this._configProvider = config;
200
+ this.origin = origin;
201
+ this._appPort = appPort;
202
+ this._shellPort = shellPort;
203
+ if (this._shellPort) {
204
+ this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
205
+ }
206
+ }
207
+ get services() {
208
+ return this._clientServices;
209
+ }
210
+ get shell() {
211
+ return this._shellRuntime;
212
+ }
213
+ async start() {
214
+ var _a;
215
+ log("starting...", {}, {
216
+ file: "iframe-host-runtime.ts",
217
+ line: 70,
218
+ scope: this,
219
+ callSite: (f, a) => f(...a)
220
+ });
221
+ try {
222
+ this._config = await getAsyncValue(this._configProvider);
223
+ this._transportFactory = createWebRTCTransportFactory({
224
+ iceServers: this._config.get("runtime.services.ice")
225
+ });
226
+ const signals = this._config.get("runtime.services.signaling");
227
+ this._clientServices = new LocalClientServices({
228
+ lockKey: LOCK_KEY,
229
+ config: this._config,
230
+ signalManager: signals ? new WebsocketSignalManager(signals) : new MemorySignalManager(new MemorySignalManagerContext()),
231
+ transportFactory: this._transportFactory
232
+ });
233
+ const middleware = {
234
+ handleCall: async (method, params, handler) => {
235
+ const error = await this._ready.wait({
236
+ timeout: PROXY_CONNECTION_TIMEOUT
237
+ });
238
+ if (error) {
239
+ throw error;
240
+ }
241
+ return handler(method, params);
242
+ },
243
+ handleStream: async (method, params, handler) => {
244
+ const error = await this._ready.wait({
245
+ timeout: PROXY_CONNECTION_TIMEOUT
246
+ });
247
+ if (error) {
248
+ throw error;
249
+ }
250
+ return handler(method, params);
251
+ }
252
+ };
253
+ this._clientRpc = new ClientRpcServer({
254
+ serviceRegistry: this._clientServices.host.serviceRegistry,
255
+ port: this._appPort,
256
+ ...middleware
257
+ });
258
+ await Promise.all([
259
+ this._clientServices.open(),
260
+ this._clientRpc.open(),
261
+ (_a = this._shellRuntime) == null ? void 0 : _a.open()
262
+ ]);
263
+ this._ready.wake(void 0);
264
+ log("started", {}, {
265
+ file: "iframe-host-runtime.ts",
266
+ line: 113,
267
+ scope: this,
268
+ callSite: (f, a) => f(...a)
269
+ });
270
+ } catch (err) {
271
+ this._ready.wake(err);
272
+ log.catch(err, {}, {
273
+ file: "iframe-host-runtime.ts",
274
+ line: 116,
275
+ scope: this,
276
+ callSite: (f, a) => f(...a)
277
+ });
278
+ }
279
+ }
280
+ async stop() {
281
+ var _a;
282
+ log("stopping...", {}, {
283
+ file: "iframe-host-runtime.ts",
284
+ line: 121,
285
+ scope: this,
286
+ callSite: (f, a) => f(...a)
287
+ });
288
+ await this._clientRpc.close();
289
+ await this._clientServices.close();
290
+ await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
291
+ log("stopped", {}, {
292
+ file: "iframe-host-runtime.ts",
293
+ line: 125,
294
+ scope: this,
295
+ callSite: (f, a) => f(...a)
296
+ });
297
+ }
298
+ };
299
+ __decorate([
300
+ logInfo
301
+ ], IFrameHostRuntime.prototype, "origin", void 0);
302
+
303
+ // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
304
+ import { Trigger as Trigger2 } from "@dxos/async";
305
+ import { iframeServiceBundle, workerServiceBundle } from "@dxos/client-protocol";
306
+ import { RemoteServiceConnectionError } from "@dxos/errors";
307
+ import { log as log2 } from "@dxos/log";
308
+ import { WebRTCTransportService } from "@dxos/network-manager";
309
+ import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
310
+ import { getAsyncValue as getAsyncValue2 } from "@dxos/util";
311
+ var IFrameProxyRuntime = class {
312
+ constructor({ config, systemPort, shellPort }) {
313
+ this._id = String(Math.floor(Math.random() * 1e6));
314
+ this._release = new Trigger2();
315
+ this._configProvider = config;
316
+ this._systemPort = systemPort;
317
+ this._shellPort = shellPort;
318
+ if (this._shellPort) {
319
+ this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
320
+ }
321
+ }
322
+ get shell() {
323
+ return this._shellRuntime;
324
+ }
325
+ async open(origin) {
326
+ var _a;
327
+ this._config = await getAsyncValue2(this._configProvider);
328
+ this._transportService = new WebRTCTransportService({
329
+ iceServers: this._config.get("runtime.services.ice")
330
+ });
331
+ this._systemRpc = createProtoRpcPeer2({
332
+ requested: workerServiceBundle,
333
+ exposed: iframeServiceBundle,
334
+ handlers: {
335
+ BridgeService: this._transportService
336
+ },
337
+ port: this._systemPort,
338
+ timeout: 200
339
+ });
340
+ let lockKey;
341
+ if (typeof navigator !== "undefined") {
342
+ lockKey = this._lockKey(origin);
343
+ this._release = new Trigger2();
344
+ const ready = new Trigger2();
345
+ void navigator.locks.request(lockKey, async () => {
346
+ ready.wake();
347
+ await this._release.wait();
348
+ });
349
+ await ready.wait();
350
+ }
351
+ try {
352
+ await this._systemRpc.open();
353
+ await this._systemRpc.rpc.WorkerService.start({
354
+ origin,
355
+ lockKey
356
+ });
357
+ } catch (err) {
358
+ log2.catch(err, {}, {
359
+ file: "iframe-proxy-runtime.ts",
360
+ line: 85,
361
+ scope: this,
362
+ callSite: (f, a) => f(...a)
363
+ });
364
+ throw new RemoteServiceConnectionError("Failed to connect to worker");
365
+ }
366
+ await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
367
+ }
368
+ async close() {
369
+ var _a;
370
+ this._release.wake();
371
+ await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
372
+ await this._systemRpc.rpc.WorkerService.stop();
373
+ await this._systemRpc.close();
374
+ }
375
+ _lockKey(origin) {
376
+ return `${origin}-${this._id}`;
377
+ }
378
+ };
379
+
380
+ // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
381
+ import { Trigger as Trigger4 } from "@dxos/async";
382
+ import { log as log4 } from "@dxos/log";
383
+ import { MemorySignalManager as MemorySignalManager2, MemorySignalManagerContext as MemorySignalManagerContext2, WebsocketSignalManager as WebsocketSignalManager2 } from "@dxos/messaging";
384
+ import { WebRTCTransportProxyFactory } from "@dxos/network-manager";
385
+
386
+ // packages/sdk/client-services/src/packlets/vault/worker-session.ts
387
+ import assert2 from "@dxos/node-std/assert";
388
+ import { asyncTimeout, Trigger as Trigger3 } from "@dxos/async";
389
+ import { iframeServiceBundle as iframeServiceBundle2, PROXY_CONNECTION_TIMEOUT as PROXY_CONNECTION_TIMEOUT2, workerServiceBundle as workerServiceBundle2 } from "@dxos/client-protocol";
390
+ import { log as log3, logInfo as logInfo2 } from "@dxos/log";
391
+ import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
392
+ import { Callback } from "@dxos/util";
393
+ var __decorate2 = function(decorators, target, key, desc) {
394
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
395
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
396
+ r = Reflect.decorate(decorators, target, key, desc);
397
+ else
398
+ for (var i = decorators.length - 1; i >= 0; i--)
399
+ if (d = decorators[i])
400
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
401
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
402
+ };
403
+ var WorkerSession = class {
404
+ constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
405
+ this._startTrigger = new Trigger3();
406
+ this.onClose = new Callback();
407
+ assert2(serviceHost);
408
+ this._serviceHost = serviceHost;
409
+ const middleware = {
410
+ handleCall: async (method, params, handler) => {
411
+ const error = await readySignal.wait({
412
+ timeout: PROXY_CONNECTION_TIMEOUT2
413
+ });
414
+ if (error) {
415
+ throw error;
416
+ }
417
+ return handler(method, params);
418
+ },
419
+ handleStream: async (method, params, handler) => {
420
+ const error = await readySignal.wait({
421
+ timeout: PROXY_CONNECTION_TIMEOUT2
422
+ });
423
+ if (error) {
424
+ throw error;
425
+ }
426
+ return handler(method, params);
427
+ }
428
+ };
429
+ this._clientRpc = new ClientRpcServer({
430
+ serviceRegistry: this._serviceHost.serviceRegistry,
431
+ port: appPort,
432
+ ...middleware
433
+ });
434
+ this._shellClientRpc = new ClientRpcServer({
435
+ serviceRegistry: this._serviceHost.serviceRegistry,
436
+ port: shellPort,
437
+ ...middleware
438
+ });
439
+ this._iframeRpc = createProtoRpcPeer3({
440
+ requested: iframeServiceBundle2,
441
+ exposed: workerServiceBundle2,
442
+ handlers: {
443
+ WorkerService: {
444
+ start: async (request) => {
445
+ this.origin = request.origin;
446
+ this.lockKey = request.lockKey;
447
+ this._startTrigger.wake();
448
+ },
449
+ stop: async () => {
450
+ setTimeout(async () => {
451
+ try {
452
+ await this.close();
453
+ } catch (err) {
454
+ log3.catch(err, {}, {
455
+ file: "worker-session.ts",
456
+ line: 100,
457
+ scope: this,
458
+ callSite: (f, a) => f(...a)
459
+ });
460
+ }
461
+ });
462
+ }
463
+ }
464
+ },
465
+ port: systemPort,
466
+ timeout: 1e3
467
+ });
468
+ this.bridgeService = this._iframeRpc.rpc.BridgeService;
469
+ }
470
+ async open() {
471
+ log3.info("opening..", {}, {
472
+ file: "worker-session.ts",
473
+ line: 114,
474
+ scope: this,
475
+ callSite: (f, a) => f(...a)
476
+ });
477
+ await Promise.all([
478
+ this._clientRpc.open(),
479
+ this._iframeRpc.open(),
480
+ this._maybeOpenShell()
481
+ ]);
482
+ await this._startTrigger.wait({
483
+ timeout: PROXY_CONNECTION_TIMEOUT2
484
+ });
485
+ if (this.lockKey) {
486
+ void this._afterLockReleases(this.lockKey, () => this.close());
487
+ }
488
+ }
489
+ async close() {
490
+ log3.info("closing..", {}, {
491
+ file: "worker-session.ts",
492
+ line: 124,
493
+ scope: this,
494
+ callSite: (f, a) => f(...a)
495
+ });
496
+ try {
497
+ await this.onClose.callIfSet();
498
+ } catch (err) {
499
+ log3.catch(err, {}, {
500
+ file: "worker-session.ts",
501
+ line: 128,
502
+ scope: this,
503
+ callSite: (f, a) => f(...a)
504
+ });
505
+ }
506
+ await Promise.all([
507
+ this._clientRpc.close(),
508
+ this._iframeRpc.close()
509
+ ]);
510
+ }
511
+ async _maybeOpenShell() {
512
+ try {
513
+ await asyncTimeout(this._shellClientRpc.open(), 1e3);
514
+ } catch (e) {
515
+ log3.info("No shell connected.", {}, {
516
+ file: "worker-session.ts",
517
+ line: 138,
518
+ scope: this,
519
+ callSite: (f, a) => f(...a)
520
+ });
521
+ }
522
+ }
523
+ _afterLockReleases(lockKey, callback) {
524
+ return navigator.locks.request(lockKey, () => {
525
+ }).then(callback);
526
+ }
527
+ };
528
+ __decorate2([
529
+ logInfo2
530
+ ], WorkerSession.prototype, "origin", void 0);
531
+ __decorate2([
532
+ logInfo2
533
+ ], WorkerSession.prototype, "lockKey", void 0);
534
+
535
+ // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
536
+ var WorkerRuntime = class {
537
+ // prettier-ignore
538
+ constructor(_configProvider) {
539
+ this._configProvider = _configProvider;
540
+ this._transportFactory = new WebRTCTransportProxyFactory();
541
+ this._ready = new Trigger4();
542
+ this.sessions = /* @__PURE__ */ new Set();
543
+ this._clientServices = new ClientServicesHost();
544
+ }
545
+ get host() {
546
+ return this._clientServices;
547
+ }
548
+ async start() {
549
+ log4("starting...", {}, {
550
+ file: "worker-runtime.ts",
551
+ line: 48,
552
+ scope: this,
553
+ callSite: (f, a) => f(...a)
554
+ });
555
+ try {
556
+ this._config = await this._configProvider();
557
+ const signals = this._config.get("runtime.services.signaling");
558
+ this._clientServices.initialize({
559
+ config: this._config,
560
+ signalManager: signals ? new WebsocketSignalManager2(signals) : new MemorySignalManager2(new MemorySignalManagerContext2()),
561
+ transportFactory: this._transportFactory
562
+ });
563
+ await this._clientServices.open();
564
+ this._ready.wake(void 0);
565
+ log4("started", {}, {
566
+ file: "worker-runtime.ts",
567
+ line: 62,
568
+ scope: this,
569
+ callSite: (f, a) => f(...a)
570
+ });
571
+ } catch (err) {
572
+ this._ready.wake(err);
573
+ log4.catch(err, {}, {
574
+ file: "worker-runtime.ts",
575
+ line: 65,
576
+ scope: this,
577
+ callSite: (f, a) => f(...a)
578
+ });
579
+ }
580
+ }
581
+ async stop() {
582
+ await this._clientServices.close();
583
+ }
584
+ /**
585
+ * Create a new session.
586
+ */
587
+ async createSession({ appPort, systemPort, shellPort }) {
588
+ const session = new WorkerSession({
589
+ serviceHost: this._clientServices,
590
+ appPort,
591
+ systemPort,
592
+ shellPort,
593
+ readySignal: this._ready
594
+ });
595
+ session.onClose.set(async () => {
596
+ this.sessions.delete(session);
597
+ this._reconnectWebrtc();
598
+ });
599
+ await session.open();
600
+ this.sessions.add(session);
601
+ this._reconnectWebrtc();
602
+ }
603
+ /**
604
+ * Selects one of the existing session fro WebRTC networking.
605
+ */
606
+ _reconnectWebrtc() {
607
+ log4("reconnecting webrtc...", {}, {
608
+ file: "worker-runtime.ts",
609
+ line: 102,
610
+ scope: this,
611
+ callSite: (f, a) => f(...a)
612
+ });
613
+ if (this._sessionForNetworking) {
614
+ if (!this.sessions.has(this._sessionForNetworking)) {
615
+ this._sessionForNetworking = void 0;
616
+ }
617
+ }
618
+ if (!this._sessionForNetworking) {
619
+ const selected = Array.from(this.sessions).find((session) => session.bridgeService);
620
+ if (selected) {
621
+ this._sessionForNetworking = selected;
622
+ this._transportFactory.setBridgeService(selected.bridgeService);
623
+ } else {
624
+ this._transportFactory.setBridgeService(void 0);
625
+ }
626
+ }
627
+ }
628
+ };
38
629
  export {
39
630
  ClientServicesHost,
40
631
  DataSpace,
@@ -50,6 +641,7 @@ export {
50
641
  InvitationsHandler,
51
642
  InvitationsServiceImpl,
52
643
  LocalClientServices,
644
+ Lock,
53
645
  MemoryShellRuntime,
54
646
  ServiceContext,
55
647
  ServiceRegistry,
@@ -57,12 +649,12 @@ export {
57
649
  SpaceInvitationProtocol,
58
650
  SpacesServiceImpl,
59
651
  TrustedKeySetAuthVerifier,
60
- VaultResourceLock,
61
652
  WorkerRuntime,
62
653
  WorkerSession,
63
654
  createAuthProvider,
64
655
  createStorageObjects,
65
656
  getNetworkPeers,
657
+ isLocked,
66
658
  subscribeToFeedBlocks,
67
659
  subscribeToFeeds,
68
660
  subscribeToNetworkStatus,