Class AwarenessWasm<T>

Awareness is a structure that tracks the ephemeral state of peers.

It can be used to synchronize cursor positions, selections, and the names of the peers.

The state of a specific peer is expected to be removed after a specified timeout. Use remove_outdated to eliminate outdated states.

Type Parameters

Constructors

  • Creates a new Awareness instance.

    The timeout parameter specifies the duration in milliseconds. A state of a peer is considered outdated, if the last update of the state of the peer is older than the timeout.

    Type Parameters

    Parameters

    • peer: number | bigint | `${number}`
    • timeout: number

    Returns AwarenessWasm<T>

Methods

  • Applies the encoded state of peers.

    Each peer's deletion countdown will be reset upon update, requiring them to pass through the timeout interval again before being eligible for deletion.

    Parameters

    • encoded_peers_info: Uint8Array

    Returns { added: `${number}`[]; updated: `${number}`[] }

  • Encodes the state of the given peers.

    Parameters

    • peers: any[]

    Returns Uint8Array

  • Encodes the state of all peers.

    Returns Uint8Array

  • Returns void

  • Returns Record<`${number}`, T>

  • Parameters

    • peer: `${number}`

    Returns T

  • Parameters

    • peer: `${number}`

    Returns number

  • Get the timestamp of the state of a given peer.

    Parameters

    • peer: number | bigint | `${number}`

    Returns number

  • If the state is empty.

    Returns boolean

  • Get the number of peers.

    Returns number

  • Get the PeerID of the local peer.

    Returns `${number}`

  • Get all the peers

    Returns `${number}`[]

  • Returns `${number}`[]

  • Remove the states of outdated peers.

    Returns `${number}`[]

  • Parameters

    • value: T

    Returns void