Constructors

Properties

WebSocketPolyfill: WebSocketPolyfillType
ackedVersion: number = -1
authEndpoint: AuthEndpoint
awareness: Awareness

Awareness protocol instance.

clientToken: null | ClientToken = null

Current client token.

connectionTimeoutHandle: null | Timeout = null
doc: Doc
docId: string
heartbeatHandle: null | Timeout = null
indexedDBProvider: null | IndexedDBProvider = null
isConnecting: boolean = false

Whether we are currently in the process of connecting.

listeners: Map<YWebsocketEvent | YSweetEvent, Set<EventListener>> = ...
localVersion: number = 0
receivedAtLeastOneSyncResponse: boolean = false

Older versions of the Y-Sweet server did not support the sync message, and would ignore it. This may lead to the client thinking the server is offline, when really it just doesn't know how to return a heartbeat.

Eventually, we will build protocol version negotiation into the handshake. Until then, we use a simple approach: until we receive the first sync message back, we assume the server is an older version for the purpose of the heartbeat logic.

reconnectSleeper: null | Sleeper = null
retries: number = 0
status: YSweetStatus = STATUS_OFFLINE

Connection status.

websocket: null | WebSocket = null

Accessors

  • get hasLocalChanges(): boolean
  • Whether the document has local changes.

    Returns boolean

  • get shouldConnect(): boolean
  • Whether the provider should attempt to connect.

    Returns boolean

    Deprecated

    use provider.status !== 'offline' instead, or call provider.connect() / provider.disconnect() to set.

  • get synced(): boolean
  • Whether the document is synced. (For compatibility with y-websocket.)

    Returns boolean

    Deprecated

    use provider.status === 'connected' instead.

  • get wsconnected(): boolean
  • Whether the underlying websocket is connected.

    Returns boolean

    Deprecated

    use provider.status === 'connected' || provider.status === 'handshaking' instead.

  • get wsconnecting(): boolean
  • Whether the underlying websocket is connecting.

    Returns boolean

    Deprecated

    use provider.status === 'connecting' instead.

Methods

  • Parameters

    • type: YWebsocketEvent | YSweetEvent
    • listener: ((d) => void)
        • (d): void
        • Parameters

          • d: any

          Returns void

    • Optional once: boolean

    Returns void

  • Attempts to connect to the websocket. Returns a promise that resolves to true if the connection was successful, or false if the connection failed.

    Parameters

    • clientToken: ClientToken

    Returns Promise<boolean>

  • Parameters

    • websocket: WebSocket

    Returns void

  • Parameters

    • eventName: YWebsocketEvent | YSweetEvent
    • data: any = null

    Returns void

  • Returns Promise<ClientToken>

  • Parameters

    • clientToken: ClientToken

    Returns string

  • Parameters

    • __namedParameters: {
          added: any[];
          removed: any[];
          updated: any[];
      }
      • added: any[]
      • removed: any[]
      • updated: any[]
    • _origin: any

    Returns void

  • Parameters

    • type: YWebsocketEvent | YSweetEvent
    • listener: ((d) => void)
        • (d): void
        • Parameters

          • d: any

          Returns void

    Returns void

  • Parameters

    • type: YWebsocketEvent | YSweetEvent
    • listener: ((d) => void)
        • (d): void
        • Parameters

          • d: any

          Returns void

    Returns void

  • Parameters

    • type: YWebsocketEvent | YSweetEvent
    • listener: ((d) => void)
        • (d): void
        • Parameters

          • d: any

          Returns void

    Returns void

  • Parameters

    • event: MessageEvent<any>

    Returns void

  • Parameters

    • decoder: Decoder

    Returns void

  • Parameters

    • version: number

    Returns void

  • Parameters

    • decoder: Decoder

    Returns void

  • Parameters

    • event: CloseEvent

    Returns void