Skip to content

Room is undefined in inspect viewΒ #23

Open
@DiZeroX

Description

@DiZeroX

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions