@dxos/client-services 0.1.2 → 0.1.4
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/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/packlets/deprecated/index.d.ts +5 -0
- package/dist/src/packlets/deprecated/index.d.ts.map +1 -0
- package/dist/src/packlets/{services/impl → deprecated}/index.js +1 -3
- package/dist/src/packlets/deprecated/index.js.map +1 -0
- package/dist/src/packlets/{invitations/common.d.ts → deprecated/invitations.d.ts} +14 -2
- package/dist/src/packlets/deprecated/invitations.d.ts.map +1 -0
- package/dist/src/packlets/{invitations/common.js → deprecated/invitations.js} +1 -1
- package/dist/src/packlets/deprecated/invitations.js.map +1 -0
- package/dist/src/packlets/{services/impl → deprecated}/profile.d.ts +5 -5
- package/dist/src/packlets/deprecated/profile.d.ts.map +1 -0
- package/dist/src/packlets/{services/impl → deprecated}/profile.js +10 -10
- package/dist/src/packlets/deprecated/profile.js.map +1 -0
- package/dist/src/packlets/deprecated/space.d.ts +23 -0
- package/dist/src/packlets/deprecated/space.d.ts.map +1 -0
- package/dist/src/packlets/deprecated/space.js +206 -0
- package/dist/src/packlets/deprecated/space.js.map +1 -0
- package/dist/src/packlets/{services/impl → deprecated}/system.d.ts +2 -2
- package/dist/src/packlets/deprecated/system.d.ts.map +1 -0
- package/dist/src/packlets/{services/impl → deprecated}/system.js +3 -3
- package/dist/src/packlets/deprecated/system.js.map +1 -0
- package/dist/src/packlets/deprecated/tracing.d.ts +12 -0
- package/dist/src/packlets/deprecated/tracing.d.ts.map +1 -0
- package/dist/src/packlets/{services/impl → deprecated}/tracing.js +3 -3
- package/dist/src/packlets/deprecated/tracing.js.map +1 -0
- package/dist/src/packlets/{services/impl → devtools}/devtools.d.ts +11 -7
- package/dist/src/packlets/devtools/devtools.d.ts.map +1 -0
- package/dist/src/packlets/devtools/devtools.js +86 -0
- package/dist/src/packlets/devtools/devtools.js.map +1 -0
- package/dist/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/src/packlets/devtools/feeds.js +28 -26
- package/dist/src/packlets/devtools/feeds.js.map +1 -1
- package/dist/src/packlets/devtools/index.d.ts +1 -1
- package/dist/src/packlets/devtools/index.d.ts.map +1 -1
- package/dist/src/packlets/devtools/index.js +1 -1
- package/dist/src/packlets/devtools/index.js.map +1 -1
- package/dist/src/packlets/devtools/spaces.d.ts +2 -2
- package/dist/src/packlets/devtools/spaces.d.ts.map +1 -1
- package/dist/src/packlets/devtools/spaces.js +13 -13
- package/dist/src/packlets/devtools/spaces.js.map +1 -1
- package/dist/src/packlets/identity/devices-service-impl.d.ts +10 -0
- package/dist/src/packlets/identity/devices-service-impl.d.ts.map +1 -0
- package/dist/src/packlets/identity/devices-service-impl.js +47 -0
- package/dist/src/packlets/identity/devices-service-impl.js.map +1 -0
- package/dist/src/packlets/identity/identity-manager.test.js +7 -11
- package/dist/src/packlets/identity/identity-manager.test.js.map +1 -1
- package/dist/src/packlets/identity/identity.d.ts +2 -0
- package/dist/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/src/packlets/identity/identity.js +4 -1
- package/dist/src/packlets/identity/identity.js.map +1 -1
- package/dist/src/packlets/identity/identity.test.js +2 -3
- package/dist/src/packlets/identity/identity.test.js.map +1 -1
- package/dist/src/packlets/invitations/encoder.d.ts +9 -0
- package/dist/src/packlets/invitations/encoder.d.ts.map +1 -0
- package/dist/src/packlets/invitations/encoder.js +27 -0
- package/dist/src/packlets/invitations/encoder.js.map +1 -0
- package/dist/src/packlets/invitations/encoder.test.d.ts +2 -0
- package/dist/src/packlets/invitations/encoder.test.d.ts.map +1 -0
- package/dist/src/packlets/invitations/encoder.test.js +19 -0
- package/dist/src/packlets/invitations/encoder.test.js.map +1 -0
- package/dist/src/packlets/invitations/halo-invitations.d.ts +3 -3
- package/dist/src/packlets/invitations/halo-invitations.d.ts.map +1 -1
- package/dist/src/packlets/invitations/halo-invitations.js +14 -10
- package/dist/src/packlets/invitations/halo-invitations.js.map +1 -1
- package/dist/src/packlets/invitations/halo-invitations.test.d.ts +2 -0
- package/dist/src/packlets/invitations/halo-invitations.test.d.ts.map +1 -0
- package/dist/src/packlets/{services/testing/halo.test.js → invitations/halo-invitations.test.js} +6 -6
- package/dist/src/packlets/invitations/halo-invitations.test.js.map +1 -0
- package/dist/src/packlets/invitations/index.d.ts +6 -3
- package/dist/src/packlets/invitations/index.d.ts.map +1 -1
- package/dist/src/packlets/invitations/index.js +6 -3
- package/dist/src/packlets/invitations/index.js.map +1 -1
- package/dist/src/packlets/invitations/invitations-proxy.d.ts +14 -0
- package/dist/src/packlets/invitations/invitations-proxy.d.ts.map +1 -0
- package/dist/src/packlets/invitations/invitations-proxy.js +126 -0
- package/dist/src/packlets/invitations/invitations-proxy.js.map +1 -0
- package/dist/src/packlets/invitations/invitations.d.ts +90 -0
- package/dist/src/packlets/invitations/invitations.d.ts.map +1 -0
- package/dist/src/packlets/invitations/invitations.js +55 -0
- package/dist/src/packlets/invitations/invitations.js.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-handler.d.ts +24 -0
- package/dist/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-handler.js +232 -0
- package/dist/src/packlets/invitations/space-invitations-handler.js.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-handler.test.d.ts +2 -0
- package/dist/src/packlets/invitations/space-invitations-handler.test.d.ts.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-handler.test.js +131 -0
- package/dist/src/packlets/invitations/space-invitations-handler.test.js.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-proxy.d.ts +11 -0
- package/dist/src/packlets/invitations/space-invitations-proxy.d.ts.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-proxy.js +17 -0
- package/dist/src/packlets/invitations/space-invitations-proxy.js.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-service.d.ts +22 -0
- package/dist/src/packlets/invitations/space-invitations-service.d.ts.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-service.js +189 -0
- package/dist/src/packlets/invitations/space-invitations-service.js.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-service.test.d.ts +2 -0
- package/dist/src/packlets/invitations/space-invitations-service.test.d.ts.map +1 -0
- package/dist/src/packlets/invitations/space-invitations-service.test.js +100 -0
- package/dist/src/packlets/invitations/space-invitations-service.test.js.map +1 -0
- package/dist/src/packlets/services/iframe-service-proxy.d.ts +23 -0
- package/dist/src/packlets/services/iframe-service-proxy.d.ts.map +1 -0
- package/dist/src/packlets/services/iframe-service-proxy.js +53 -0
- package/dist/src/packlets/services/iframe-service-proxy.js.map +1 -0
- package/dist/src/packlets/services/index.d.ts +3 -2
- package/dist/src/packlets/services/index.d.ts.map +1 -1
- package/dist/src/packlets/services/index.js +3 -2
- package/dist/src/packlets/services/index.js.map +1 -1
- package/dist/src/packlets/services/service-context.d.ts +4 -7
- package/dist/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/src/packlets/services/service-context.js +9 -25
- package/dist/src/packlets/services/service-context.js.map +1 -1
- package/dist/src/packlets/services/service-definitions.d.ts +30 -0
- package/dist/src/packlets/services/service-definitions.d.ts.map +1 -0
- package/dist/src/packlets/services/{services.js → service-definitions.js} +9 -5
- package/dist/src/packlets/services/service-definitions.js.map +1 -0
- package/dist/src/packlets/services/service-host.d.ts +9 -12
- package/dist/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/src/packlets/services/service-host.js +55 -54
- package/dist/src/packlets/services/service-host.js.map +1 -1
- package/dist/src/packlets/services/service-host.test.js +7 -17
- package/dist/src/packlets/services/service-host.test.js.map +1 -1
- package/dist/src/packlets/services/service-proxy.d.ts +17 -0
- package/dist/src/packlets/services/service-proxy.d.ts.map +1 -0
- package/dist/src/packlets/services/service-proxy.js +48 -0
- package/dist/src/packlets/services/service-proxy.js.map +1 -0
- package/dist/src/packlets/services/service-registry.d.ts +12 -0
- package/dist/src/packlets/services/service-registry.d.ts.map +1 -0
- package/dist/src/packlets/services/service-registry.js +24 -0
- package/dist/src/packlets/services/service-registry.js.map +1 -0
- package/dist/src/packlets/services/service-registry.test.d.ts +2 -0
- package/dist/src/packlets/services/service-registry.test.d.ts.map +1 -0
- package/dist/src/packlets/services/service-registry.test.js +75 -0
- package/dist/src/packlets/services/service-registry.test.js.map +1 -0
- package/dist/src/packlets/services/signer.d.ts +0 -3
- package/dist/src/packlets/services/signer.d.ts.map +1 -1
- package/dist/src/packlets/spaces/index.d.ts +2 -0
- package/dist/src/packlets/spaces/index.d.ts.map +1 -0
- package/dist/src/packlets/spaces/index.js +21 -0
- package/dist/src/packlets/spaces/index.js.map +1 -0
- package/dist/src/packlets/spaces/spaces-service.d.ts +11 -0
- package/dist/src/packlets/spaces/spaces-service.d.ts.map +1 -0
- package/dist/src/packlets/spaces/spaces-service.js +22 -0
- package/dist/src/packlets/spaces/spaces-service.js.map +1 -0
- package/dist/src/packlets/storage/storage.js +1 -1
- package/dist/src/packlets/storage/storage.js.map +1 -1
- package/dist/src/packlets/testing/index.d.ts +2 -0
- package/dist/src/packlets/testing/index.d.ts.map +1 -0
- package/dist/src/packlets/testing/index.js +21 -0
- package/dist/src/packlets/testing/index.js.map +1 -0
- package/dist/src/packlets/testing/test-builder.d.ts +14 -0
- package/dist/src/packlets/testing/test-builder.d.ts.map +1 -0
- package/dist/src/packlets/testing/test-builder.js +66 -0
- package/dist/src/packlets/testing/test-builder.js.map +1 -0
- package/dist/src/packlets/vault/iframe-runtime.d.ts +19 -0
- package/dist/src/packlets/vault/iframe-runtime.d.ts.map +1 -0
- package/dist/src/packlets/vault/iframe-runtime.js +54 -0
- package/dist/src/packlets/vault/iframe-runtime.js.map +1 -0
- package/dist/src/packlets/vault/index.d.ts +4 -0
- package/dist/src/packlets/vault/index.d.ts.map +1 -0
- package/dist/src/packlets/vault/index.js +23 -0
- package/dist/src/packlets/vault/index.js.map +1 -0
- package/dist/src/packlets/vault/services.d.ts +13 -0
- package/dist/src/packlets/vault/services.d.ts.map +1 -0
- package/dist/src/packlets/vault/services.js +15 -0
- package/dist/src/packlets/vault/services.js.map +1 -0
- package/dist/src/packlets/vault/worker-runtime.d.ts +32 -0
- package/dist/src/packlets/vault/worker-runtime.d.ts.map +1 -0
- package/dist/src/packlets/vault/worker-runtime.js +94 -0
- package/dist/src/packlets/vault/worker-runtime.js.map +1 -0
- package/dist/src/packlets/vault/worker-session.d.ts +29 -0
- package/dist/src/packlets/vault/worker-session.d.ts.map +1 -0
- package/dist/src/packlets/vault/worker-session.js +84 -0
- package/dist/src/packlets/vault/worker-session.js.map +1 -0
- package/package.json +26 -26
- package/src/index.ts +4 -2
- package/src/packlets/{services/impl → deprecated}/index.ts +1 -4
- package/src/packlets/{invitations/common.ts → deprecated/invitations.ts} +18 -3
- package/src/packlets/{services/impl → deprecated}/profile.ts +13 -13
- package/src/packlets/deprecated/space.ts +245 -0
- package/src/packlets/{services/impl → deprecated}/system.ts +2 -2
- package/src/packlets/{services/impl → deprecated}/tracing.ts +2 -2
- package/src/packlets/{services/impl → devtools}/devtools.ts +33 -34
- package/src/packlets/devtools/feeds.ts +31 -27
- package/src/packlets/devtools/index.ts +1 -1
- package/src/packlets/devtools/spaces.ts +19 -18
- package/src/packlets/identity/devices-service-impl.ts +54 -0
- package/src/packlets/identity/identity-manager.test.ts +7 -8
- package/src/packlets/identity/identity.test.ts +2 -3
- package/src/packlets/identity/identity.ts +5 -1
- package/src/packlets/invitations/encoder.test.ts +22 -0
- package/src/packlets/invitations/encoder.ts +26 -0
- package/src/packlets/{services/testing/halo.test.ts → invitations/halo-invitations.test.ts} +5 -5
- package/src/packlets/invitations/halo-invitations.ts +12 -10
- package/src/packlets/invitations/index.ts +6 -3
- package/src/packlets/invitations/invitations-proxy.ts +157 -0
- package/src/packlets/invitations/invitations.ts +149 -0
- package/src/packlets/invitations/space-invitations-handler.test.ts +154 -0
- package/src/packlets/invitations/space-invitations-handler.ts +266 -0
- package/src/packlets/invitations/space-invitations-proxy.ts +16 -0
- package/src/packlets/invitations/space-invitations-service.test.ts +129 -0
- package/src/packlets/invitations/space-invitations-service.ts +196 -0
- package/src/packlets/services/iframe-service-proxy.ts +71 -0
- package/src/packlets/services/index.ts +3 -2
- package/src/packlets/services/service-context.ts +9 -31
- package/src/packlets/services/service-definitions.ts +54 -0
- package/src/packlets/services/service-host.test.ts +12 -24
- package/src/packlets/services/service-host.ts +64 -64
- package/src/packlets/services/service-proxy.ts +54 -0
- package/src/packlets/services/service-registry.test.ts +95 -0
- package/src/packlets/services/service-registry.ts +24 -0
- package/src/packlets/services/signer.ts +1 -3
- package/src/packlets/spaces/index.ts +5 -0
- package/src/packlets/spaces/spaces-service.ts +28 -0
- package/src/packlets/storage/storage.ts +1 -1
- package/src/packlets/testing/index.ts +5 -0
- package/src/packlets/testing/test-builder.ts +80 -0
- package/src/packlets/vault/iframe-runtime.ts +68 -0
- package/src/packlets/vault/index.ts +7 -0
- package/src/packlets/vault/services.ts +26 -0
- package/src/packlets/vault/worker-runtime.ts +111 -0
- package/src/packlets/vault/worker-session.ts +113 -0
- package/dist/src/packlets/devtools/devtools-host-events.d.ts +0 -5
- package/dist/src/packlets/devtools/devtools-host-events.d.ts.map +0 -1
- package/dist/src/packlets/devtools/devtools-host-events.js +0 -14
- package/dist/src/packlets/devtools/devtools-host-events.js.map +0 -1
- package/dist/src/packlets/invitations/common.d.ts.map +0 -1
- package/dist/src/packlets/invitations/common.js.map +0 -1
- package/dist/src/packlets/invitations/invitation-wrapper.d.ts +0 -36
- package/dist/src/packlets/invitations/invitation-wrapper.d.ts.map +0 -1
- package/dist/src/packlets/invitations/invitation-wrapper.js +0 -104
- package/dist/src/packlets/invitations/invitation-wrapper.js.map +0 -1
- package/dist/src/packlets/invitations/space-invitations.d.ts +0 -25
- package/dist/src/packlets/invitations/space-invitations.d.ts.map +0 -1
- package/dist/src/packlets/invitations/space-invitations.js +0 -136
- package/dist/src/packlets/invitations/space-invitations.js.map +0 -1
- package/dist/src/packlets/services/impl/devtools.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/devtools.js +0 -77
- package/dist/src/packlets/services/impl/devtools.js.map +0 -1
- package/dist/src/packlets/services/impl/halo.d.ts +0 -20
- package/dist/src/packlets/services/impl/halo.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/halo.js +0 -93
- package/dist/src/packlets/services/impl/halo.js.map +0 -1
- package/dist/src/packlets/services/impl/index.d.ts +0 -6
- package/dist/src/packlets/services/impl/index.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/index.js.map +0 -1
- package/dist/src/packlets/services/impl/party.d.ts +0 -25
- package/dist/src/packlets/services/impl/party.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/party.js +0 -265
- package/dist/src/packlets/services/impl/party.js.map +0 -1
- package/dist/src/packlets/services/impl/profile.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/profile.js.map +0 -1
- package/dist/src/packlets/services/impl/system.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/system.js.map +0 -1
- package/dist/src/packlets/services/impl/tracing.d.ts +0 -12
- package/dist/src/packlets/services/impl/tracing.d.ts.map +0 -1
- package/dist/src/packlets/services/impl/tracing.js.map +0 -1
- package/dist/src/packlets/services/service-factory.d.ts +0 -15
- package/dist/src/packlets/services/service-factory.d.ts.map +0 -1
- package/dist/src/packlets/services/service-factory.js +0 -25
- package/dist/src/packlets/services/service-factory.js.map +0 -1
- package/dist/src/packlets/services/services.d.ts +0 -19
- package/dist/src/packlets/services/services.d.ts.map +0 -1
- package/dist/src/packlets/services/services.js.map +0 -1
- package/dist/src/packlets/services/testing/halo.test.d.ts +0 -2
- package/dist/src/packlets/services/testing/halo.test.d.ts.map +0 -1
- package/dist/src/packlets/services/testing/halo.test.js.map +0 -1
- package/dist/src/packlets/services/testing/spaces.test.d.ts +0 -2
- package/dist/src/packlets/services/testing/spaces.test.d.ts.map +0 -1
- package/dist/src/packlets/services/testing/spaces.test.js +0 -68
- package/dist/src/packlets/services/testing/spaces.test.js.map +0 -1
- package/dist/src/packlets/services/testing/testing.d.ts +0 -8
- package/dist/src/packlets/services/testing/testing.d.ts.map +0 -1
- package/dist/src/packlets/services/testing/testing.js +0 -23
- package/dist/src/packlets/services/testing/testing.js.map +0 -1
- package/src/packlets/devtools/devtools-host-events.ts +0 -8
- package/src/packlets/invitations/invitation-wrapper.ts +0 -140
- package/src/packlets/invitations/space-invitations.ts +0 -159
- package/src/packlets/services/impl/halo.ts +0 -107
- package/src/packlets/services/impl/party.ts +0 -305
- package/src/packlets/services/service-factory.ts +0 -35
- package/src/packlets/services/services.ts +0 -39
- package/src/packlets/services/testing/spaces.test.ts +0 -87
- package/src/packlets/services/testing/testing.ts +0 -28
|
@@ -27,14 +27,15 @@ export const subscribeToFeeds = (
|
|
|
27
27
|
const feedMap = new ComplexMap<PublicKey, FeedWrapper<FeedMessage>>(PublicKey.hash);
|
|
28
28
|
const subscriptions = new EventSubscriptions();
|
|
29
29
|
|
|
30
|
-
const update =
|
|
31
|
-
const feeds =
|
|
30
|
+
const update = () => {
|
|
31
|
+
const feeds = feedStore.feeds;
|
|
32
32
|
feeds
|
|
33
33
|
.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key)))
|
|
34
34
|
.forEach((feed) => {
|
|
35
35
|
if (!feedMap.has(feed.key)) {
|
|
36
36
|
feedMap.set(feed.key, feed);
|
|
37
|
-
feed.on('close', update);
|
|
37
|
+
feed.on('close', update);
|
|
38
|
+
subscriptions.add(feed.off('close', update));
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
41
|
next({
|
|
@@ -42,10 +43,8 @@ export const subscribeToFeeds = (
|
|
|
42
43
|
});
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
await update();
|
|
48
|
-
});
|
|
46
|
+
subscriptions.add(feedStore.feedOpened.on(update));
|
|
47
|
+
update();
|
|
49
48
|
|
|
50
49
|
return () => {
|
|
51
50
|
subscriptions.clear();
|
|
@@ -60,31 +59,36 @@ export const subscribeToFeedBlocks = (
|
|
|
60
59
|
if (!feedKey) {
|
|
61
60
|
return;
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
const update = async (feed: FeedWrapper<FeedMessage>) => {
|
|
65
|
-
const iterator = new FeedIterator(feed);
|
|
66
|
-
await iterator.open();
|
|
67
|
-
const blocks = [];
|
|
68
|
-
for await (const block of iterator) {
|
|
69
|
-
blocks.push(block);
|
|
70
|
-
if (blocks.length >= feed.properties.length) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
next({
|
|
75
|
-
blocks: blocks.slice(-maxBlocks)
|
|
76
|
-
});
|
|
77
|
-
await iterator.close();
|
|
78
|
-
};
|
|
62
|
+
const subscriptions = new EventSubscriptions();
|
|
79
63
|
|
|
80
64
|
setImmediate(async () => {
|
|
81
|
-
const feed =
|
|
65
|
+
const feed = feedStore.getFeed(feedKey);
|
|
82
66
|
if (!feed) {
|
|
83
67
|
return;
|
|
84
68
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
|
|
70
|
+
const update = async () => {
|
|
71
|
+
const iterator = new FeedIterator(feed);
|
|
72
|
+
await iterator.open();
|
|
73
|
+
const blocks = [];
|
|
74
|
+
for await (const block of iterator) {
|
|
75
|
+
blocks.push(block);
|
|
76
|
+
if (blocks.length >= feed.properties.length) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
next({
|
|
81
|
+
blocks: blocks.slice(-maxBlocks)
|
|
82
|
+
});
|
|
83
|
+
await iterator.close();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
feed.on('append', update);
|
|
87
|
+
subscriptions.add(feed.off('append', update));
|
|
88
|
+
|
|
89
|
+
feed.on('truncate', update);
|
|
90
|
+
subscriptions.add(feed.off('truncate', update));
|
|
91
|
+
await update();
|
|
88
92
|
});
|
|
89
93
|
|
|
90
94
|
return () => {};
|
|
@@ -4,33 +4,34 @@
|
|
|
4
4
|
|
|
5
5
|
import { Stream } from '@dxos/codec-protobuf';
|
|
6
6
|
import { Space } from '@dxos/echo-db';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { SubscribeToSpacesRequest, SubscribeToSpacesResponse } from '@dxos/protocols/proto/dxos/devtools/host';
|
|
8
|
+
import { SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
9
9
|
|
|
10
10
|
import { ServiceContext } from '../services';
|
|
11
11
|
|
|
12
|
-
export const subscribeToSpaces = (context: ServiceContext, {
|
|
13
|
-
new Stream<
|
|
12
|
+
export const subscribeToSpaces = (context: ServiceContext, { spaceKeys = [] }: SubscribeToSpacesRequest) =>
|
|
13
|
+
new Stream<SubscribeToSpacesResponse>(({ next }) => {
|
|
14
14
|
let unsubscribe: () => void;
|
|
15
15
|
|
|
16
16
|
const update = async () => {
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
(
|
|
17
|
+
const spaces: Space[] = [...context.spaceManager!.spaces.values()];
|
|
18
|
+
const filteredSpaces = spaces.filter(
|
|
19
|
+
(space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key))
|
|
20
20
|
);
|
|
21
21
|
|
|
22
22
|
next({
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
spaces: filteredSpaces.map((space) => {
|
|
24
|
+
const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata: SpaceMetadata) =>
|
|
25
|
+
spaceMetadata.key.equals(space.key)
|
|
26
26
|
);
|
|
27
|
+
|
|
27
28
|
return {
|
|
28
|
-
key:
|
|
29
|
-
isOpen:
|
|
30
|
-
timeframe:
|
|
31
|
-
genesisFeed:
|
|
32
|
-
controlFeed:
|
|
33
|
-
dataFeed:
|
|
29
|
+
key: space.key,
|
|
30
|
+
isOpen: space.isOpen,
|
|
31
|
+
timeframe: spaceMetadata!.latestTimeframe!,
|
|
32
|
+
genesisFeed: space.genesisFeedKey,
|
|
33
|
+
controlFeed: space.controlFeedKey,
|
|
34
|
+
dataFeed: space.dataFeedKey
|
|
34
35
|
};
|
|
35
36
|
})
|
|
36
37
|
});
|
|
@@ -38,9 +39,9 @@ export const subscribeToSpaces = (context: ServiceContext, { partyKeys = [] }: S
|
|
|
38
39
|
|
|
39
40
|
setImmediate(async () => {
|
|
40
41
|
await context.initialized.wait();
|
|
41
|
-
unsubscribe = context.spaceManager!.
|
|
42
|
+
unsubscribe = context.spaceManager!.updated.on(() => update());
|
|
42
43
|
|
|
43
|
-
// Send initial
|
|
44
|
+
// Send initial spaces.
|
|
44
45
|
await update();
|
|
45
46
|
});
|
|
46
47
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { EventSubscriptions } from '@dxos/async';
|
|
6
|
+
import { Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { Device, DevicesService, QueryDevicesResponse } from '@dxos/protocols/proto/dxos/client/services';
|
|
8
|
+
|
|
9
|
+
import { IdentityManager } from './identity-manager';
|
|
10
|
+
|
|
11
|
+
export class DevicesServiceImpl implements DevicesService {
|
|
12
|
+
constructor(private readonly _identityManager: IdentityManager) {}
|
|
13
|
+
|
|
14
|
+
updateDevice(): Promise<Device> {
|
|
15
|
+
throw new Error('Method not implemented.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
queryDevices(): Stream<QueryDevicesResponse> {
|
|
19
|
+
return new Stream(({ next }) => {
|
|
20
|
+
const update = () => {
|
|
21
|
+
const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
|
|
22
|
+
if (!deviceKeys) {
|
|
23
|
+
next({ devices: [] });
|
|
24
|
+
} else {
|
|
25
|
+
next({
|
|
26
|
+
devices: Array.from(deviceKeys.values()).map((key) => ({
|
|
27
|
+
deviceKey: key
|
|
28
|
+
}))
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const dispose = new EventSubscriptions();
|
|
34
|
+
|
|
35
|
+
dispose.add(
|
|
36
|
+
this._identityManager.stateUpdate.on(() => {
|
|
37
|
+
update();
|
|
38
|
+
|
|
39
|
+
if (this._identityManager.identity) {
|
|
40
|
+
dispose.add(
|
|
41
|
+
this._identityManager.identity.stateUpdate.on(() => {
|
|
42
|
+
update();
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
update();
|
|
50
|
+
|
|
51
|
+
return () => dispose.clear();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { valueEncoding, MetadataStore } from '@dxos/echo-db';
|
|
8
8
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
9
9
|
import { Keyring } from '@dxos/keyring';
|
|
10
10
|
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
11
|
-
import { ModelFactory } from '@dxos/model-factory';
|
|
12
11
|
import { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
|
|
13
|
-
import { ObjectModel } from '@dxos/object-model';
|
|
14
12
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
15
13
|
import { createStorage, Storage, StorageType } from '@dxos/random-access-storage';
|
|
16
14
|
import { afterTest } from '@dxos/testutils';
|
|
17
15
|
|
|
16
|
+
import { createDefaultModelFactory } from '../services';
|
|
18
17
|
import { IdentityManager } from './identity-manager';
|
|
19
18
|
|
|
20
19
|
describe('identity/identity-manager', function () {
|
|
@@ -50,7 +49,7 @@ describe('identity/identity-manager', function () {
|
|
|
50
49
|
feedStore,
|
|
51
50
|
keyring,
|
|
52
51
|
networkManager,
|
|
53
|
-
|
|
52
|
+
createDefaultModelFactory()
|
|
54
53
|
);
|
|
55
54
|
|
|
56
55
|
return {
|
|
@@ -65,7 +64,7 @@ describe('identity/identity-manager', function () {
|
|
|
65
64
|
afterTest(() => identityManager.close());
|
|
66
65
|
|
|
67
66
|
const identity = await identityManager.createIdentity();
|
|
68
|
-
expect(identity).
|
|
67
|
+
expect(identity).to.exist;
|
|
69
68
|
});
|
|
70
69
|
|
|
71
70
|
it('reload from storage', async function () {
|
|
@@ -80,9 +79,9 @@ describe('identity/identity-manager', function () {
|
|
|
80
79
|
const peer2 = await setupPeer({ storage });
|
|
81
80
|
await peer2.identityManager.open();
|
|
82
81
|
|
|
83
|
-
expect(peer2.identityManager.identity).
|
|
84
|
-
expect(peer2.identityManager.identity!.identityKey).
|
|
85
|
-
expect(peer2.identityManager.identity!.deviceKey).
|
|
82
|
+
expect(peer2.identityManager.identity).to.exist;
|
|
83
|
+
expect(peer2.identityManager.identity!.identityKey).to.deep.eq(identity1.identityKey);
|
|
84
|
+
expect(peer2.identityManager.identity!.deviceKey).to.deep.eq(identity1.deviceKey);
|
|
86
85
|
|
|
87
86
|
// TODO(dmaretskyi): Check that identity is "alive" (space is working and can write mutations).
|
|
88
87
|
});
|
|
@@ -10,18 +10,17 @@ import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
|
10
10
|
import { Keyring } from '@dxos/keyring';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
13
|
-
import { ModelFactory } from '@dxos/model-factory';
|
|
14
13
|
import { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
|
|
15
|
-
import { ObjectModel } from '@dxos/object-model';
|
|
16
14
|
import { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
17
15
|
import { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
18
16
|
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
19
17
|
import { afterTest } from '@dxos/testutils';
|
|
20
18
|
|
|
19
|
+
import { createDefaultModelFactory } from '../services';
|
|
21
20
|
import { createHaloAuthProvider, createHaloAuthVerifier } from './authenticator';
|
|
22
21
|
import { Identity } from './identity';
|
|
23
22
|
|
|
24
|
-
const modelFactory =
|
|
23
|
+
const modelFactory = createDefaultModelFactory();
|
|
25
24
|
|
|
26
25
|
describe('identity/identity', function () {
|
|
27
26
|
it('create', async function () {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
|
|
7
|
+
import { Event } from '@dxos/async';
|
|
7
8
|
import {
|
|
8
9
|
DeviceStateMachine,
|
|
9
10
|
CredentialSigner,
|
|
@@ -34,6 +35,8 @@ export class Identity {
|
|
|
34
35
|
public readonly identityKey: PublicKey;
|
|
35
36
|
public readonly deviceKey: PublicKey;
|
|
36
37
|
|
|
38
|
+
public readonly stateUpdate = new Event();
|
|
39
|
+
|
|
37
40
|
constructor({ space, signer, identityKey, deviceKey }: IdentityParams) {
|
|
38
41
|
this._space = space;
|
|
39
42
|
this._signer = signer;
|
|
@@ -43,9 +46,10 @@ export class Identity {
|
|
|
43
46
|
|
|
44
47
|
this._deviceStateMachine = new DeviceStateMachine(this.identityKey, this.deviceKey);
|
|
45
48
|
|
|
46
|
-
// Save device key chain credential when processed by the
|
|
49
|
+
// Save device key chain credential when processed by the space state machine.
|
|
47
50
|
this._space.onCredentialProcessed.set(async (credential) => {
|
|
48
51
|
await this._deviceStateMachine.process(credential);
|
|
52
|
+
this.stateUpdate.emit();
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
|
|
7
|
+
import { PublicKey } from '@dxos/keys';
|
|
8
|
+
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
|
+
|
|
10
|
+
import { InvitationEncoder } from './encoder';
|
|
11
|
+
|
|
12
|
+
describe('Invitation utils', function () {
|
|
13
|
+
it('encodes and decodes an invitation', function () {
|
|
14
|
+
const invitation: Invitation = {
|
|
15
|
+
swarmKey: PublicKey.random()
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const encoded = InvitationEncoder.encode(invitation);
|
|
19
|
+
const decoded = InvitationEncoder.decode(encoded);
|
|
20
|
+
expect(decoded.swarmKey).to.deep.eq(invitation.swarmKey);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import base from 'base-x';
|
|
6
|
+
|
|
7
|
+
import { schema } from '@dxos/protocols';
|
|
8
|
+
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
|
+
|
|
10
|
+
// Encode with URL-safe alpha-numeric characters.
|
|
11
|
+
const base62 = base('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
|
12
|
+
|
|
13
|
+
const codec = schema.getCodecForType('dxos.client.services.Invitation');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Encodes and decodes an invitation proto into/from alphanumeric chars.
|
|
17
|
+
*/
|
|
18
|
+
export class InvitationEncoder {
|
|
19
|
+
static decode(text: string): Invitation {
|
|
20
|
+
return codec.decode(base62.decode(text));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static encode(invitation: Invitation): string {
|
|
24
|
+
return base62.encode(codec.encode(invitation));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -7,11 +7,11 @@ import { expect } from 'chai';
|
|
|
7
7
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
8
8
|
import { afterTest } from '@dxos/testutils';
|
|
9
9
|
|
|
10
|
-
import { createServiceContext } from '
|
|
10
|
+
import { createServiceContext } from '../testing';
|
|
11
11
|
|
|
12
12
|
describe('services/halo', function () {
|
|
13
13
|
it('creates identity', async function () {
|
|
14
|
-
const peer =
|
|
14
|
+
const peer = createServiceContext();
|
|
15
15
|
await peer.open();
|
|
16
16
|
afterTest(() => peer.close());
|
|
17
17
|
|
|
@@ -19,11 +19,11 @@ describe('services/halo', function () {
|
|
|
19
19
|
expect(identity).not.to.be.undefined;
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it('
|
|
22
|
+
it('invitations', async function () {
|
|
23
23
|
const signalContext = new MemorySignalManagerContext();
|
|
24
24
|
|
|
25
|
-
const peer1 =
|
|
26
|
-
const peer2 =
|
|
25
|
+
const peer1 = createServiceContext({ signalContext });
|
|
26
|
+
const peer2 = createServiceContext({ signalContext });
|
|
27
27
|
await peer1.open();
|
|
28
28
|
await peer2.open();
|
|
29
29
|
afterTest(() => peer1.close());
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import assert from 'assert';
|
|
6
|
+
|
|
5
7
|
import { Trigger } from '@dxos/async';
|
|
6
8
|
import { failUndefined } from '@dxos/debug';
|
|
7
9
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -9,7 +11,7 @@ import { log } from '@dxos/log';
|
|
|
9
11
|
import { createProtocolFactory, NetworkManager, StarTopology } from '@dxos/network-manager';
|
|
10
12
|
import { createRpcPlugin } from '@dxos/protocol-plugin-rpc';
|
|
11
13
|
import { schema } from '@dxos/protocols';
|
|
12
|
-
import {
|
|
14
|
+
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
13
15
|
import { createProtoRpcPeer } from '@dxos/rpc';
|
|
14
16
|
|
|
15
17
|
import { Identity, IdentityManager } from '../identity';
|
|
@@ -27,12 +29,11 @@ export class HaloInvitations {
|
|
|
27
29
|
/**
|
|
28
30
|
* Sends a HALO admission offer and waits for guest to accept.
|
|
29
31
|
*/
|
|
30
|
-
async createInvitation({ onFinish }: { onFinish?: () => void } = {}): Promise<
|
|
32
|
+
async createInvitation({ onFinish }: { onFinish?: () => void } = {}): Promise<Invitation> {
|
|
31
33
|
const identity = this._identityManager.identity ?? failUndefined();
|
|
32
34
|
|
|
33
35
|
const plugin = createRpcPlugin(async (port) => {
|
|
34
36
|
const peer = createProtoRpcPeer({
|
|
35
|
-
port,
|
|
36
37
|
requested: {
|
|
37
38
|
HaloGuestService: schema.getService('dxos.halo.invitations.HaloGuestService')
|
|
38
39
|
},
|
|
@@ -61,7 +62,8 @@ export class HaloInvitations {
|
|
|
61
62
|
// TODO(dmaretskyi): Admit guest's feeds otherwise messages from them won't be processed by the pipeline.
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
}
|
|
65
|
+
},
|
|
66
|
+
port
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
await peer.open();
|
|
@@ -90,21 +92,19 @@ export class HaloInvitations {
|
|
|
90
92
|
});
|
|
91
93
|
|
|
92
94
|
return {
|
|
93
|
-
type:
|
|
94
|
-
swarmKey: topic
|
|
95
|
-
invitation: new Uint8Array() // TODO(burdon): Remove.
|
|
95
|
+
type: Invitation.Type.INTERACTIVE,
|
|
96
|
+
swarmKey: topic
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* Joins an existing identity HALO by invitation.
|
|
101
102
|
*/
|
|
102
|
-
async acceptInvitation(invitation:
|
|
103
|
+
async acceptInvitation(invitation: Invitation): Promise<Identity> {
|
|
103
104
|
const admitted = new Trigger<Identity>(); // TODO(burdon): Must not share across multiple connections.
|
|
104
105
|
|
|
105
106
|
const plugin = createRpcPlugin(async (port) => {
|
|
106
107
|
const peer = createProtoRpcPeer({
|
|
107
|
-
port,
|
|
108
108
|
requested: {
|
|
109
109
|
// TODO(burdon): Rename in-bound.
|
|
110
110
|
HaloHostService: schema.getService('dxos.halo.invitations.HaloHostService')
|
|
@@ -136,7 +136,8 @@ export class HaloInvitations {
|
|
|
136
136
|
admitted.wake(identity);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
}
|
|
139
|
+
},
|
|
140
|
+
port
|
|
140
141
|
});
|
|
141
142
|
|
|
142
143
|
await peer.open();
|
|
@@ -144,6 +145,7 @@ export class HaloInvitations {
|
|
|
144
145
|
await peer.close();
|
|
145
146
|
});
|
|
146
147
|
|
|
148
|
+
assert(invitation.swarmKey);
|
|
147
149
|
const topic = PublicKey.from(invitation.swarmKey);
|
|
148
150
|
const peerId = PublicKey.random(); // TODO(burdon): Fails if using the actual peer key.
|
|
149
151
|
const connection = await this._networkManager.openSwarmConnection({
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './encoder';
|
|
6
6
|
export * from './halo-invitations';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
7
|
+
export * from './invitations';
|
|
8
|
+
export * from './invitations-proxy';
|
|
9
|
+
export * from './space-invitations-handler';
|
|
10
|
+
export * from './space-invitations-proxy';
|
|
11
|
+
export * from './space-invitations-service';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import assert from 'assert';
|
|
6
|
+
|
|
7
|
+
import { observableError } from '@dxos/async';
|
|
8
|
+
import { Stream } from '@dxos/codec-protobuf';
|
|
9
|
+
import { log } from '@dxos/log';
|
|
10
|
+
import { Invitation, InvitationsService } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
AuthenticatingInvitationObservable,
|
|
14
|
+
AuthenticatingInvitationProvider,
|
|
15
|
+
CreateInvitationsOptions,
|
|
16
|
+
InvitationsProxy,
|
|
17
|
+
InvitationObservable,
|
|
18
|
+
InvitationObservableProvider
|
|
19
|
+
} from './invitations';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Adapts invitations service observable to client/service stream.
|
|
23
|
+
* Used by both HALO and Spaces client/service interfaces.
|
|
24
|
+
*/
|
|
25
|
+
export abstract class AbstractInvitationsProxy<T> implements InvitationsProxy<T> {
|
|
26
|
+
// prettier-ignore
|
|
27
|
+
constructor(
|
|
28
|
+
private readonly _invitationsService: InvitationsService
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
abstract createInvitationObject(context: T): Invitation;
|
|
32
|
+
|
|
33
|
+
createInvitation(context: T, options?: CreateInvitationsOptions): InvitationObservable {
|
|
34
|
+
assert(context);
|
|
35
|
+
|
|
36
|
+
let invitationId: string;
|
|
37
|
+
const observable = new InvitationObservableProvider(async () => {
|
|
38
|
+
if (invitationId) {
|
|
39
|
+
await this._invitationsService.cancelInvitation({ invitationId });
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const invitation = { ...this.createInvitationObject(context), ...options };
|
|
44
|
+
const stream: Stream<Invitation> = this._invitationsService.createInvitation(invitation);
|
|
45
|
+
|
|
46
|
+
stream.subscribe(
|
|
47
|
+
(invitation: Invitation) => {
|
|
48
|
+
observable.setInvitation(invitation);
|
|
49
|
+
|
|
50
|
+
switch (invitation.state) {
|
|
51
|
+
case Invitation.State.CONNECTING: {
|
|
52
|
+
assert(invitation.invitationId);
|
|
53
|
+
invitationId = invitation.invitationId;
|
|
54
|
+
observable.callback.onConnecting?.(invitation);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
case Invitation.State.CONNECTED: {
|
|
59
|
+
observable.callback.onConnected?.(invitation);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
case Invitation.State.AUTHENTICATING: {
|
|
64
|
+
observable.callback.onAuthenticating?.(invitation);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
case Invitation.State.SUCCESS: {
|
|
69
|
+
observable.callback.onSuccess?.(invitation);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case Invitation.State.CANCELLED: {
|
|
74
|
+
observable.callback.onCancelled?.();
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
default: {
|
|
79
|
+
log.error(`Invalid state: ${invitation.state}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
(err) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
observableError(observable, err);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return observable;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
acceptInvitation(invitation: Invitation): AuthenticatingInvitationObservable {
|
|
94
|
+
assert(invitation && invitation.swarmKey);
|
|
95
|
+
|
|
96
|
+
const observable = new AuthenticatingInvitationProvider({
|
|
97
|
+
onCancel: async () => {
|
|
98
|
+
const invitationId = observable.invitation?.invitationId;
|
|
99
|
+
assert(invitationId);
|
|
100
|
+
await this._invitationsService.cancelInvitation({ invitationId });
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
onAuthenticate: async (authenticationCode: string) => {
|
|
104
|
+
const invitationId = observable.invitation?.invitationId;
|
|
105
|
+
assert(invitationId);
|
|
106
|
+
await this._invitationsService.authenticate({ invitationId, authenticationCode });
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const stream: Stream<Invitation> = this._invitationsService.acceptInvitation(invitation);
|
|
111
|
+
|
|
112
|
+
stream.subscribe(
|
|
113
|
+
(invitation: Invitation) => {
|
|
114
|
+
assert(invitation.invitationId);
|
|
115
|
+
observable.setInvitation(invitation);
|
|
116
|
+
|
|
117
|
+
switch (invitation.state) {
|
|
118
|
+
case Invitation.State.CONNECTING: {
|
|
119
|
+
observable.callback.onConnecting?.(invitation);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
case Invitation.State.CONNECTED: {
|
|
124
|
+
observable.callback.onConnected?.(invitation);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case Invitation.State.AUTHENTICATING: {
|
|
129
|
+
observable.callback.onAuthenticating?.(invitation);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case Invitation.State.SUCCESS: {
|
|
134
|
+
observable.callback.onSuccess?.(invitation);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
case Invitation.State.CANCELLED: {
|
|
139
|
+
observable.callback.onCancelled?.();
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
default: {
|
|
144
|
+
log.error(`Invalid state: ${invitation.state}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
(err) => {
|
|
149
|
+
if (err) {
|
|
150
|
+
observableError(observable, err);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return observable;
|
|
156
|
+
}
|
|
157
|
+
}
|