Start adding shim for local player instance on servers

This commit is contained in:
Hamcha 2019-09-04 16:17:21 +02:00
parent 34ab5d4a10
commit c164a70fc1
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
2 changed files with 16 additions and 3 deletions

View file

@ -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<T>(message: T) {
for (const playerName in this.room.players) {
const player = this.room.players[playerName];
this.send<T>(player.conn, message);
if (player.kind == "remote") {
this.send<T>(player.conn, message);
} else {
//TODO Local wrapper
}
}
}
}

View file

@ -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<string, NetworkPlayer>;
players: Record<string, NetworkPlayer | LocalPlayer>;
}
export interface RoomInfo {