From 771e8b16f5404a2b4b5f4be8beb7fc6d1f55cc73 Mon Sep 17 00:00:00 2001 From: Jens Date: Wed, 25 Feb 2026 23:02:51 +0100 Subject: [PATCH] host --- src/multiplayer.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/multiplayer.ts b/src/multiplayer.ts index 4f10041..081d0b6 100644 --- a/src/multiplayer.ts +++ b/src/multiplayer.ts @@ -36,6 +36,33 @@ const gameState: GameState = { players: [], } +class Host { + private peer: Peer + private connections: DataConnection[] + + private gameState: GameState + + constructor() { + this.connections = [] + this.gameState = { + players: [], + } + } + + start() { + this.peer = new Peer({ + config: configuration, + }) + + this.peer.on("connection", this.onConnection) + } + + onConnection(conn: DataConnection) { + this.connections.push(conn) + conn.on("open", () => {}) + } +} + export async function initWebRTC( render: (gameState: GameState) => void, peerId?: string, @@ -50,7 +77,6 @@ export async function initWebRTC( peers[conn.peer] = { lastHeartBeat: new Date().toISOString(), - conn, } conn.on("open", () => {