@automerge/automerge-repo-network-websocket 1.0.7 → 1.0.8
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserWebSocketClientAdapter.d.ts","sourceRoot":"","sources":["../src/BrowserWebSocketClientAdapter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAQ,MAAM,2BAA2B,CAAA;AACxE,OAAO,SAAS,MAAM,eAAe,CAAA;AAIrC,OAAO,EACL,iBAAiB,EAGlB,MAAM,eAAe,CAAA;AAMtB,uBAAe,uBAAwB,SAAQ,cAAc;IAC3D,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,qBAAa,6BAA8B,SAAQ,uBAAuB;;IAGxE,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA;IAGvC,GAAG,EAAE,MAAM,CAAA;gBAEC,GAAG,EAAE,MAAM;IAKvB,OAAO,CAAC,MAAM,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"BrowserWebSocketClientAdapter.d.ts","sourceRoot":"","sources":["../src/BrowserWebSocketClientAdapter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAQ,MAAM,2BAA2B,CAAA;AACxE,OAAO,SAAS,MAAM,eAAe,CAAA;AAIrC,OAAO,EACL,iBAAiB,EAGlB,MAAM,eAAe,CAAA;AAMtB,uBAAe,uBAAwB,SAAQ,cAAc;IAC3D,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,qBAAa,6BAA8B,SAAQ,uBAAuB;;IAGxE,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAA;IAGvC,GAAG,EAAE,MAAM,CAAA;gBAEC,GAAG,EAAE,MAAM;IAKvB,OAAO,CAAC,MAAM,EAAE,MAAM;IAoDtB,IAAI;IAoBJ,UAAU;IAOV,IAAI,CAAC,OAAO,EAAE,iBAAiB;IAwB/B,kBAAkB,CAAC,MAAM,EAAE,MAAM;IAajC,cAAc,CAAC,OAAO,EAAE,UAAU;CA6BnC"}
|
|
@@ -18,27 +18,37 @@ export class BrowserWebSocketClientAdapter extends WebSocketNetworkAdapter {
|
|
|
18
18
|
this.url = url;
|
|
19
19
|
}
|
|
20
20
|
connect(peerId) {
|
|
21
|
-
|
|
22
|
-
if (!this.timerId) {
|
|
23
|
-
this.timerId = setInterval(() => this.connect(peerId), 5000);
|
|
24
|
-
}
|
|
25
|
-
this.peerId = peerId;
|
|
26
|
-
this.socket = new WebSocket(this.url);
|
|
27
|
-
this.socket.binaryType = "arraybuffer";
|
|
28
|
-
this.socket.addEventListener("open", () => {
|
|
21
|
+
const onOpen = () => {
|
|
29
22
|
log(`@ ${this.url}: open`);
|
|
30
23
|
clearInterval(this.timerId);
|
|
31
24
|
this.timerId = undefined;
|
|
32
|
-
}
|
|
25
|
+
};
|
|
33
26
|
// When a socket closes, or disconnects, remove it from the array.
|
|
34
|
-
|
|
27
|
+
const onClose = () => {
|
|
35
28
|
log(`${this.url}: close`);
|
|
36
29
|
if (!this.timerId) {
|
|
37
30
|
this.connect(peerId);
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
};
|
|
33
|
+
const onMessage = (event) => {
|
|
34
|
+
this.receiveMessage(event.data);
|
|
35
|
+
};
|
|
36
|
+
// If we're reconnecting make sure we remove the old event listeners
|
|
37
|
+
// before creating a new connection.
|
|
38
|
+
if (this.socket) {
|
|
39
|
+
this.socket.removeEventListener("open", onOpen);
|
|
40
|
+
this.socket.removeEventListener("close", onClose);
|
|
41
|
+
this.socket.removeEventListener("message", onMessage);
|
|
42
|
+
}
|
|
43
|
+
if (!this.timerId) {
|
|
44
|
+
this.timerId = setInterval(() => this.connect(peerId), 5000);
|
|
45
|
+
}
|
|
46
|
+
this.peerId = peerId;
|
|
47
|
+
this.socket = new WebSocket(this.url);
|
|
48
|
+
this.socket.binaryType = "arraybuffer";
|
|
49
|
+
this.socket.addEventListener("open", onOpen);
|
|
50
|
+
this.socket.addEventListener("close", onClose);
|
|
51
|
+
this.socket.addEventListener("message", onMessage);
|
|
42
52
|
// mark this adapter as ready if we haven't received an ack in 1 second.
|
|
43
53
|
// We might hear back from the other end at some point but we shouldn't
|
|
44
54
|
// hold up marking things as unavailable for any longer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automerge/automerge-repo-network-websocket",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "isomorphic node/browser Websocket network adapter for Automerge Repo",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@automerge/automerge": "^2.1.0"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"test": "vitest"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@automerge/automerge-repo": "^1.0.
|
|
19
|
+
"@automerge/automerge-repo": "^1.0.8",
|
|
20
20
|
"cbor-x": "^1.3.0",
|
|
21
21
|
"eventemitter3": "^5.0.1",
|
|
22
22
|
"isomorphic-ws": "^5.0.0",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d244a36aebab52a86f91b5427bbe8ab2800bf2f4"
|
|
37
37
|
}
|
|
@@ -31,33 +31,43 @@ export class BrowserWebSocketClientAdapter extends WebSocketNetworkAdapter {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
connect(peerId: PeerId) {
|
|
34
|
-
|
|
35
|
-
if (!this.timerId) {
|
|
36
|
-
this.timerId = setInterval(() => this.connect(peerId), 5000)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.peerId = peerId
|
|
40
|
-
this.socket = new WebSocket(this.url)
|
|
41
|
-
this.socket.binaryType = "arraybuffer"
|
|
42
|
-
|
|
43
|
-
this.socket.addEventListener("open", () => {
|
|
34
|
+
const onOpen = () => {
|
|
44
35
|
log(`@ ${this.url}: open`)
|
|
45
36
|
clearInterval(this.timerId)
|
|
46
37
|
this.timerId = undefined
|
|
47
|
-
}
|
|
38
|
+
}
|
|
48
39
|
|
|
49
40
|
// When a socket closes, or disconnects, remove it from the array.
|
|
50
|
-
|
|
41
|
+
const onClose = () => {
|
|
51
42
|
log(`${this.url}: close`)
|
|
52
43
|
if (!this.timerId) {
|
|
53
44
|
this.connect(peerId)
|
|
54
45
|
}
|
|
55
|
-
|
|
56
|
-
})
|
|
46
|
+
}
|
|
57
47
|
|
|
58
|
-
|
|
48
|
+
const onMessage = (event: WebSocket.MessageEvent) => {
|
|
59
49
|
this.receiveMessage(event.data as Uint8Array)
|
|
60
|
-
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// If we're reconnecting make sure we remove the old event listeners
|
|
53
|
+
// before creating a new connection.
|
|
54
|
+
if (this.socket) {
|
|
55
|
+
this.socket.removeEventListener("open", onOpen)
|
|
56
|
+
this.socket.removeEventListener("close", onClose)
|
|
57
|
+
this.socket.removeEventListener("message", onMessage)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!this.timerId) {
|
|
61
|
+
this.timerId = setInterval(() => this.connect(peerId), 5000)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.peerId = peerId
|
|
65
|
+
this.socket = new WebSocket(this.url)
|
|
66
|
+
this.socket.binaryType = "arraybuffer"
|
|
67
|
+
|
|
68
|
+
this.socket.addEventListener("open", onOpen)
|
|
69
|
+
this.socket.addEventListener("close", onClose)
|
|
70
|
+
this.socket.addEventListener("message", onMessage)
|
|
61
71
|
|
|
62
72
|
// mark this adapter as ready if we haven't received an ack in 1 second.
|
|
63
73
|
// We might hear back from the other end at some point but we shouldn't
|