Negotiated data channels keyed by channel label.
Native WebRTC peer connection to the remote peer.
Remote peer identifier.
Metadata advertised by the remote peer.
Room name the peer is associated with.
Peer connection state, updated on connection state changes.
Remote media streams keyed by stream label.
Closes and frees all connection resources.
Emits an event with optional payload to the registered event handlers.
Event type to emit.
Optional arguments to pass to the event handlers.
Unregisters an event handler for a specific event type emitted by the remote peer connection.
Event type to stop listening for.
Callback function to remove from the event listeners.
Registers an event handler for a specific event type emitted by the remote peer connection.
Opens a data channel to the current remote peer.
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.
Sends a message through a data channel.
If options is a string, it is treated as the channel label. If no label
is provided, it uses the default channel.
The send method works only with open channels that have no protocol specified,
are ordered (reliable), and match the specified label.
Message payload to send.
Optionaloptions: string | SendOptionsSend options or channel label.
A ReadableStream of transfer progress status or a Promise.
// send a message to default channel
await remote.send("Hello, peer!");
// send large data with a progress handler
const file = new File([new Uint8Array(1024 * 1024)], "example.dat");
const transfer = remote.send(file, {
label: "chat", // channel label
info: { filename: file.name }, // metadata
signal: AbortSignal.timeout(10000), // abort signal
});
// optionally handle the progress
for await (const progress of transfer) {
const { id, label, current, total } = progress;
const percent = Math.round((current / total) * 100);
console.log(`[${id}:${label}] Sending... ${percent}%`);
}
Shares a new media stream to the current remote peer or updates an existing one.
If you pass a MediaStream instance directly, it will be shared 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 shared with the managed option, its tracks will be
automatically stopped when the stream is unshared or replaced with
a new stream.
Stream descriptor or MediaStream instance.
The shared MediaStream instance if successful, or undefined.
Serializes the remote peer to a JSON-compatible object.
A serializable representation of the peer.
Stops sharing a previously shared media stream to the current remote peer.
If you pass a MediaStream instance directly, it will be unshared using its id as the label. Otherwise, you can specify the label in the options object or pass it directly as a string.
If the stream was shared with the managed option, its tracks will be
stopped automatically.
A stream label, MediaStream instance, or an object containing a label.
The unshared MediaStream instance, or undefined.
Represents a remote peer connection. Do not create RemotePeer instances manually.