Skip to content

feat(network): p2p mode - #452

Open
Tchips46 wants to merge 5 commits into
mainfrom
feat/network/p2p
Open

Tchips46 wants to merge 5 commits into
mainfrom
feat/network/p2p

Conversation

@Tchips46

Copy link
Copy Markdown
Member

Peer-to-peer mode: the server app runs in the host’s browser
With network: "p2p" in the nanoforge.config.ts, the first player hosts the game in their tab and the others join over WebRTC. Game code is unchanged. Th server only does signaling, on LISTENING_TCP_PORT. ctx.network.roomCode and ctx.network.inviteLink give the invite

Closes #284

With NETWORK_MODE=p2p (set by nf from network: "p2p"), the client hosts
the server app in its tab or joins a room over WebRTC, and the Bun server
only does signaling. Removes the /peer entry point and pong-p2p example.
@github-actions github-actions Bot added documentation Improvements or additions to documentation modules:ecs Related to ECS library modules:network Related to Network library labels Oct 24, 2026
@Tchips46 Tchips46 changed the title Feat/network/p2p feat(network): p2p mode Oct 24, 2026
@github-actions github-actions Bot added the packages:core Related to Core library label Oct 24, 2026
Comment on lines +166 to +167
// eslint-disable-next-line @typescript-eslint/no-this-alias
const client = this;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed ?

Comment on lines +168 to +181
public attach(
token: null,
connection: ConnectionInfo,
register?: (session: { id: ClientId; token: string }) => void,
): { id: ClientId; token: string };
public attach(
token: string | null,
connection: ConnectionInfo,
register?: (session: { id: ClientId; token: string }) => void,
): { id: ClientId; token: string } | null;
public attach(
token: string | null,
connection: ConnectionInfo,
register?: (session: { id: ClientId; token: string }) => void,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there the same function multiple times ?

public expose(): NetworkServerContextApi {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const server = this;
return {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in the network client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation modules:ecs Related to ECS library modules:network Related to Network library packages:core Related to Core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow no server multiplayer game with server hosted by a client : lib network browse

2 participants