import dotenv from "dotenv";
import { Game } from "@gathertown/gather-game-client";
import webSocket from "isomorphic-ws";
dotenv.config();
global.WebSocket = webSocket;
const API_KEY = process.env.GATHER_API_KEY;
const GATHER_SPACE = process.env.GATHER_SPACE;
const onConnected = (connected) => {
console.log("Connected: ", connected);
game.enter(GATHER_SPACE);
console.log(Object.keys(game.players))
console.log(game.getStats())
}
const game = new Game(() => Promise.resolve({ apiKey: API_KEY }));
game.connect(GATHER_SPACE);
game.subscribeToConnection(onConnected);
game.subscribeToEvent("playerJoined", (player) => {
console.log("playerJoined", player);
console.log(Object.keys(game.players))
});
With the above code game.players
is always empty, and the event playerJoined
is never emitted I tried on two separate spaces I get the same results.