@styris-ame/y-engineio 1.1.0

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.
@@ -0,0 +1,135 @@
1
+ export const messageSync: 0;
2
+ export const messageQueryAwareness: 3;
3
+ export const messageAwareness: 1;
4
+ export const messageAuth: 2;
5
+ /**
6
+ * Engine.IO Provider for Yjs. Creates an engine.io connection to sync the shared
7
+ * document. Unlike a raw WebSocket, engine.io connects to a single endpoint and
8
+ * has no document name in the URL, so the room name is sent as the `room`
9
+ * handshake query parameter, letting the server accept or reject the connection
10
+ * before any sync frames are exchanged.
11
+ *
12
+ * @example
13
+ * import * as Y from 'yjs'
14
+ * import { EngineIOProvider } from '@styris-ame/y-engineio'
15
+ * const doc = new Y.Doc()
16
+ * const provider = new EngineIOProvider('http://localhost:1234', 'my-document-name', doc)
17
+ *
18
+ * @extends {ObservableV2<{ 'connection-close': (event: any, provider: EngineIOProvider) => any, 'status': (event: { status: 'connected' | 'disconnected' | 'connecting' }) => any, 'connection-error': (event: any, provider: EngineIOProvider) => any, 'sync': (state: boolean) => any, 'synced': (state: boolean) => any }>}
19
+ */
20
+ export class EngineIOProvider extends ObservableV2<{
21
+ 'connection-close': (event: any, provider: EngineIOProvider) => any;
22
+ status: (event: {
23
+ status: "connected" | "disconnected" | "connecting";
24
+ }) => any;
25
+ 'connection-error': (event: any, provider: EngineIOProvider) => any;
26
+ sync: (state: boolean) => any;
27
+ synced: (state: boolean) => any;
28
+ }> {
29
+ /**
30
+ * @param {string} serverUrl engine.io server origin, e.g. 'http://localhost:1234'
31
+ * @param {string} roomname
32
+ * @param {Y.Doc} doc
33
+ * @param {object} opts
34
+ * @param {boolean} [opts.connect]
35
+ * @param {awarenessProtocol.Awareness} [opts.awareness]
36
+ * @param {Object<string,string>} [opts.params] url query params, passed to engine.io as `query`
37
+ * @param {object} [opts.engineOptions] options forwarded to the engine.io-client `Socket` (e.g. `path`, `transports`, `withCredentials`, `extraHeaders`)
38
+ * @param {typeof Engine} [opts.EngineClass] override the engine.io `Socket` constructor (e.g. for testing)
39
+ * @param {number} [opts.resyncInterval] Request server state every `resyncInterval` milliseconds
40
+ * @param {number} [opts.maxBackoffTime] Maximum amount of time to wait before trying to reconnect (we try to reconnect using exponential backoff)
41
+ * @param {boolean} [opts.disableBc] Disable cross-tab BroadcastChannel communication
42
+ */
43
+ constructor(serverUrl: string, roomname: string, doc: Y.Doc, { connect, awareness, params, engineOptions, EngineClass, resyncInterval, maxBackoffTime, disableBc }?: {
44
+ connect?: boolean | undefined;
45
+ awareness?: awarenessProtocol.Awareness | undefined;
46
+ params?: {
47
+ [x: string]: string;
48
+ } | undefined;
49
+ engineOptions?: object | undefined;
50
+ EngineClass?: typeof Engine | undefined;
51
+ resyncInterval?: number | undefined;
52
+ maxBackoffTime?: number | undefined;
53
+ disableBc?: boolean | undefined;
54
+ });
55
+ serverUrl: string;
56
+ bcChannel: string;
57
+ maxBackoffTime: number;
58
+ /**
59
+ * The specified url parameters. This can be safely updated. The changed parameters will be used
60
+ * when a new connection is established.
61
+ * @type {Object<string,string>}
62
+ */
63
+ params: {
64
+ [x: string]: string;
65
+ };
66
+ /**
67
+ * Options forwarded verbatim to the engine.io-client `Socket`.
68
+ * @type {object}
69
+ */
70
+ engineOptions: object;
71
+ roomname: string;
72
+ doc: Y.Doc;
73
+ _Engine: typeof Engine;
74
+ awareness: awarenessProtocol.Awareness;
75
+ connected: boolean;
76
+ connecting: boolean;
77
+ bcconnected: boolean;
78
+ disableBc: boolean;
79
+ unsuccessfulReconnects: number;
80
+ messageHandlers: ((arg0: encoding.Encoder, arg1: decoding.Decoder, arg2: EngineIOProvider, arg3: boolean, arg4: number) => void)[];
81
+ /**
82
+ * @type {boolean}
83
+ */
84
+ _synced: boolean;
85
+ /**
86
+ * The engine.io-client `Socket`, or null when disconnected.
87
+ * @type {Engine?}
88
+ */
89
+ engine: Engine | null;
90
+ lastMessageReceived: number;
91
+ /**
92
+ * Whether to connect to other peers or not
93
+ * @type {boolean}
94
+ */
95
+ shouldConnect: boolean;
96
+ /**
97
+ * @type {number}
98
+ */
99
+ _resyncInterval: number;
100
+ /**
101
+ * @param {ArrayBuffer} data
102
+ * @param {any} origin
103
+ */
104
+ _bcSubscriber: (data: ArrayBuffer, origin: any) => void;
105
+ /**
106
+ * Listens to Yjs updates and sends them to remote peers (engine.io and broadcastchannel)
107
+ * @param {Uint8Array} update
108
+ * @param {any} origin
109
+ */
110
+ _updateHandler: (update: Uint8Array, origin: any) => void;
111
+ /**
112
+ * @param {any} changed
113
+ * @param {any} _origin
114
+ */
115
+ _awarenessUpdateHandler: ({ added, updated, removed }: any, _origin: any) => void;
116
+ _exitHandler: () => void;
117
+ _checkInterval: any;
118
+ get url(): string;
119
+ set synced(state: boolean);
120
+ /**
121
+ * @type {boolean}
122
+ */
123
+ get synced(): boolean;
124
+ connectBc(): void;
125
+ disconnectBc(): void;
126
+ disconnect(): void;
127
+ connect(): void;
128
+ }
129
+ import { ObservableV2 } from 'lib0/observable';
130
+ import * as Y from 'yjs';
131
+ import { Socket as Engine } from 'engine.io-client';
132
+ import * as awarenessProtocol from 'y-protocols/awareness';
133
+ import * as encoding from 'lib0/encoding';
134
+ import * as decoding from 'lib0/decoding';
135
+ //# sourceMappingURL=y-engineio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"y-engineio.d.ts","sourceRoot":"","sources":["../src/y-engineio.js"],"names":[],"mappings":"AAmBA,0BAA2B,CAAC,CAAA;AAC5B,oCAAqC,CAAC,CAAA;AACtC,+BAAgC,CAAC,CAAA;AACjC,0BAA2B,CAAC,CAAA;AA6P5B;;;;;;;;;;;;;;GAcG;AACH;wBAFgD,CAAC,KAAK,EAAE,GAAG,EAAG,QAAQ,EAAE,gBAAgB,KAAK,GAAG;YAAY,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,YAAY,CAAA;KAAE,KAAK,GAAG;wBAAsB,CAAC,KAAK,EA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B;0BAJhC,eAAe;0BACf,eAAe"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@styris-ame/y-engineio",
3
+ "version": "1.1.0",
4
+ "description": "Engine.IO provider for Yjs (Yjs v13 line)",
5
+ "main": "./dist/y-engineio.cjs",
6
+ "module": "./src/y-engineio.js",
7
+ "types": "./dist/y-engineio.d.ts",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "scripts": {
11
+ "clean": "rm -rf dist",
12
+ "dist": "npm run clean && rollup -c && tsc --skipLibCheck",
13
+ "lint": "standard && tsc --skipLibCheck",
14
+ "test": "node ./test/index.js",
15
+ "preversion": "npm run dist && test -e dist/y-engineio.d.ts && test -e dist/y-engineio.cjs"
16
+ },
17
+ "files": [
18
+ "dist/*",
19
+ "src/*"
20
+ ],
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "module": "./src/y-engineio.js",
25
+ "import": "./src/y-engineio.js",
26
+ "require": "./dist/y-engineio.cjs",
27
+ "types": "./dist/y-engineio.d.ts",
28
+ "default": "./src/y-engineio.js"
29
+ }
30
+ },
31
+ "keywords": [
32
+ "Yjs",
33
+ "engine.io"
34
+ ],
35
+ "license": "MIT",
36
+ "standard": {
37
+ "ignore": [
38
+ "/dist",
39
+ "/node_modules"
40
+ ]
41
+ },
42
+ "dependencies": {
43
+ "engine.io-client": "^6.6.5",
44
+ "lib0": "^0.2.99",
45
+ "y-protocols": "^1.0.6"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^22.14.0",
49
+ "rollup": "^4.43.0",
50
+ "standard": "^17.1.2",
51
+ "typescript": "^5.8.3",
52
+ "yjs": "^13.6.0"
53
+ },
54
+ "peerDependencies": {
55
+ "yjs": "^13.6.0"
56
+ },
57
+ "engines": {
58
+ "npm": ">=8.0.0",
59
+ "node": ">=16.0.0"
60
+ }
61
+ }