Set up local player send hook
This commit is contained in:
parent
005290d057
commit
dd279573e6
2 changed files with 7 additions and 4 deletions
|
@ -1,9 +1,8 @@
|
||||||
import NetworkPeer from "./peer";
|
|
||||||
import { DataConnection } from "peerjs";
|
|
||||||
import { PeerMetadata, NetworkMessage } from "./types";
|
import { PeerMetadata, NetworkMessage } from "./types";
|
||||||
|
|
||||||
export default class LocalClient {
|
export default class LocalClient {
|
||||||
public metadata: PeerMetadata;
|
public metadata: PeerMetadata;
|
||||||
|
public receiver!: (data: NetworkMessage) => void;
|
||||||
|
|
||||||
public constructor(metadata: PeerMetadata) {
|
public constructor(metadata: PeerMetadata) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
|
@ -13,7 +12,7 @@ export default class LocalClient {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public send(data: NetworkMessage) {
|
public send<T extends NetworkMessage>(data: T) {
|
||||||
//TODO
|
this.receiver(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,15 @@ export default class PeerServer extends NetworkPeer {
|
||||||
public constructor(roomInfo: RoomInfo, local: LocalClient) {
|
public constructor(roomInfo: RoomInfo, local: LocalClient) {
|
||||||
super();
|
super();
|
||||||
let players: Record<string, Player> = {};
|
let players: Record<string, Player> = {};
|
||||||
|
|
||||||
|
// Add local player to server
|
||||||
players[local.metadata.name] = {
|
players[local.metadata.name] = {
|
||||||
kind: "local",
|
kind: "local",
|
||||||
name: local.metadata.name,
|
name: local.metadata.name,
|
||||||
client: local
|
client: local
|
||||||
};
|
};
|
||||||
|
local.receiver = this._received.bind(this, players[local.metadata.name]);
|
||||||
|
|
||||||
this.room = {
|
this.room = {
|
||||||
info: roomInfo,
|
info: roomInfo,
|
||||||
players
|
players
|
||||||
|
|
Loading…
Reference in a new issue