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", () => {