From c164a70fc1d32964fda3e88cb85d68c45043b268 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Wed, 4 Sep 2019 16:17:21 +0200 Subject: [PATCH] Start adding shim for local player instance on servers --- src/network/server.ts | 11 +++++++++-- src/network/types.ts | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/network/server.ts b/src/network/server.ts index 5a2d707..92aa7b0 100644 --- a/src/network/server.ts +++ b/src/network/server.ts @@ -18,7 +18,9 @@ export default class PeerServer extends NetworkPeer { super(); this.room = { info: roomInfo, - players: {} + players: { + //TODO Add local player + } }; this.peer.on("connection", this._connection); } @@ -69,6 +71,7 @@ export default class PeerServer extends NetworkPeer { private addPlayer(conn: DataConnection) { const playerName = conn.metadata.name; this.room.players[playerName] = { + kind: "remote", name: conn.metadata.name, conn: conn }; @@ -97,7 +100,11 @@ export default class PeerServer extends NetworkPeer { private broadcast(message: T) { for (const playerName in this.room.players) { const player = this.room.players[playerName]; - this.send(player.conn, message); + if (player.kind == "remote") { + this.send(player.conn, message); + } else { + //TODO Local wrapper + } } } } diff --git a/src/network/types.ts b/src/network/types.ts index f055f87..24edf57 100644 --- a/src/network/types.ts +++ b/src/network/types.ts @@ -1,6 +1,12 @@ import { DataConnection } from "peerjs"; +export interface LocalPlayer { + kind: "local"; + name: string; +} + export interface NetworkPlayer { + kind: "remote"; name: string; conn: DataConnection; } @@ -11,7 +17,7 @@ export interface PeerMetadata { export interface Room { info: RoomInfo; - players: Record; + players: Record; } export interface RoomInfo {