host
This commit is contained in:
@@ -36,6 +36,33 @@ const gameState: GameState = {
|
|||||||
players: [],
|
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(
|
export async function initWebRTC(
|
||||||
render: (gameState: GameState) => void,
|
render: (gameState: GameState) => void,
|
||||||
peerId?: string,
|
peerId?: string,
|
||||||
@@ -50,7 +77,6 @@ export async function initWebRTC(
|
|||||||
|
|
||||||
peers[conn.peer] = {
|
peers[conn.peer] = {
|
||||||
lastHeartBeat: new Date().toISOString(),
|
lastHeartBeat: new Date().toISOString(),
|
||||||
conn,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.on("open", () => {
|
conn.on("open", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user