From dd279573e68f01f99b77039af76a00f9bf3762a9 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Wed, 4 Sep 2019 18:01:56 +0200 Subject: [PATCH] Set up local player send hook --- src/network/local.ts | 7 +++---- src/network/server.ts | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/network/local.ts b/src/network/local.ts index 4ee071a..980a054 100644 --- a/src/network/local.ts +++ b/src/network/local.ts @@ -1,9 +1,8 @@ -import NetworkPeer from "./peer"; -import { DataConnection } from "peerjs"; import { PeerMetadata, NetworkMessage } from "./types"; export default class LocalClient { public metadata: PeerMetadata; + public receiver!: (data: NetworkMessage) => void; public constructor(metadata: PeerMetadata) { this.metadata = metadata; @@ -13,7 +12,7 @@ export default class LocalClient { //TODO } - public send(data: NetworkMessage) { - //TODO + public send(data: T) { + this.receiver(data); } } diff --git a/src/network/server.ts b/src/network/server.ts index 25e60f4..d3aec55 100644 --- a/src/network/server.ts +++ b/src/network/server.ts @@ -36,11 +36,15 @@ export default class PeerServer extends NetworkPeer { public constructor(roomInfo: RoomInfo, local: LocalClient) { super(); let players: Record = {}; + + // Add local player to server players[local.metadata.name] = { kind: "local", name: local.metadata.name, client: local }; + local.receiver = this._received.bind(this, players[local.metadata.name]); + this.room = { info: roomInfo, players