yrby-client 0.4.3 → 0.6.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.
- package/README.md +250 -36
- package/dist/actioncable_provider.d.ts +26 -1
- package/dist/actioncable_provider.d.ts.map +1 -1
- package/dist/actioncable_provider.js +295 -150
- package/dist/actioncable_provider.js.map +1 -1
- package/dist/cjs/actioncable_provider.d.ts +26 -1
- package/dist/cjs/actioncable_provider.js +296 -151
- package/dist/cjs/document_element.d.ts +24 -0
- package/dist/cjs/document_element.js +260 -0
- package/dist/cjs/document_session.d.ts +62 -0
- package/dist/cjs/document_session.js +335 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/reliable_sync.d.ts +18 -31
- package/dist/cjs/reliable_sync.js +128 -98
- package/dist/cjs/turbo_adapter.d.ts +9 -0
- package/dist/cjs/turbo_adapter.js +81 -0
- package/dist/cjs/y_protocol_session.d.ts +7 -14
- package/dist/cjs/y_protocol_session.js +97 -92
- package/dist/document_element.d.ts +25 -0
- package/dist/document_element.d.ts.map +1 -0
- package/dist/document_element.js +225 -0
- package/dist/document_element.js.map +1 -0
- package/dist/document_session.d.ts +63 -0
- package/dist/document_session.d.ts.map +1 -0
- package/dist/document_session.js +296 -0
- package/dist/document_session.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/reliable_sync.d.ts +18 -31
- package/dist/reliable_sync.d.ts.map +1 -1
- package/dist/reliable_sync.js +128 -98
- package/dist/reliable_sync.js.map +1 -1
- package/dist/turbo_adapter.d.ts +10 -0
- package/dist/turbo_adapter.d.ts.map +1 -0
- package/dist/turbo_adapter.js +78 -0
- package/dist/turbo_adapter.js.map +1 -0
- package/dist/y_protocol_session.d.ts +7 -14
- package/dist/y_protocol_session.d.ts.map +1 -1
- package/dist/y_protocol_session.js +97 -92
- package/dist/y_protocol_session.js.map +1 -1
- package/package.json +29 -6
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
// the server's persistence/ack path.
|
|
10
10
|
//
|
|
11
11
|
// The constructor does not auto-connect: wire up your editor binding first, then
|
|
12
|
-
// call `connect()`. Watch the connection with `onStatusChange(({ status }) => ...)`
|
|
13
|
-
// or the `status`
|
|
14
|
-
// `
|
|
15
|
-
//
|
|
12
|
+
// call `connect()`. Watch the connection with `onStatusChange(({ status, pending }) => ...)`
|
|
13
|
+
// or the `status` and `hasPending` getters. Editors that must not bind before the first sync
|
|
14
|
+
// can `await provider.whenSynced` after connect(). On `disconnect()`/`destroy()`,
|
|
15
|
+
// and on browser `pagehide`, the provider broadcasts a presence removal so peers
|
|
16
|
+
// drop our cursor right away instead of waiting for the awareness timeout.
|
|
16
17
|
import { YProtocolSession, MessageType } from "./y_protocol_session.js";
|
|
17
18
|
import { toBase64, fromBase64 } from "./base64.js";
|
|
18
19
|
import { Awareness } from "y-protocols/awareness";
|
|
@@ -23,27 +24,53 @@ export class ActionCableProvider {
|
|
|
23
24
|
channelParams;
|
|
24
25
|
awareness;
|
|
25
26
|
session;
|
|
26
|
-
#
|
|
27
|
+
#state = { phase: "disconnected" };
|
|
27
28
|
#onError;
|
|
28
|
-
|
|
29
|
-
#
|
|
29
|
+
// The last event sent to listeners. A refresh notifies them only when a field differs.
|
|
30
|
+
#last = { status: "disconnected", pending: false };
|
|
30
31
|
#statusListeners = new Set();
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
32
|
+
#resolveSynced;
|
|
33
|
+
#onDocUpdate = () => this.#refreshStatus(); // a local edit may have made the queue non-empty
|
|
34
|
+
#page = null;
|
|
35
|
+
/**
|
|
36
|
+
* Resolves once the document has first caught up with the server. Most
|
|
37
|
+
* editor bindings seed an empty document when they mount, so binding
|
|
38
|
+
* before the server's state arrives makes each client insert its own
|
|
39
|
+
* top-level node. Create the editor after this resolves:
|
|
40
|
+
*
|
|
41
|
+
* provider.connect();
|
|
42
|
+
* await provider.whenSynced;
|
|
43
|
+
* // now hand the doc to the editor binding
|
|
44
|
+
*
|
|
45
|
+
* It resolves on the first catch-up and remains resolved across later
|
|
46
|
+
* reconnects, even while `synced` is false during a re-handshake. Use
|
|
47
|
+
* `onStatusChange` to track the live connection. If the provider is
|
|
48
|
+
* destroyed before the first sync, it never resolves.
|
|
49
|
+
*/
|
|
50
|
+
whenSynced = new Promise((resolve) => { this.#resolveSynced = resolve; });
|
|
34
51
|
constructor(doc, consumer, channelName, channelParams = {}, opts = {}) {
|
|
35
52
|
this.doc = doc;
|
|
36
53
|
this.consumer = consumer;
|
|
37
54
|
this.channelName = channelName;
|
|
38
55
|
this.channelParams = channelParams;
|
|
39
|
-
|
|
40
|
-
this.#onError =
|
|
56
|
+
const onError = opts.onError ?? ((error, context) => console.warn(`[yrby] ${context}:`, error));
|
|
57
|
+
this.#onError = (error, context) => {
|
|
58
|
+
try {
|
|
59
|
+
onError(error, context);
|
|
60
|
+
}
|
|
61
|
+
catch (callbackError) {
|
|
62
|
+
console.warn("[yrby] onError callback failed:", callbackError, "while reporting:", error);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
this.awareness = new ProviderAwareness(doc, this.#onError);
|
|
41
66
|
this.session = new YProtocolSession(doc, {
|
|
42
67
|
awareness: this.awareness,
|
|
43
68
|
resendInterval: opts.resendInterval,
|
|
44
69
|
onError: this.#onError,
|
|
45
70
|
send: (frame, id) => this.#send(frame, id),
|
|
46
71
|
});
|
|
72
|
+
// Registered after the session's listener, so the queue already has the edit.
|
|
73
|
+
this.doc.on("update", this.#onDocUpdate);
|
|
47
74
|
}
|
|
48
75
|
/** True once the document has caught up with the server (received a SyncStep2). */
|
|
49
76
|
get synced() {
|
|
@@ -70,7 +97,7 @@ export class ActionCableProvider {
|
|
|
70
97
|
}
|
|
71
98
|
/** Current connection status. See {@link ProviderStatus}. */
|
|
72
99
|
get status() {
|
|
73
|
-
return this.#
|
|
100
|
+
return this.#computeStatus();
|
|
74
101
|
}
|
|
75
102
|
/** Subscribe to status changes. Returns an unsubscribe function. */
|
|
76
103
|
onStatusChange(listener) {
|
|
@@ -78,170 +105,288 @@ export class ActionCableProvider {
|
|
|
78
105
|
return () => this.#statusListeners.delete(listener);
|
|
79
106
|
}
|
|
80
107
|
connect() {
|
|
81
|
-
if (this.#
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
this.#installUnloadHandler();
|
|
135
|
-
this.#refreshStatus(); // -> "connecting"
|
|
136
|
-
}
|
|
137
|
-
disconnect() {
|
|
138
|
-
if (!this.#subscription)
|
|
139
|
-
return;
|
|
140
|
-
const sub = this.#subscription;
|
|
141
|
-
// Tell peers we're gone while the transport is still live, then pause and
|
|
142
|
-
// detach. Defer the unsubscribe one microtask so the removal frame flushes
|
|
143
|
-
// before the channel tears down.
|
|
144
|
-
this.session.removeLocalAwareness();
|
|
145
|
-
this.session.onDisconnect();
|
|
146
|
-
this.#connected = false;
|
|
147
|
-
this.#subscription = null;
|
|
148
|
-
this.#removeUnloadHandler();
|
|
149
|
-
// Universal teardown: both @rails/actioncable and @anycable/web subscriptions
|
|
150
|
-
// expose unsubscribe() (Rails' just calls consumer.subscriptions.remove(this)
|
|
151
|
-
// internally). @anycable has NO consumer.subscriptions.remove, so calling that
|
|
152
|
-
// would throw there.
|
|
153
|
-
queueMicrotask(() => sub.unsubscribe?.());
|
|
154
|
-
this.#refreshStatus(); // -> "disconnected"
|
|
155
|
-
}
|
|
156
|
-
destroy() {
|
|
108
|
+
if (this.#destroying())
|
|
109
|
+
throw new Error("provider is destroyed");
|
|
110
|
+
if (this.#state.phase !== "disconnected")
|
|
111
|
+
return;
|
|
112
|
+
const attempt = {};
|
|
113
|
+
this.#state = { phase: "subscribing", attempt };
|
|
114
|
+
// A consumer may invoke callbacks inside create(), before the subscription
|
|
115
|
+
// is installed, so on() defers those by one microtask.
|
|
116
|
+
const on = (callback) => (...args) => {
|
|
117
|
+
const run = () => { if (this.#active(attempt))
|
|
118
|
+
callback(...args); };
|
|
119
|
+
if (this.#state.phase === "subscribing")
|
|
120
|
+
queueMicrotask(run);
|
|
121
|
+
else
|
|
122
|
+
run();
|
|
123
|
+
};
|
|
124
|
+
let subscription;
|
|
125
|
+
try {
|
|
126
|
+
subscription = this.consumer.subscriptions.create({ channel: this.channelName, ...this.channelParams }, {
|
|
127
|
+
received: on((message) => this.#receive(message, attempt)),
|
|
128
|
+
connected: on(() => this.#connected()),
|
|
129
|
+
disconnected: on(() => this.#lost()),
|
|
130
|
+
rejected: on(() => this.#stop("reject")),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (!this.#subscribing(attempt))
|
|
135
|
+
return;
|
|
136
|
+
this.#state = { phase: "disconnected" };
|
|
137
|
+
this.#refreshStatus();
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
// disconnect() or destroy() ran inside create().
|
|
141
|
+
if (!this.#subscribing(attempt)) {
|
|
142
|
+
this.#unsubscribe(subscription);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.#state = { phase: "connecting", attempt, subscription };
|
|
146
|
+
this.#watchPage();
|
|
147
|
+
this.#refreshStatus();
|
|
148
|
+
}
|
|
149
|
+
disconnect() { this.#stop("disconnect"); }
|
|
150
|
+
/**
|
|
151
|
+
* Resubscribes with updated channel params, such as a renewed grant. This
|
|
152
|
+
* replaces only the cable subscription and keeps the doc, the delivery
|
|
153
|
+
* queue, awareness, and this provider's ack route. Does nothing after
|
|
154
|
+
* destroy().
|
|
155
|
+
*/
|
|
156
|
+
renew(params) {
|
|
157
|
+
if (this.#destroying())
|
|
158
|
+
return;
|
|
159
|
+
Object.assign(this.channelParams, params);
|
|
157
160
|
this.disconnect();
|
|
158
|
-
this.
|
|
159
|
-
this.awareness.destroy(); // stops its reaper timer
|
|
160
|
-
this.#statusListeners.clear();
|
|
161
|
+
this.connect();
|
|
161
162
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return "connecting";
|
|
167
|
-
return this.session.synced ? "synced" : "connected";
|
|
163
|
+
destroy() { this.#stop("destroy"); }
|
|
164
|
+
#destroying() {
|
|
165
|
+
const state = this.#state;
|
|
166
|
+
return state.phase === "destroyed" || (state.phase === "stopping" && state.reason === "destroy");
|
|
168
167
|
}
|
|
169
|
-
#
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
168
|
+
#subscribing(attempt) {
|
|
169
|
+
return this.#state.phase === "subscribing" && this.#state.attempt === attempt;
|
|
170
|
+
}
|
|
171
|
+
// Cable callbacks run only for a connecting or connected subscription.
|
|
172
|
+
#active(attempt) {
|
|
173
|
+
const state = this.#state;
|
|
174
|
+
return (state.phase === "connecting" || state.phase === "connected") && state.attempt === attempt;
|
|
175
|
+
}
|
|
176
|
+
// The cable callbacks below run only for the active attempt, which on() in
|
|
177
|
+
// connect() checks.
|
|
178
|
+
#connected() {
|
|
179
|
+
const state = this.#state;
|
|
180
|
+
if (state.phase !== "connecting")
|
|
181
|
+
return;
|
|
182
|
+
this.#state = { ...state, phase: "connected" };
|
|
183
|
+
this.session.resume();
|
|
184
|
+
this.#refreshStatus();
|
|
185
|
+
}
|
|
186
|
+
#lost() {
|
|
187
|
+
const state = this.#state;
|
|
188
|
+
if (state.phase !== "connecting" && state.phase !== "connected")
|
|
189
|
+
return;
|
|
190
|
+
this.#state = { ...state, phase: "connecting" };
|
|
191
|
+
this.session.pause();
|
|
192
|
+
this.#refreshStatus();
|
|
193
|
+
}
|
|
194
|
+
#stop(reason) {
|
|
195
|
+
const state = this.#state;
|
|
196
|
+
if (state.phase === "destroyed")
|
|
197
|
+
return;
|
|
198
|
+
if (state.phase === "stopping") {
|
|
199
|
+
if (reason === "destroy")
|
|
200
|
+
state.reason = reason;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (state.phase === "disconnected" && reason === "disconnect")
|
|
204
|
+
return;
|
|
205
|
+
let finalReason = reason;
|
|
206
|
+
if ("subscription" in state) {
|
|
207
|
+
const stopping = { ...state, phase: "stopping", reason };
|
|
208
|
+
this.#state = stopping;
|
|
209
|
+
this.#unwatchPage();
|
|
210
|
+
// From here the provider ignores the old subscription's callbacks, but the
|
|
211
|
+
// subscription can still send our presence removal before its deferred
|
|
212
|
+
// unsubscribe.
|
|
188
213
|
this.session.removeLocalAwareness();
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (
|
|
214
|
+
this.session.pause();
|
|
215
|
+
this.#unsubscribe(state.subscription);
|
|
216
|
+
if (this.#state !== stopping)
|
|
192
217
|
return;
|
|
193
|
-
|
|
194
|
-
|
|
218
|
+
finalReason = stopping.reason; // a destroy() during those calls upgrades it
|
|
219
|
+
}
|
|
220
|
+
const destroyed = finalReason === "destroy";
|
|
221
|
+
this.#state = { phase: destroyed ? "destroyed" : "disconnected" };
|
|
222
|
+
if (destroyed)
|
|
223
|
+
this.#destroyOwned();
|
|
224
|
+
else if (finalReason === "reject")
|
|
225
|
+
this.#onError(new Error("subscription rejected by the server"), "rejected");
|
|
226
|
+
this.#refreshStatus();
|
|
227
|
+
if (destroyed)
|
|
228
|
+
this.#statusListeners.clear();
|
|
229
|
+
}
|
|
230
|
+
#destroyOwned() {
|
|
231
|
+
this.session.destroy();
|
|
232
|
+
this.awareness.destroy();
|
|
233
|
+
this.doc.off("update", this.#onDocUpdate);
|
|
234
|
+
}
|
|
235
|
+
#unsubscribe(subscription) {
|
|
236
|
+
queueMicrotask(() => {
|
|
237
|
+
try {
|
|
238
|
+
subscription.unsubscribe?.();
|
|
195
239
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
240
|
+
catch (error) {
|
|
241
|
+
this.#onError(error, "unsubscribe");
|
|
242
|
+
}
|
|
243
|
+
});
|
|
200
244
|
}
|
|
201
|
-
#
|
|
202
|
-
if (
|
|
245
|
+
#receive(message, attempt) {
|
|
246
|
+
if (message && message.ack !== undefined) {
|
|
247
|
+
this.session.acknowledge(message.ack);
|
|
248
|
+
this.#refreshStatus();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const awarenessPayload = message && message.awareness;
|
|
252
|
+
const payload = message && (awarenessPayload ?? message.update);
|
|
253
|
+
if (typeof payload !== "string")
|
|
254
|
+
return;
|
|
255
|
+
let frame;
|
|
256
|
+
try {
|
|
257
|
+
frame = fromBase64(payload);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
this.#onError(error, "received");
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (awarenessPayload !== undefined && frame[0] !== MessageType.Awareness) {
|
|
264
|
+
this.#onError(new Error("awareness envelope carried a non-awareness frame"), "received");
|
|
203
265
|
return;
|
|
204
|
-
if (this.#onUnload) {
|
|
205
|
-
window.removeEventListener("pagehide", this.#onUnload);
|
|
206
|
-
this.#onUnload = null;
|
|
207
266
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
267
|
+
const reply = this.session.receive(frame);
|
|
268
|
+
// Applying the frame runs doc observers, which may have replaced the connection.
|
|
269
|
+
if (reply && this.#active(attempt))
|
|
270
|
+
this.#send(reply, undefined);
|
|
271
|
+
this.#refreshStatus();
|
|
272
|
+
}
|
|
273
|
+
#computeStatus() {
|
|
274
|
+
switch (this.#state.phase) {
|
|
275
|
+
case "subscribing":
|
|
276
|
+
case "connecting": return "connecting";
|
|
277
|
+
case "connected": return this.session.synced ? "synced" : "connected";
|
|
278
|
+
default: return "disconnected";
|
|
211
279
|
}
|
|
212
280
|
}
|
|
281
|
+
#refreshStatus() {
|
|
282
|
+
const status = this.#computeStatus();
|
|
283
|
+
const pending = this.hasPending;
|
|
284
|
+
if (status === this.#last.status && pending === this.#last.pending)
|
|
285
|
+
return;
|
|
286
|
+
const event = this.#last = { status, pending };
|
|
287
|
+
if (status === "synced")
|
|
288
|
+
this.#resolveSynced();
|
|
289
|
+
// A throwing listener is an application bug. Report it and continue so one
|
|
290
|
+
// bad listener can't stop the others or break the cable callback that
|
|
291
|
+
// triggered this refresh.
|
|
292
|
+
for (const listener of this.#statusListeners) {
|
|
293
|
+
if (this.#last !== event)
|
|
294
|
+
break; // a listener caused a newer transition
|
|
295
|
+
try {
|
|
296
|
+
listener({ status, pending });
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
this.#onError(error, "listener");
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Handles presence across the page lifecycle. `pagehide` removes our cursor
|
|
304
|
+
// while the socket is still live, so peers drop it without waiting for the
|
|
305
|
+
// awareness timeout. A `pageshow` with `persisted` means the user came back
|
|
306
|
+
// through the bfcache, so we restore the cursor. Editor bindings set
|
|
307
|
+
// awareness only once at setup, so without this the user would return with
|
|
308
|
+
// no cursor.
|
|
309
|
+
#watchPage() {
|
|
310
|
+
if (typeof window === "undefined" || this.#page)
|
|
311
|
+
return;
|
|
312
|
+
let stashed = null;
|
|
313
|
+
const page = this.#page = {
|
|
314
|
+
hide: () => {
|
|
315
|
+
if (this.#page !== page)
|
|
316
|
+
return;
|
|
317
|
+
stashed = this.awareness.getLocalState();
|
|
318
|
+
this.session.removeLocalAwareness();
|
|
319
|
+
},
|
|
320
|
+
show: (event) => {
|
|
321
|
+
if (this.#page !== page || !event.persisted || !stashed)
|
|
322
|
+
return;
|
|
323
|
+
if (this.awareness.getLocalState() === null)
|
|
324
|
+
this.awareness.setLocalState(stashed);
|
|
325
|
+
stashed = null;
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
window.addEventListener("pagehide", this.#page.hide);
|
|
329
|
+
window.addEventListener("pageshow", this.#page.show);
|
|
330
|
+
}
|
|
331
|
+
#unwatchPage() {
|
|
332
|
+
if (!this.#page || typeof window === "undefined")
|
|
333
|
+
return;
|
|
334
|
+
const page = this.#page;
|
|
335
|
+
this.#page = null;
|
|
336
|
+
window.removeEventListener("pagehide", page.hide);
|
|
337
|
+
window.removeEventListener("pageshow", page.show);
|
|
338
|
+
}
|
|
213
339
|
// Send one raw protocol frame over the cable. Awareness frames are whispered
|
|
214
340
|
// when AnyCable exposes `subscription.whisper`; otherwise they fall back to a
|
|
215
341
|
// normal send. `id` (reliable doc updates) is tagged onto the envelope so the
|
|
216
342
|
// server can ack. A no-op while disconnected: reliable frames stay queued in
|
|
217
343
|
// the session and flush on the next connect().
|
|
218
344
|
#send(frame, id) {
|
|
219
|
-
const
|
|
220
|
-
if (!
|
|
345
|
+
const state = this.#state;
|
|
346
|
+
if (!("subscription" in state))
|
|
221
347
|
return;
|
|
222
|
-
const update = toBase64(frame);
|
|
223
348
|
const isAwareness = frame[0] === MessageType.Awareness;
|
|
349
|
+
if (state.phase === "stopping" && !isAwareness)
|
|
350
|
+
return;
|
|
351
|
+
const { subscription } = state;
|
|
352
|
+
const update = toBase64(frame);
|
|
224
353
|
// Route transport failures (sync throws, or @anycable/web's rejected
|
|
225
354
|
// promises) to onError instead of letting them escape into update
|
|
226
355
|
// handlers. A failed send is recoverable: reliable frames stay queued
|
|
227
|
-
// until acked, and awareness is best-effort anyway.
|
|
356
|
+
// until acked, and awareness is best-effort anyway. Failures from a
|
|
357
|
+
// subscription that has since been replaced go unreported.
|
|
358
|
+
const report = (error) => {
|
|
359
|
+
const current = this.#state;
|
|
360
|
+
if ("subscription" in current && current.subscription === subscription)
|
|
361
|
+
this.#onError(error, "send");
|
|
362
|
+
};
|
|
228
363
|
try {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
this.#observe(sub.send(payload));
|
|
364
|
+
const result = isAwareness && typeof subscription.whisper === "function"
|
|
365
|
+
? subscription.whisper({ awareness: update })
|
|
366
|
+
: subscription.send(id === undefined ? { update } : { update, id });
|
|
367
|
+
if (result instanceof Promise)
|
|
368
|
+
result.catch(report);
|
|
235
369
|
}
|
|
236
370
|
catch (error) {
|
|
237
|
-
|
|
371
|
+
report(error);
|
|
238
372
|
}
|
|
239
373
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
374
|
+
}
|
|
375
|
+
// Awareness runs application listeners during presence removal and destruction.
|
|
376
|
+
// A failing listener must not interrupt either one or leave the awareness timer
|
|
377
|
+
// running.
|
|
378
|
+
class ProviderAwareness extends Awareness {
|
|
379
|
+
onError;
|
|
380
|
+
constructor(doc, onError) {
|
|
381
|
+
super(doc);
|
|
382
|
+
this.onError = onError;
|
|
383
|
+
}
|
|
384
|
+
emit(...args) {
|
|
385
|
+
try {
|
|
386
|
+
super.emit(...args);
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
this.onError(error, `awareness:${args[0]}`);
|
|
245
390
|
}
|
|
246
391
|
}
|
|
247
392
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actioncable_provider.js","sourceRoot":"","sources":["../src/actioncable_provider.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kFAAkF;AAClF,kFAAkF;AAClF,qEAAqE;AACrE,gDAAgD;AAChD,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,qCAAqC;AACrC,EAAE;AACF,iFAAiF;AACjF,oFAAoF;AACpF,wEAAwE;AACxE,kFAAkF;AAClF,2DAA2D;AAC3D,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAgC,MAAM,yBAAyB,CAAC;AACtG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAoDlD,MAAM,OAAO,mBAAmB;IACrB,GAAG,CAAM;IACT,QAAQ,CAAgB;IACxB,WAAW,CAAS;IACpB,aAAa,CAAS;IACtB,SAAS,CAAY;IACrB,OAAO,CAAmB;IACnC,aAAa,GAA6B,IAAI,CAAC;IAC/C,QAAQ,CAA4C;IACpD,UAAU,GAAG,KAAK,CAAC;IACnB,OAAO,GAAmB,cAAc,CAAC;IACzC,gBAAgB,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC3D,SAAS,GAAwB,IAAI,CAAC;IACtC,UAAU,GAAkD,IAAI,CAAC;IACjE,gBAAgB,GAAmC,IAAI,CAAC;IAExD,YACE,GAAQ,EACR,QAAuB,EACvB,WAAmB,EACnB,gBAAwB,EAAE,EAC1B,OAAmC,EAAE;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,IAAI,S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AAW,IAAI,OAAO,YAAY,CAAC,OAAO,KAAK,UAAU;gBACtE,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;gBAC7C,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;YACtE,IAAI,MAAM,YAAY,OAAO;gBAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;CACF;AAED,gFAAgF;AAChF,gFAAgF;AAChF,WAAW;AACX,MAAM,iBAAkB,SAAQ,SAAS;IACA;IAAvC,YAAY,GAAQ,EAAmB,OAAkD;QACvF,KAAK,CAAC,GAAG,CAAC,CAAC;QAD0B,YAAO,GAAP,OAAO,CAA2C;IAEzF,CAAC;IACQ,IAAI,CAAC,GAAG,IAAmC;QAClD,IAAI,CAAC;YAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAAC,CAAC;QAC5B,OAAO,KAAK,EAAE,CAAC;YAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -9,9 +9,11 @@ import type { Doc } from "yjs";
|
|
|
9
9
|
* will retry shows as "connecting", not "disconnected".
|
|
10
10
|
*/
|
|
11
11
|
export type ProviderStatus = "connecting" | "connected" | "synced" | "disconnected";
|
|
12
|
-
/** Payload passed to onStatusChange listeners. */
|
|
12
|
+
/** Payload passed to onStatusChange listeners, which run when either field changes. */
|
|
13
13
|
export interface StatusEvent {
|
|
14
14
|
status: ProviderStatus;
|
|
15
|
+
/** True while local edits await the server's acknowledgment. */
|
|
16
|
+
pending: boolean;
|
|
15
17
|
}
|
|
16
18
|
/** The minimal slice of an ActionCable/AnyCable subscription this provider uses. */
|
|
17
19
|
export interface CableSubscription {
|
|
@@ -45,6 +47,22 @@ export declare class ActionCableProvider {
|
|
|
45
47
|
readonly channelParams: object;
|
|
46
48
|
readonly awareness: Awareness;
|
|
47
49
|
readonly session: YProtocolSession;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves once the document has first caught up with the server. Most
|
|
52
|
+
* editor bindings seed an empty document when they mount, so binding
|
|
53
|
+
* before the server's state arrives makes each client insert its own
|
|
54
|
+
* top-level node. Create the editor after this resolves:
|
|
55
|
+
*
|
|
56
|
+
* provider.connect();
|
|
57
|
+
* await provider.whenSynced;
|
|
58
|
+
* // now hand the doc to the editor binding
|
|
59
|
+
*
|
|
60
|
+
* It resolves on the first catch-up and remains resolved across later
|
|
61
|
+
* reconnects, even while `synced` is false during a re-handshake. Use
|
|
62
|
+
* `onStatusChange` to track the live connection. If the provider is
|
|
63
|
+
* destroyed before the first sync, it never resolves.
|
|
64
|
+
*/
|
|
65
|
+
readonly whenSynced: Promise<void>;
|
|
48
66
|
constructor(doc: Doc, consumer: CableConsumer, channelName: string, channelParams?: object, opts?: ActionCableProviderOptions);
|
|
49
67
|
/** True once the document has caught up with the server (received a SyncStep2). */
|
|
50
68
|
get synced(): boolean;
|
|
@@ -69,5 +87,12 @@ export declare class ActionCableProvider {
|
|
|
69
87
|
onStatusChange(listener: (event: StatusEvent) => void): () => void;
|
|
70
88
|
connect(): void;
|
|
71
89
|
disconnect(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Resubscribes with updated channel params, such as a renewed grant. This
|
|
92
|
+
* replaces only the cable subscription and keeps the doc, the delivery
|
|
93
|
+
* queue, awareness, and this provider's ack route. Does nothing after
|
|
94
|
+
* destroy().
|
|
95
|
+
*/
|
|
96
|
+
renew(params: object): void;
|
|
72
97
|
destroy(): void;
|
|
73
98
|
}
|