-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix puter.js docs and types drift 10 aug #3531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
reynaldichernando
merged 1 commit into
HeyPuter:main
from
reynaldichernando:docs-types-10-aug
Aug 10, 2026
+286
−41
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| title: PuterPeerConnection | ||
| description: The PuterPeerConnection object representing a WebRTC data-channel connection to a peer. | ||
| --- | ||
|
|
||
| The `PuterPeerConnection` object representing a WebRTC data-channel connection to a peer. [`puter.peer.connect()`](/Peer/connect/) resolves to one, and a [`PuterPeerServer`](/Objects/puterpeerserver/) hands one to its `connection` event for every client that joins. | ||
|
|
||
| `PuterPeerConnection` extends [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget), so events are subscribed to with `addEventListener()`. | ||
|
|
||
| ## Attributes | ||
|
|
||
| #### `owner` (Object) | ||
|
|
||
| Information about the user who created the server, with `username` and `uuid`. | ||
|
|
||
| #### `connected` (Boolean) | ||
|
|
||
| Whether the data channel is currently open. | ||
|
|
||
| #### `closed` (Boolean) | ||
|
|
||
| Whether the connection has been closed. | ||
|
|
||
| #### `peerconnection` (RTCPeerConnection) | ||
|
|
||
| The raw underlying [`RTCPeerConnection`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection) handle, for cases the Puter API does not cover. | ||
|
|
||
| ## Methods | ||
|
|
||
| #### `send(data)` | ||
|
|
||
| Sends a message to the peer. `data` may be a `String`, `Blob`, `ArrayBuffer`, or `ArrayBufferView`. | ||
|
|
||
| #### `close(reason)` | ||
|
|
||
| Closes the connection. The optional `reason` string is delivered to the peer on its `close` event. | ||
|
|
||
| ## Events | ||
|
|
||
| #### `open` | ||
|
|
||
| Fired when the data channel is ready. Wait for this before calling `send()`. | ||
|
|
||
| #### `message` | ||
|
|
||
| Fired when a message is received. `event.data` holds the payload. | ||
|
|
||
| #### `close` | ||
|
|
||
| Fired when the connection closes. `event.reason` holds the reason, if one was given. | ||
|
|
||
| #### `error` | ||
|
|
||
| Fired when a connection error occurs. `event.error` holds the error. | ||
|
|
||
| ## Example | ||
|
|
||
| ```js | ||
| const conn = await puter.peer.connect(inviteCode); | ||
|
|
||
| conn.addEventListener('open', () => { | ||
| conn.send('Hello from the client!'); | ||
| }); | ||
| conn.addEventListener('message', (msg) => { | ||
| puter.print('Server says:', msg.data); | ||
| }); | ||
| conn.addEventListener('close', (event) => { | ||
| puter.print('Connection closed:', event.reason); | ||
| }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| title: PuterPeerServer | ||
| description: The PuterPeerServer object returned by puter.peer.serve(), representing a peer server and its connected clients. | ||
| --- | ||
|
|
||
| The `PuterPeerServer` object returned by [`puter.peer.serve()`](/Peer/serve/). It holds the invite code other clients use to reach you, and tracks every client that connects. | ||
|
|
||
| `PuterPeerServer` extends [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget), so events are subscribed to with `addEventListener()`. | ||
|
|
||
| ## Attributes | ||
|
|
||
| #### `inviteCode` (String) | ||
|
|
||
| The code to share with other clients so they can connect with [`puter.peer.connect()`](/Peer/connect/). | ||
|
|
||
| #### `connections` (Map) | ||
|
|
||
| A `Map` of every connected client, keyed by connection id. The values are [`PuterPeerConnection`](/Objects/puterpeerconnection/) objects. | ||
|
|
||
| ## Methods | ||
|
|
||
| #### `close()` | ||
|
|
||
| Closes every client connection and the signalling connection. The invite code stops working. | ||
|
|
||
| ## Events | ||
|
|
||
| #### `connection` | ||
|
|
||
| Fired when a client connects. The event has the following attributes: | ||
|
|
||
| - `conn` ([`PuterPeerConnection`](/Objects/puterpeerconnection/)) - The connection to the client. | ||
| - `user` (Object) - Metadata about the connecting user, with `username` and `uuid` (if available). | ||
|
|
||
| ## Example | ||
|
|
||
| ```js | ||
| const server = await puter.peer.serve(); | ||
| puter.print(`Invite code: ${server.inviteCode}`); | ||
|
|
||
| server.addEventListener('connection', (event) => { | ||
| const conn = event.conn; | ||
| conn.addEventListener('open', () => { | ||
| conn.send('Hello from the server!'); | ||
| }); | ||
| conn.addEventListener('message', (msg) => { | ||
| puter.print('Client says:', msg.data); | ||
| }); | ||
| }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.