@hocuspocus/provider 1.0.0-alpha.27 → 1.0.0-alpha.31
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/hocuspocus-provider.cjs +126 -351
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +123 -347
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/CloseEvents.d.ts +23 -0
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
- package/dist/packages/common/src/index.d.ts +2 -0
- package/dist/packages/extension-database/src/Database.d.ts +32 -0
- package/dist/packages/extension-database/src/index.d.ts +1 -0
- package/dist/packages/extension-logger/src/Logger.d.ts +5 -0
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
- package/dist/packages/extension-throttle/src/index.d.ts +6 -2
- package/dist/packages/extension-webhook/src/index.d.ts +2 -3
- package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +4 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +17 -9
- package/dist/packages/provider/src/index.d.ts +0 -1
- package/dist/packages/provider/src/types.d.ts +10 -0
- package/dist/packages/server/src/Connection.d.ts +5 -5
- package/dist/packages/server/src/Debugger.d.ts +1 -2
- package/dist/packages/server/src/Document.d.ts +8 -5
- package/dist/packages/server/src/Hocuspocus.d.ts +32 -14
- package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
- package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
- package/dist/packages/server/src/index.d.ts +7 -0
- package/dist/packages/server/src/types.d.ts +92 -23
- package/dist/{demos/backend/src/express.d.ts → playground/backend/src/default.d.ts} +0 -0
- package/dist/{demos/backend/src/koa.d.ts → playground/backend/src/express.d.ts} +0 -0
- package/dist/{demos/backend/src/load-document.d.ts → playground/backend/src/koa.d.ts} +0 -0
- package/dist/{demos/backend/src/minimal.d.ts → playground/backend/src/load-document.d.ts} +0 -0
- package/dist/{demos → playground}/backend/src/monitor.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/redis.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/slow.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/webhook.d.ts +0 -0
- package/dist/tests/extension-logger/onListen.d.ts +1 -0
- package/dist/tests/extension-redis/onLoadDocument.d.ts +1 -0
- package/dist/tests/extension-redis/onSynced.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/closeConnections.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/getConnectionCount.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/getDocumentsCount.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onAwarenessChange.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onChange.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onStoreDocument.d.ts +1 -0
- package/dist/tests/extension-rocksdb/onLoadDocument.d.ts +1 -0
- package/dist/tests/extension-throttle/configuration.d.ts +1 -0
- package/dist/tests/provider/configuration.d.ts +1 -0
- package/dist/tests/provider/observeDeep.d.ts +1 -0
- package/dist/tests/provider/onAuthenticated.d.ts +1 -0
- package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
- package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
- package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/provider/onClose.d.ts +1 -0
- package/dist/tests/provider/onConnect.d.ts +1 -0
- package/dist/tests/provider/onDisconnect.d.ts +1 -0
- package/dist/tests/provider/onMessage.d.ts +1 -0
- package/dist/tests/provider/onOpen.d.ts +1 -0
- package/dist/tests/provider/onSynced.d.ts +1 -0
- package/dist/tests/server/address.d.ts +1 -0
- package/dist/tests/server/afterStoreDocument.d.ts +1 -0
- package/dist/tests/server/closeConnections.d.ts +1 -0
- package/dist/tests/server/getConnectionsCount.d.ts +1 -0
- package/dist/tests/server/getDocumentName.d.ts +1 -0
- package/dist/tests/server/getDocumentsCount.d.ts +1 -0
- package/dist/tests/server/getMessageLogs.d.ts +1 -0
- package/dist/tests/server/listen.d.ts +1 -0
- package/dist/tests/server/onAuthenticate.d.ts +1 -0
- package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/server/onChange.d.ts +1 -0
- package/dist/tests/server/onConfigure.d.ts +1 -0
- package/dist/tests/server/onConnect.d.ts +1 -0
- package/dist/tests/server/onDestroy.d.ts +1 -0
- package/dist/tests/server/onDisconnect.d.ts +1 -0
- package/dist/tests/server/onListen.d.ts +1 -0
- package/dist/tests/server/onLoadDocument.d.ts +1 -0
- package/dist/tests/server/onRequest.d.ts +1 -0
- package/dist/tests/server/onStoreDocument.d.ts +1 -0
- package/dist/tests/server/onUpgrade.d.ts +1 -0
- package/dist/tests/server/requiresAuthentication.d.ts +1 -0
- package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
- package/dist/tests/utils/createDirectory.d.ts +1 -0
- package/dist/tests/utils/flushRedis.d.ts +1 -0
- package/dist/tests/utils/index.d.ts +7 -0
- package/dist/tests/utils/newHocuspocus.d.ts +2 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
- package/dist/tests/utils/removeDirectory.d.ts +1 -0
- package/dist/tests/utils/sleep.d.ts +1 -0
- package/package.json +6 -5
- package/src/EventEmitter.ts +1 -1
- package/src/HocuspocusCloudProvider.ts +18 -10
- package/src/HocuspocusProvider.ts +100 -69
- package/src/index.ts +0 -1
- package/src/types.ts +10 -0
- package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
- package/dist/packages/provider/src/utils/index.d.ts +0 -1
- package/dist/packages/server/src/CloseEvents.d.ts +0 -4
- package/src/utils/awarenessStatesToArray.ts +0 -8
- package/src/utils/index.ts +0 -1
|
@@ -4,8 +4,9 @@ import * as time from 'lib0/time'
|
|
|
4
4
|
import { Awareness, removeAwarenessStates } from 'y-protocols/awareness'
|
|
5
5
|
import * as mutex from 'lib0/mutex'
|
|
6
6
|
import * as url from 'lib0/url'
|
|
7
|
-
import { Event, CloseEvent, MessageEvent } from 'ws'
|
|
7
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws'
|
|
8
8
|
import { retry } from '@lifeomic/attempt'
|
|
9
|
+
import { awarenessStatesToArray, Forbidden, Unauthorized } from '@hocuspocus/common'
|
|
9
10
|
import EventEmitter from './EventEmitter'
|
|
10
11
|
import { IncomingMessage } from './IncomingMessage'
|
|
11
12
|
import { MessageReceiver } from './MessageReceiver'
|
|
@@ -17,8 +18,8 @@ import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage'
|
|
|
17
18
|
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage'
|
|
18
19
|
import { UpdateMessage } from './OutgoingMessages/UpdateMessage'
|
|
19
20
|
import { OutgoingMessage } from './OutgoingMessage'
|
|
20
|
-
import awarenessStatesToArray from './utils/awarenessStatesToArray'
|
|
21
21
|
import { ConstructableOutgoingMessage } from './types'
|
|
22
|
+
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.'
|
|
22
23
|
|
|
23
24
|
export enum WebSocketStatus {
|
|
24
25
|
Connecting = 'connecting',
|
|
@@ -26,15 +27,19 @@ export enum WebSocketStatus {
|
|
|
26
27
|
Disconnected = 'disconnected',
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export
|
|
30
|
+
export type HocuspocusProviderConfiguration =
|
|
31
|
+
Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>>
|
|
32
|
+
& Partial<CompleteHocuspocusProviderConfiguration>
|
|
33
|
+
|
|
34
|
+
export interface CompleteHocuspocusProviderConfiguration {
|
|
30
35
|
/**
|
|
31
36
|
* URL of your @hocuspocus/server instance
|
|
32
37
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
url: string,
|
|
39
|
+
/**
|
|
40
|
+
* The identifier/name of your document
|
|
41
|
+
*/
|
|
42
|
+
name: string,
|
|
38
43
|
/**
|
|
39
44
|
* The actual Y.js document
|
|
40
45
|
*/
|
|
@@ -110,23 +115,27 @@ export interface HocuspocusProviderOptions {
|
|
|
110
115
|
onMessage: (event: MessageEvent) => void,
|
|
111
116
|
onOutgoingMessage: (message: OutgoingMessage) => void,
|
|
112
117
|
onStatus: (status: any) => void,
|
|
113
|
-
onSynced: () => void,
|
|
118
|
+
onSynced: ({ state }: { state: boolean }) => void,
|
|
114
119
|
onDisconnect: (event: CloseEvent) => void,
|
|
115
120
|
onClose: (event: CloseEvent) => void,
|
|
116
121
|
onDestroy: () => void,
|
|
117
|
-
onAwarenessUpdate: (states:
|
|
118
|
-
onAwarenessChange: (states:
|
|
122
|
+
onAwarenessUpdate: ({ states }: onAwarenessUpdateParameters) => void,
|
|
123
|
+
onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void,
|
|
124
|
+
/**
|
|
125
|
+
* Don’t output any warnings.
|
|
126
|
+
*/
|
|
127
|
+
quiet: boolean,
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
export class HocuspocusProvider extends EventEmitter {
|
|
122
|
-
public
|
|
131
|
+
public configuration: CompleteHocuspocusProviderConfiguration = {
|
|
132
|
+
name: '',
|
|
133
|
+
url: '',
|
|
123
134
|
// @ts-ignore
|
|
124
135
|
document: undefined,
|
|
125
136
|
// @ts-ignore
|
|
126
137
|
awareness: undefined,
|
|
127
138
|
WebSocketPolyfill: undefined,
|
|
128
|
-
url: '',
|
|
129
|
-
name: '',
|
|
130
139
|
token: null,
|
|
131
140
|
parameters: {},
|
|
132
141
|
connect: true,
|
|
@@ -163,6 +172,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
163
172
|
onDestroy: () => null,
|
|
164
173
|
onAwarenessUpdate: () => null,
|
|
165
174
|
onAwarenessChange: () => null,
|
|
175
|
+
quiet: false,
|
|
166
176
|
}
|
|
167
177
|
|
|
168
178
|
subscribedToBroadcastChannel = false
|
|
@@ -191,27 +201,27 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
191
201
|
reject: (reason?: any) => void
|
|
192
202
|
} | null = null
|
|
193
203
|
|
|
194
|
-
constructor(
|
|
204
|
+
constructor(configuration: HocuspocusProviderConfiguration) {
|
|
195
205
|
super()
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
this.
|
|
199
|
-
this.
|
|
200
|
-
this.
|
|
201
|
-
|
|
202
|
-
this.on('open', this.
|
|
203
|
-
this.on('authenticated', this.
|
|
204
|
-
this.on('authenticationFailed', this.
|
|
205
|
-
this.on('connect', this.
|
|
206
|
-
this.on('message', this.
|
|
207
|
-
this.on('outgoingMessage', this.
|
|
208
|
-
this.on('synced', this.
|
|
209
|
-
this.on('status', this.
|
|
210
|
-
this.on('disconnect', this.
|
|
211
|
-
this.on('close', this.
|
|
212
|
-
this.on('destroy', this.
|
|
213
|
-
this.on('awarenessUpdate', this.
|
|
214
|
-
this.on('awarenessChange', this.
|
|
206
|
+
this.setConfiguration(configuration)
|
|
207
|
+
|
|
208
|
+
this.configuration.document = configuration.document ? configuration.document : new Y.Doc()
|
|
209
|
+
this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document)
|
|
210
|
+
this.configuration.WebSocketPolyfill = configuration.WebSocketPolyfill ? configuration.WebSocketPolyfill : WebSocket
|
|
211
|
+
|
|
212
|
+
this.on('open', this.configuration.onOpen)
|
|
213
|
+
this.on('authenticated', this.configuration.onAuthenticated)
|
|
214
|
+
this.on('authenticationFailed', this.configuration.onAuthenticationFailed)
|
|
215
|
+
this.on('connect', this.configuration.onConnect)
|
|
216
|
+
this.on('message', this.configuration.onMessage)
|
|
217
|
+
this.on('outgoingMessage', this.configuration.onOutgoingMessage)
|
|
218
|
+
this.on('synced', this.configuration.onSynced)
|
|
219
|
+
this.on('status', this.configuration.onStatus)
|
|
220
|
+
this.on('disconnect', this.configuration.onDisconnect)
|
|
221
|
+
this.on('close', this.configuration.onClose)
|
|
222
|
+
this.on('destroy', this.configuration.onDestroy)
|
|
223
|
+
this.on('awarenessUpdate', this.configuration.onAwarenessUpdate)
|
|
224
|
+
this.on('awarenessChange', this.configuration.onAwarenessChange)
|
|
215
225
|
|
|
216
226
|
this.awareness.on('update', () => {
|
|
217
227
|
this.emit('awarenessUpdate', { states: awarenessStatesToArray(this.awareness.getStates()) })
|
|
@@ -223,22 +233,22 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
223
233
|
|
|
224
234
|
this.document.on('update', this.documentUpdateHandler.bind(this))
|
|
225
235
|
this.awareness.on('update', this.awarenessUpdateHandler.bind(this))
|
|
226
|
-
this.
|
|
236
|
+
this.registerEventListeners()
|
|
227
237
|
|
|
228
238
|
this.intervals.connectionChecker = setInterval(
|
|
229
239
|
this.checkConnection.bind(this),
|
|
230
|
-
this.
|
|
240
|
+
this.configuration.messageReconnectTimeout / 10,
|
|
231
241
|
)
|
|
232
242
|
|
|
233
|
-
if (this.
|
|
243
|
+
if (this.configuration.forceSyncInterval) {
|
|
234
244
|
this.intervals.forceSync = setInterval(
|
|
235
245
|
this.forceSync.bind(this),
|
|
236
|
-
this.
|
|
246
|
+
this.configuration.forceSyncInterval,
|
|
237
247
|
)
|
|
238
248
|
}
|
|
239
249
|
|
|
240
|
-
if (typeof
|
|
241
|
-
this.shouldConnect =
|
|
250
|
+
if (typeof configuration.connect !== 'undefined') {
|
|
251
|
+
this.shouldConnect = configuration.connect
|
|
242
252
|
}
|
|
243
253
|
|
|
244
254
|
if (!this.shouldConnect) {
|
|
@@ -248,8 +258,8 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
248
258
|
this.connect()
|
|
249
259
|
}
|
|
250
260
|
|
|
251
|
-
public
|
|
252
|
-
this.
|
|
261
|
+
public setConfiguration(configuration: Partial<HocuspocusProviderConfiguration> = {}): void {
|
|
262
|
+
this.configuration = { ...this.configuration, ...configuration }
|
|
253
263
|
}
|
|
254
264
|
|
|
255
265
|
async connect() {
|
|
@@ -262,14 +272,14 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
262
272
|
|
|
263
273
|
try {
|
|
264
274
|
await retry(this.createWebSocketConnection.bind(this), {
|
|
265
|
-
delay: this.
|
|
266
|
-
initialDelay: this.
|
|
267
|
-
factor: this.
|
|
268
|
-
maxAttempts: this.
|
|
269
|
-
minDelay: this.
|
|
270
|
-
maxDelay: this.
|
|
271
|
-
jitter: this.
|
|
272
|
-
timeout: this.
|
|
275
|
+
delay: this.configuration.delay,
|
|
276
|
+
initialDelay: this.configuration.initialDelay,
|
|
277
|
+
factor: this.configuration.factor,
|
|
278
|
+
maxAttempts: this.configuration.maxAttempts,
|
|
279
|
+
minDelay: this.configuration.minDelay,
|
|
280
|
+
maxDelay: this.configuration.maxDelay,
|
|
281
|
+
jitter: this.configuration.jitter,
|
|
282
|
+
timeout: this.configuration.timeout,
|
|
273
283
|
beforeAttempt: context => {
|
|
274
284
|
if (!this.shouldConnect) {
|
|
275
285
|
context.abort()
|
|
@@ -288,7 +298,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
288
298
|
createWebSocketConnection() {
|
|
289
299
|
return new Promise((resolve, reject) => {
|
|
290
300
|
// Init the WebSocket connection
|
|
291
|
-
const ws = new this.
|
|
301
|
+
const ws = new this.configuration.WebSocketPolyfill(this.url)
|
|
292
302
|
ws.binaryType = 'arraybuffer'
|
|
293
303
|
ws.onmessage = this.onMessage.bind(this)
|
|
294
304
|
ws.onclose = this.onClose.bind(this)
|
|
@@ -322,11 +332,11 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
322
332
|
}
|
|
323
333
|
|
|
324
334
|
get document() {
|
|
325
|
-
return this.
|
|
335
|
+
return this.configuration.document
|
|
326
336
|
}
|
|
327
337
|
|
|
328
338
|
get awareness() {
|
|
329
|
-
return this.
|
|
339
|
+
return this.configuration.awareness
|
|
330
340
|
}
|
|
331
341
|
|
|
332
342
|
checkConnection() {
|
|
@@ -341,7 +351,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
341
351
|
}
|
|
342
352
|
|
|
343
353
|
// Don’t close the connection when a message was received recently
|
|
344
|
-
if (this.
|
|
354
|
+
if (this.configuration.messageReconnectTimeout >= time.getUnixTime() - this.lastMessageReceived) {
|
|
345
355
|
return
|
|
346
356
|
}
|
|
347
357
|
|
|
@@ -358,11 +368,12 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
358
368
|
this.send(SyncStepOneMessage, { document: this.document })
|
|
359
369
|
}
|
|
360
370
|
|
|
361
|
-
|
|
371
|
+
registerEventListeners() {
|
|
362
372
|
if (typeof window === 'undefined') {
|
|
363
373
|
return
|
|
364
374
|
}
|
|
365
375
|
|
|
376
|
+
window.addEventListener('online', this.connect.bind(this))
|
|
366
377
|
window.addEventListener('beforeunload', () => {
|
|
367
378
|
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
|
|
368
379
|
})
|
|
@@ -400,17 +411,17 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
400
411
|
|
|
401
412
|
// Ensure that the URL always ends with /
|
|
402
413
|
get serverUrl() {
|
|
403
|
-
while (this.
|
|
404
|
-
return this.
|
|
414
|
+
while (this.configuration.url[this.configuration.url.length - 1] === '/') {
|
|
415
|
+
return this.configuration.url.slice(0, this.configuration.url.length - 1)
|
|
405
416
|
}
|
|
406
417
|
|
|
407
|
-
return this.
|
|
418
|
+
return this.configuration.url
|
|
408
419
|
}
|
|
409
420
|
|
|
410
421
|
get url() {
|
|
411
|
-
const encodedParams = url.encodeQueryParams(this.
|
|
422
|
+
const encodedParams = url.encodeQueryParams(this.configuration.parameters)
|
|
412
423
|
|
|
413
|
-
return `${this.serverUrl}/${this.
|
|
424
|
+
return `${this.serverUrl}/${this.configuration.name}${encodedParams.length === 0 ? '' : `?${encodedParams}`}`
|
|
414
425
|
}
|
|
415
426
|
|
|
416
427
|
get synced(): boolean {
|
|
@@ -428,7 +439,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
428
439
|
}
|
|
429
440
|
|
|
430
441
|
get isAuthenticationRequired(): boolean {
|
|
431
|
-
return !!this.
|
|
442
|
+
return !!this.configuration.token && !this.isAuthenticated
|
|
432
443
|
}
|
|
433
444
|
|
|
434
445
|
disconnect() {
|
|
@@ -455,12 +466,12 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
455
466
|
}
|
|
456
467
|
|
|
457
468
|
async getToken() {
|
|
458
|
-
if (typeof this.
|
|
459
|
-
const token = await this.
|
|
469
|
+
if (typeof this.configuration.token === 'function') {
|
|
470
|
+
const token = await this.configuration.token()
|
|
460
471
|
return token
|
|
461
472
|
}
|
|
462
473
|
|
|
463
|
-
return this.
|
|
474
|
+
return this.configuration.token
|
|
464
475
|
}
|
|
465
476
|
|
|
466
477
|
async webSocketConnectionEstablished() {
|
|
@@ -534,15 +545,29 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
534
545
|
this.emit('disconnect', { event })
|
|
535
546
|
}
|
|
536
547
|
|
|
548
|
+
if (event.code === Unauthorized.code) {
|
|
549
|
+
if (!this.configuration.quiet) {
|
|
550
|
+
console.warn('[HocuspocusProvider] An authentication token is required, but you didn’t send one. Try adding a `token` to your HocuspocusProvider configuration. Won’t try again.')
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
this.shouldConnect = false
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (event.code === Forbidden.code) {
|
|
557
|
+
if (!this.configuration.quiet) {
|
|
558
|
+
console.warn('[HocuspocusProvider] The provided authentication token isn’t allowed to connect to this server. Will try again.')
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
537
562
|
if (this.connectionAttempt) {
|
|
538
|
-
//
|
|
563
|
+
// That connection attempt failed.
|
|
539
564
|
this.rejectConnectionAttempt()
|
|
540
565
|
} else if (this.shouldConnect) {
|
|
541
|
-
// The connection was closed by the server
|
|
566
|
+
// The connection was closed by the server. Let’s just try again.
|
|
542
567
|
this.connect()
|
|
543
568
|
}
|
|
544
569
|
|
|
545
|
-
// If we’ll reconnect
|
|
570
|
+
// If we’ll reconnect, we’re done for now.
|
|
546
571
|
if (this.shouldConnect) {
|
|
547
572
|
return
|
|
548
573
|
}
|
|
@@ -580,10 +605,16 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
580
605
|
this.document.off('update', this.documentUpdateHandler)
|
|
581
606
|
|
|
582
607
|
this.removeAllListeners()
|
|
608
|
+
|
|
609
|
+
if (typeof window === 'undefined') {
|
|
610
|
+
return
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
window.removeEventListener('online', this.connect.bind(this))
|
|
583
614
|
}
|
|
584
615
|
|
|
585
616
|
get broadcastChannel() {
|
|
586
|
-
return `${this.serverUrl}/${this.
|
|
617
|
+
return `${this.serverUrl}/${this.configuration.name}`
|
|
587
618
|
}
|
|
588
619
|
|
|
589
620
|
broadcastChannelSubscriber(data: ArrayBuffer) {
|
|
@@ -624,7 +655,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
624
655
|
}
|
|
625
656
|
|
|
626
657
|
broadcast(Message: ConstructableOutgoingMessage, args?: any) {
|
|
627
|
-
if (!this.
|
|
658
|
+
if (!this.configuration.broadcast) {
|
|
628
659
|
return
|
|
629
660
|
}
|
|
630
661
|
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -41,3 +41,13 @@ export type ConstructableOutgoingMessage =
|
|
|
41
41
|
Constructable<SyncStepOneMessage> |
|
|
42
42
|
Constructable<SyncStepTwoMessage> |
|
|
43
43
|
Constructable<UpdateMessage>
|
|
44
|
+
|
|
45
|
+
export type onAwarenessUpdateParameters = {
|
|
46
|
+
states: StatesArray
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type onAwarenessChangeParameters = {
|
|
50
|
+
states: StatesArray
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type StatesArray = { clientId: number, [key: string | number]: any }[]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as awarenessStatesToArray } from './awarenessStatesToArray';
|
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as awarenessStatesToArray } from './awarenessStatesToArray'
|