Viktorani API - v0.0.8
    Preparing search index...

    Class TransportManager

    Facade over PeerJSTransport and GunTransport that handles mode selection, automatic fallback, and event fan-out.

    Instantiated as a module-level singleton (transportManager). Components and hooks interact with the transport exclusively through this class -- never by constructing transport instances directly.

    Mode selection (config.mode):

    • 'peer' -- use PeerJS only.
    • 'gun' -- use Gun.js only.
    • 'auto' -- try PeerJS; if it fails within the timeout, fall back to Gun.js.

    PeerJS and GunTransport are dynamically imported inside connect() so neither appears in the initial bundle.

    await transportManager.connect({ mode: 'auto', role: 'host', roomId, passphrase })
    const unsub = transportManager.onEvent(event => console.log(event))
    transportManager.send({ type: 'BUZZER_LOCK' })
    unsub()
    await transportManager.disconnect()
    Index

    Constructors

    Accessors

    Methods

    • Connect to (or create) a room using the specified configuration.

      Parameters

      Returns Promise<void>

      Any existing connection is cleanly disconnected before the new one starts. All previously registered event handlers are preserved -- they will receive events from the new connection without needing to re-subscribe.

      PeerJS and GunTransport are imported dynamically per branch so they are excluded from the initial bundle and loaded only when a connection is made.

      If the selected transport fails to connect (non-'auto' modes only).

    • Disconnect from the current room and release all transport resources.

      Returns Promise<void>

      Safe to call when not connected -- it is a no-op in that case. Status listeners are notified after disconnection.

    • Subscribe to incoming transport events.

      Parameters

      • handler: (e: TransportEvent) => void

        Invoked for every event received from the room.

      Returns () => void

      An unsubscribe function. Call it in a useEffect cleanup or component teardown to avoid memory leaks.

      useEffect(() => {
      return transportManager.onEvent(event => {
      if (event.type === 'BUZZ') handleBuzz(event)
      })
      }, [])