Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room is undefined in inspect view #23

Open
DiZeroX opened this issue Oct 3, 2023 · 0 comments
Open

Room is undefined in inspect view #23

DiZeroX opened this issue Oct 3, 2023 · 0 comments

Comments

@DiZeroX
Copy link

DiZeroX commented Oct 3, 2023

In list view, it shows 2 clients in the room.

image

Upon inspection, room is undefined and there are 0 clients.

image

State showing 0 items:

image

Console output showing 2 clients joined:

image

Client correctly gets room state:

image

React code:

import * as Colyseus from "colyseus.js";

function App() {
  var client = new Colyseus.Client("ws://localhost:2567");
  let room: Colyseus.Room;

  const joinRoom = async () => {
    room = await client.joinOrCreate("cg_chess");
    console.log(room.state);
  };

  return (
    <>
      <div>
        <button onClick={joinRoom}>
          Join Room
        </button>
     </div>
    </>
  );
}

Server code:

export class CGChess extends Room<CGChessState> {
  chess: Chess;
  constructor() {
    super();
    this.chess = new Chess();
  }

  maxClients = 2;

  onCreate (options: any) {
    this.setState(new CGChessState());
  }

  onJoin (client: Client, options: any) {
    this.state.players.set(client.sessionId, new Player());
    if (this.state.players.size === 2) {
      this.lock();
    }
  }
}

This might be related to #22 . I am using version 0.15.

"@colyseus/monitor": "^0.15.0",
"@colyseus/playground": "^0.15.3",
"@colyseus/tools": "^0.15.0",
"colyseus": "^0.15.0",

Other notes:

  • On Playground, creating/joining room, setting up state, and onMessage() works properly.
  • Same behavior occurs when only joining with 1 user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant