Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/docs/src/Peer/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ A string invite code created by `puter.peer.serve()`.
`options` is an object with the following properties:

- `iceServers` (`RTCIceServer[]`) Custom ICE servers (STUN/TURN) to use instead of the Puter-managed relays.
- `forceRelay` (`boolean`) Whether to force connections to route through a relay instead of attempting peer-to-peer (default). Metering charges may apply.

## Return value

Expand All @@ -41,6 +42,7 @@ A `Promise` that resolves to a `PuterPeerConnection` instance.
- `send(data)` - Send a message to the peer. Supports strings, `Blob`, `ArrayBuffer`, or `ArrayBufferView`.
- `close(reason)` - Close the connection.
- `owner` (`object`) - Information about the user who created the server.
- `peerconnection` (`RTCPeerConnection`) - the raw underlying RTC handle for this connection.
- `open` event: Fired when the data channel is ready.
- `message` event: Fired when a message is received (`event.data`).
- `close` event: Fired when the connection closes (`event.reason`).
Expand Down
1 change: 1 addition & 0 deletions src/docs/src/Peer/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const server = await puter.peer.serve(options);
`options` is an object with the following properties:

- `iceServers` (`RTCIceServer[]`) Custom ICE servers (STUN/TURN) to use instead of the Puter-managed relays.
- `forceRelay` (`boolean`) Whether to force connections to route through a relay instead of attempting peer-to-peer (default). Metering charges will increase.

## Return value

Expand Down
2 changes: 2 additions & 0 deletions src/puter-js/src/modules/Peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class PuterPeerConnection extends EventTarget {
super();
this.#peerConfig = peerConfig;
this.peerconnection = new RTCPeerConnection({
iceTransportPolicy: peerConfig.forceRelay ? "relay" : "all",
iceServers: peerConfig.iceServers,
});
this.#datachannel = this.peerconnection.createDataChannel('channel-1', { negotiated: true, id: 2 });
Expand Down Expand Up @@ -446,6 +447,7 @@ class Peer {
authToken: this.authToken,
iceServers,
signallerUrl: this.#signallerUrl,
forceRelay: options?.forceRelay
};
}
async serve (options) {
Expand Down
1 change: 1 addition & 0 deletions src/puter-js/types/modules/peer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export interface PuterPeerOptions {
/** Custom ICE servers (STUN/TURN) to use instead of the Puter-managed relays. */
iceServers?: RTCIceServer[];
forceRelay?: boolean;
}

/** Metadata about a peer user. */
Expand Down
Loading