(
serverUrl: string,
roomname: string,
doc: Y.Doc,
{
connect = true,
awareness = new awarenessProtocol.Awareness(doc),
params = {},
WebSocketPolyfill = WebSocket,
resyncInterval = -1,
maxBackoffTime = 2500,
disableBc = false,
}: {
connect?: boolean
awareness?: awarenessProtocol.Awareness
params?: { [key: string]: string }
WebSocketPolyfill?: typeof WebSocket
resyncInterval?: number
maxBackoffTime?: number
disableBc?: boolean
} = {},
)
| 262 | _updateSubDocHandler: (update: Uint8Array, origin: unknown, doc: Y.Doc) => void |
| 263 | |
| 264 | constructor( |
| 265 | serverUrl: string, |
| 266 | roomname: string, |
| 267 | doc: Y.Doc, |
| 268 | { |
| 269 | connect = true, |
| 270 | awareness = new awarenessProtocol.Awareness(doc), |
| 271 | params = {}, |
| 272 | WebSocketPolyfill = WebSocket, |
| 273 | resyncInterval = -1, |
| 274 | maxBackoffTime = 2500, |
| 275 | disableBc = false, |
| 276 | }: { |
| 277 | connect?: boolean |
| 278 | awareness?: awarenessProtocol.Awareness |
| 279 | params?: { [key: string]: string } |
| 280 | WebSocketPolyfill?: typeof WebSocket |
| 281 | resyncInterval?: number |
| 282 | maxBackoffTime?: number |
| 283 | disableBc?: boolean |
| 284 | } = {}, |
| 285 | ) { |
| 286 | super() |
| 287 | // ensure that url is always ends with / |
| 288 | while (serverUrl[serverUrl.length - 1] === '/') { |
| 289 | serverUrl = serverUrl.slice(0, serverUrl.length - 1) |
| 290 | } |
| 291 | const encodedParams = url.encodeQueryParams(params) |
| 292 | this.maxBackoffTime = maxBackoffTime |
| 293 | this.bcChannel = serverUrl + '/' + roomname |
| 294 | this.url = serverUrl + '/' + roomname + (encodedParams.length === 0 ? '' : '?' + encodedParams) |
| 295 | this.roomname = roomname |
| 296 | this.doc = doc |
| 297 | this._WS = WebSocketPolyfill |
| 298 | this.awareness = awareness |
| 299 | this.wsconnected = false |
| 300 | this.wsconnecting = false |
| 301 | this.bcconnected = false |
| 302 | this.disableBc = disableBc |
| 303 | this.wsUnsuccessfulReconnects = 0 |
| 304 | this.messageHandlers = messageHandlers.slice() |
| 305 | this._synced = false |
| 306 | this.ws = null |
| 307 | this.wsLastMessageReceived = 0 |
| 308 | |
| 309 | this.shouldConnect = connect |
| 310 | |
| 311 | this._resyncInterval = 0 |
| 312 | if (resyncInterval > 0) { |
| 313 | // @ts-ignore |
| 314 | this._resyncInterval = setInterval(() => { |
| 315 | if (this.ws && this.ws.readyState === WebSocket.OPEN) { |
| 316 | // resend sync step 1 |
| 317 | const encoder = encoding.createEncoder() |
| 318 | encoding.writeVarUint(encoder, messageSync) |
| 319 | encoding.writeAny(encoder, {}) |
| 320 | syncProtocol.writeSyncStep1(encoder, doc) |
| 321 | this.ws.send(encoding.toUint8Array(encoder)) |
nothing calls this directly
no test coverage detected