@automerge/automerge-repo-network-websocket 1.1.1 → 1.1.3
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/README.md +17 -6
- package/dist/BrowserWebSocketClientAdapter.d.ts +2 -1
- package/dist/BrowserWebSocketClientAdapter.d.ts.map +1 -1
- package/dist/BrowserWebSocketClientAdapter.js +14 -6
- package/dist/NodeWSServerAdapter.js +1 -1
- package/package.json +4 -4
- package/src/BrowserWebSocketClientAdapter.ts +17 -6
- package/src/NodeWSServerAdapter.ts +1 -1
package/README.md
CHANGED
|
@@ -106,7 +106,7 @@ document_id = str
|
|
|
106
106
|
; Metadata sent in either the join or peer message types
|
|
107
107
|
peer_metadata = {
|
|
108
108
|
; The storage ID of this peer
|
|
109
|
-
? storageId: storage_id,
|
|
109
|
+
? storageId: storage_id,
|
|
110
110
|
; Whether the sender expects to connect again with this storage ID
|
|
111
111
|
isEphemeral: bool
|
|
112
112
|
}
|
|
@@ -140,11 +140,22 @@ Sent by the receiving peer in response to the join message in the
|
|
|
140
140
|
}
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
+
#### Leave
|
|
144
|
+
|
|
145
|
+
An advisory message sent by a peer when they are planning to disconnect.
|
|
146
|
+
|
|
147
|
+
```cddl
|
|
148
|
+
{
|
|
149
|
+
type: "leave",
|
|
150
|
+
senderId: peer_id,
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
143
154
|
#### Request
|
|
144
155
|
|
|
145
|
-
Sent when the `senderId` is asking to begin sync for the given `documentid`.
|
|
156
|
+
Sent when the `senderId` is asking to begin sync for the given `documentid`.
|
|
146
157
|
Identical to [sync](#sync) but indicates that the `senderId` would like an
|
|
147
|
-
[unavailable](#unavailable) message if the `targetId` does not have the
|
|
158
|
+
[unavailable](#unavailable) message if the `targetId` does not have the
|
|
148
159
|
document.
|
|
149
160
|
|
|
150
161
|
```cddl
|
|
@@ -200,7 +211,7 @@ Sent when a peer wants to send an ephemeral message to another peer
|
|
|
200
211
|
type: "ephemeral",
|
|
201
212
|
; The peer who sent this message
|
|
202
213
|
senderId: peer_id,
|
|
203
|
-
; The target of this message
|
|
214
|
+
; The target of this message
|
|
204
215
|
targetId: peer_id,
|
|
205
216
|
; The sequence number of this message within its session
|
|
206
217
|
count: uint,
|
|
@@ -257,9 +268,9 @@ Sent when the sender wishes to inform the receiver that a peer with a storage ID
|
|
|
257
268
|
documentId: document_id
|
|
258
269
|
|
|
259
270
|
; A map from storage ID to the heads advertised for a given storage ID
|
|
260
|
-
newHeads: {
|
|
271
|
+
newHeads: {
|
|
261
272
|
* storage_id => {
|
|
262
|
-
; The heads of the new document for the given storage ID as
|
|
273
|
+
; The heads of the new document for the given storage ID as
|
|
263
274
|
; a list of base64 encoded SHA2 hashes
|
|
264
275
|
heads: [* string]
|
|
265
276
|
; The local time on the node which initially sent the remote-heads-changed
|
|
@@ -15,7 +15,8 @@ export declare class BrowserWebSocketClientAdapter extends WebSocketNetworkAdapt
|
|
|
15
15
|
onOpen: () => void;
|
|
16
16
|
onClose: () => void;
|
|
17
17
|
onMessage: (event: WebSocket.MessageEvent) => void;
|
|
18
|
-
|
|
18
|
+
/** The websocket error handler signature is different on node and the browser. */
|
|
19
|
+
onError: (event: Event | WebSocket.ErrorEvent) => void;
|
|
19
20
|
join(): void;
|
|
20
21
|
disconnect(): void;
|
|
21
22
|
send(message: FromClientMessage): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserWebSocketClientAdapter.d.ts","sourceRoot":"","sources":["../src/BrowserWebSocketClientAdapter.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,YAAY,EAEb,MAAM,2BAA2B,CAAA;AAClC,OAAO,SAAS,MAAM,eAAe,CAAA;AAIrC,OAAO,EACL,iBAAiB,EAKlB,MAAM,eAAe,CAAA;AAKtB,uBAAe,uBAAwB,SAAQ,cAAc;IAC3D,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,qBAAa,6BAA8B,SAAQ,uBAAuB;;aAQtD,GAAG,EAAE,MAAM;aACX,aAAa;IAJ/B,YAAY,CAAC,EAAE,MAAM,CAAA;gBAGH,GAAG,EAAE,MAAM,EACX,aAAa,SAAO;IAMtC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY;IAqCnD,MAAM,aAKL;IAGD,OAAO,aAWN;IAED,SAAS,UAAW,sBAAsB,UAEzC;IAED,OAAO,
|
|
1
|
+
{"version":3,"file":"BrowserWebSocketClientAdapter.d.ts","sourceRoot":"","sources":["../src/BrowserWebSocketClientAdapter.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,YAAY,EAEb,MAAM,2BAA2B,CAAA;AAClC,OAAO,SAAS,MAAM,eAAe,CAAA;AAIrC,OAAO,EACL,iBAAiB,EAKlB,MAAM,eAAe,CAAA;AAKtB,uBAAe,uBAAwB,SAAQ,cAAc;IAC3D,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,qBAAa,6BAA8B,SAAQ,uBAAuB;;aAQtD,GAAG,EAAE,MAAM;aACX,aAAa;IAJ/B,YAAY,CAAC,EAAE,MAAM,CAAA;gBAGH,GAAG,EAAE,MAAM,EACX,aAAa,SAAO;IAMtC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY;IAqCnD,MAAM,aAKL;IAGD,OAAO,aAWN;IAED,SAAS,UAAW,sBAAsB,UAEzC;IAED,mFAAmF;IACnF,OAAO,UAED,KAAK,GACL,oBAAoB,UAezB;IAQD,IAAI;IAUJ,UAAU;IAMV,IAAI,CAAC,OAAO,EAAE,iBAAiB;IAY/B,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAU9D,cAAc,CAAC,YAAY,EAAE,UAAU;CAiBxC"}
|
|
@@ -75,15 +75,23 @@ export class BrowserWebSocketClientAdapter extends WebSocketNetworkAdapter {
|
|
|
75
75
|
onMessage = (event) => {
|
|
76
76
|
this.receiveMessage(event.data);
|
|
77
77
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
/** The websocket error handler signature is different on node and the browser. */
|
|
79
|
+
onError = (event // node
|
|
80
|
+
) => {
|
|
81
|
+
if ("error" in event) {
|
|
82
|
+
// (node)
|
|
83
|
+
if (event.error.code !== "ECONNREFUSED") {
|
|
84
|
+
/* c8 ignore next */
|
|
85
|
+
throw event.error;
|
|
86
|
+
}
|
|
82
87
|
}
|
|
83
88
|
else {
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
// (browser) We get no information about errors. https://stackoverflow.com/a/31003057/239663
|
|
90
|
+
// There will be an error logged in the console (`WebSocket connection to 'wss://foo.com/'
|
|
91
|
+
// failed`), but by design the error is unavailable to scripts. We'll just assume this is a
|
|
92
|
+
// failed connection.
|
|
86
93
|
}
|
|
94
|
+
this.#log("Connection failed, retrying...");
|
|
87
95
|
};
|
|
88
96
|
#ready() {
|
|
89
97
|
if (this.#isReady)
|
|
@@ -4,7 +4,7 @@ const log = debug("WebsocketServer");
|
|
|
4
4
|
import { cbor as cborHelpers, NetworkAdapter, } from "@automerge/automerge-repo";
|
|
5
5
|
import { isJoinMessage, isLeaveMessage, } from "./messages.js";
|
|
6
6
|
import { ProtocolV1 } from "./protocolVersion.js";
|
|
7
|
-
import assert from "assert";
|
|
7
|
+
import { assert } from "./assert.js";
|
|
8
8
|
import { toArrayBuffer } from "./toArrayBuffer.js";
|
|
9
9
|
const { encode, decode } = cborHelpers;
|
|
10
10
|
export class NodeWSServerAdapter extends NetworkAdapter {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automerge/automerge-repo-network-websocket",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "isomorphic node/browser Websocket network adapter for Automerge Repo",
|
|
5
5
|
"repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo-network-websocket",
|
|
6
6
|
"author": "Peter van Hardenberg <pvh@pvh.ca>",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
|
-
"watch": "npm-watch",
|
|
12
|
+
"watch": "npm-watch build",
|
|
13
13
|
"test": "vitest"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@automerge/automerge-repo": "1.1.
|
|
16
|
+
"@automerge/automerge-repo": "1.1.3",
|
|
17
17
|
"cbor-x": "^1.3.0",
|
|
18
18
|
"debug": "^4.3.4",
|
|
19
19
|
"eventemitter3": "^5.0.1",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "f59ba3612d1110003e2365fe0fe5a799539f1b59"
|
|
35
35
|
}
|
|
@@ -100,14 +100,25 @@ export class BrowserWebSocketClientAdapter extends WebSocketNetworkAdapter {
|
|
|
100
100
|
this.receiveMessage(event.data as Uint8Array)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
/** The websocket error handler signature is different on node and the browser. */
|
|
104
|
+
onError = (
|
|
105
|
+
event:
|
|
106
|
+
| Event // browser
|
|
107
|
+
| WebSocket.ErrorEvent // node
|
|
108
|
+
) => {
|
|
109
|
+
if ("error" in event) {
|
|
110
|
+
// (node)
|
|
111
|
+
if (event.error.code !== "ECONNREFUSED") {
|
|
112
|
+
/* c8 ignore next */
|
|
113
|
+
throw event.error
|
|
114
|
+
}
|
|
107
115
|
} else {
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
// (browser) We get no information about errors. https://stackoverflow.com/a/31003057/239663
|
|
117
|
+
// There will be an error logged in the console (`WebSocket connection to 'wss://foo.com/'
|
|
118
|
+
// failed`), but by design the error is unavailable to scripts. We'll just assume this is a
|
|
119
|
+
// failed connection.
|
|
110
120
|
}
|
|
121
|
+
this.#log("Connection failed, retrying...")
|
|
111
122
|
}
|
|
112
123
|
|
|
113
124
|
#ready() {
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
isLeaveMessage,
|
|
18
18
|
} from "./messages.js"
|
|
19
19
|
import { ProtocolV1, ProtocolVersion } from "./protocolVersion.js"
|
|
20
|
-
import assert from "assert"
|
|
20
|
+
import { assert } from "./assert.js"
|
|
21
21
|
import { toArrayBuffer } from "./toArrayBuffer.js"
|
|
22
22
|
|
|
23
23
|
const { encode, decode } = cborHelpers
|