Current connection lifecycle state. 'idle' when not connected.
Which concrete transport is active, or null when not connected.
Connect to (or create) a room using the specified configuration.
Room credentials and transport mode.
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.
Subscribe to incoming transport events.
Invoked for every event received from the room.
An unsubscribe function. Call it in a useEffect cleanup or
component teardown to avoid memory leaks.
Subscribe to connection status changes.
Called whenever status or transportType changes.
An unsubscribe function.
Send an event to all peers in the room.
Any TransportEvent variant.
Facade over PeerJSTransport and GunTransport that handles mode selection, automatic fallback, and event fan-out.
Remarks
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.Example