@dxos/echo-pipeline 0.3.10-next.ef70620 → 0.3.10
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-6XOL2DVG.mjs → chunk-7VTIQAQM.mjs} +18 -15
- package/dist/lib/browser/{chunk-6XOL2DVG.mjs.map → chunk-7VTIQAQM.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/node/{chunk-2RIO52RK.cjs → chunk-OEOED3JS.cjs} +21 -18
- package/dist/lib/node/{chunk-2RIO52RK.cjs.map → chunk-OEOED3JS.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +26 -26
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +16 -16
- package/package.json +33 -33
- package/src/automerge/automerge-host.test.ts +51 -48
- package/src/automerge/automerge-host.ts +10 -0
|
@@ -49,54 +49,6 @@ describe('AutomergeHost', () => {
|
|
|
49
49
|
client: new Trigger<TestAdapter>(),
|
|
50
50
|
host: new Trigger<TestAdapter>(),
|
|
51
51
|
};
|
|
52
|
-
|
|
53
|
-
class TestAdapter extends NetworkAdapter {
|
|
54
|
-
constructor(public readonly context: Context, public readonly role: 'host' | 'client') {
|
|
55
|
-
super();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// NOTE: Emitting `ready` event in NetworkAdapter`s constructor causes a race condition
|
|
59
|
-
// because `Repo` waits for `ready` event (which it never receives) before it starts using the adapter.
|
|
60
|
-
ready() {
|
|
61
|
-
this.emit('ready', { network: this });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
override connect(peerId: PeerId) {
|
|
65
|
-
this.peerId = peerId;
|
|
66
|
-
context[this.role].wake(this);
|
|
67
|
-
context[this.role === 'host' ? 'client' : 'host']
|
|
68
|
-
.wait()
|
|
69
|
-
.then((adapter) => {
|
|
70
|
-
invariant(adapter.peerId, 'Peer id is not set');
|
|
71
|
-
this.emit('peer-candidate', { peerId: adapter.peerId });
|
|
72
|
-
})
|
|
73
|
-
.catch((error) => {
|
|
74
|
-
log.catch(error);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
override send(message: Message) {
|
|
79
|
-
context[this.role === 'host' ? 'client' : 'host']
|
|
80
|
-
.wait()
|
|
81
|
-
.then((adapter) => {
|
|
82
|
-
adapter.receive(message);
|
|
83
|
-
})
|
|
84
|
-
.catch((error) => {
|
|
85
|
-
log.catch(error);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
override disconnect() {
|
|
90
|
-
this.peerId = undefined;
|
|
91
|
-
this.context[this.role].reset();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
receive(message: Message) {
|
|
95
|
-
invariant(this.peerId, 'Peer id is not set');
|
|
96
|
-
this.emit('message', message);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
52
|
const hostAdapter = new TestAdapter(context, 'host');
|
|
101
53
|
const clientAdapter = new TestAdapter(context, 'client');
|
|
102
54
|
|
|
@@ -119,4 +71,55 @@ describe('AutomergeHost', () => {
|
|
|
119
71
|
await asyncTimeout(docOnClient.whenReady(), 3_000);
|
|
120
72
|
expect(docOnClient.docSync().text).toEqual(text);
|
|
121
73
|
});
|
|
74
|
+
|
|
75
|
+
test('doubled connection', async () => {});
|
|
122
76
|
});
|
|
77
|
+
|
|
78
|
+
type Context = { client: Trigger<TestAdapter>; host: Trigger<TestAdapter> };
|
|
79
|
+
|
|
80
|
+
class TestAdapter extends NetworkAdapter {
|
|
81
|
+
constructor(public readonly context: Context, public readonly role: 'host' | 'client') {
|
|
82
|
+
super();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// NOTE: Emitting `ready` event in NetworkAdapter`s constructor causes a race condition
|
|
86
|
+
// because `Repo` waits for `ready` event (which it never receives) before it starts using the adapter.
|
|
87
|
+
ready() {
|
|
88
|
+
this.emit('ready', { network: this });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override connect(peerId: PeerId) {
|
|
92
|
+
this.peerId = peerId;
|
|
93
|
+
this.context[this.role].wake(this);
|
|
94
|
+
this.context[this.role === 'host' ? 'client' : 'host']
|
|
95
|
+
.wait()
|
|
96
|
+
.then((adapter) => {
|
|
97
|
+
invariant(adapter.peerId, 'Peer id is not set');
|
|
98
|
+
this.emit('peer-candidate', { peerId: adapter.peerId });
|
|
99
|
+
})
|
|
100
|
+
.catch((error) => {
|
|
101
|
+
log.catch(error);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
override send(message: Message) {
|
|
106
|
+
this.context[this.role === 'host' ? 'client' : 'host']
|
|
107
|
+
.wait()
|
|
108
|
+
.then((adapter) => {
|
|
109
|
+
adapter.receive(message);
|
|
110
|
+
})
|
|
111
|
+
.catch((error) => {
|
|
112
|
+
log.catch(error);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override disconnect() {
|
|
117
|
+
this.peerId = undefined;
|
|
118
|
+
this.context[this.role].reset();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
receive(message: Message) {
|
|
122
|
+
invariant(this.peerId, 'Peer id is not set');
|
|
123
|
+
this.emit('message', message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -205,6 +205,15 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
205
205
|
},
|
|
206
206
|
{
|
|
207
207
|
onStartReplication: async (info) => {
|
|
208
|
+
// Note: We store only one extension per peer.
|
|
209
|
+
// There can be a case where two connected peers have more than one teleport connection between them
|
|
210
|
+
// and each of them uses different teleport connections to send messages.
|
|
211
|
+
// It works because we receive messages from all teleport connections and Automerge Repo dedup them.
|
|
212
|
+
// TODO(mykola): Use only one teleport connection per peer.
|
|
213
|
+
if (this._extensions.has(info.id)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
208
217
|
peerInfo = info;
|
|
209
218
|
// TODO(mykola): Fix race condition?
|
|
210
219
|
this._extensions.set(info.id, extension);
|
|
@@ -214,6 +223,7 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
214
223
|
},
|
|
215
224
|
onSyncMessage: async ({ payload }) => {
|
|
216
225
|
const message = cbor.decode(payload) as Message;
|
|
226
|
+
// Note: automerge Repo dedup messages.
|
|
217
227
|
this.emit('message', message);
|
|
218
228
|
},
|
|
219
229
|
onClose: async () => {
|