Creates a new Peer instance.
Optionaloptions: PeerOptionsPeer configuration options.
Indicates whether the peer is currently active (joined a room).
ReadonlyaddonsAttachable extensions.
ReadonlychannelsConfigured local data channels indexed by channel label.
ReadonlyconnectionsActive remote peers indexed by remote peer id.
ReadonlyidUnique identifier for the local peer.
OptionalmetadataOptional metadata announced to other peers in signaling messages.
Current room name. Empty until join() is called.
ReadonlystreamsPublished local streams indexed by application-level stream label.
Attaches an addon/extension to the peer instance.
Addon instance to attach.
Detaches a previously attached addon/extension from the peer instance.
Addon instance to detach.
Emits one or more events. Usually you would not call this method directly.
Event name or list of event names.
Event payload.
Joins a room and starts listening for incoming connections.
Optionaloptions: string | PeerJoinOptionsRoom name or join options.
Removes a previously registered event listener.
Event name or list of event names.
Optionalhandler: (...args: PeerEvents[K]) => voidEvent handler to remove. If omitted, all handlers for the given event(s) will be removed.
Subscribes to one or more peer events.
Event name or list of event names.
Event handler.
Subscribes to an event and auto-unsubscribes after first invocation.
Event name or list of event names.
Event handler.
Opens a data channel with the given label and options to all remote peers. If a channel with the same label already exists, it will be reused.
You can open a channel with the same label on both local and remote peers or only on one side. In any case, only one channel will be created for each label. You can send data through the channel in both directions.
Channel options or channel label.
Publishes new or updates an existing media stream to all remote peers including new ones that join later.
If you pass a MediaStream instance directly, it will be published under a label equal to the stream id. Otherwise, you can specify an explicit label in the options object. If a stream with the same label already exists, it will be updated and its tracks will be added/removed as needed to minimize renegotiations.
If the stream is published with the managed option, its tracks will be
automatically stopped when the stream is unpublished or replaced with
a new stream.
Stream descriptor or MediaStream instance.
The published MediaStream instance if successful, or undefined.
Sends a message through data channels.
If options is omitted, the message is sent to all open channels for every
connected remote peer. If options is a string, it is treated as channel label.
Message payload to send. This may be a string, a Blob, an ArrayBuffer, a TypedArray or a DataView object.
Optionaloptions: string | { label?: string }Optional channel label or object containing label.
Stops publishing a previously published media stream with the given label and removes it from all remote peers.
If you pass a MediaStream instance directly, it will be unpublished based on its id as label. Otherwise, you can specify the label in the options object or pass it directly as a string.
If the stream was published with the managed option, its tracks will be
stopped automatically.
A stream label, MediaStream instance, or an object containing a label.
The unpublished MediaStream instance, or undefined.
Manages WebRTC peer connections, signaling, media streams, and data channels.
Example