kevinshen56714 / SkyOffice

Immersive virtual office built with Phaser, React, Redux, PeerJS, and Colyseus.

Home Page:https://sky-office.co/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When logging in, later players may not be able to see who is around them.

shoshoi opened this issue · comments

Hello, thanks for this useful software !

When logging in, later players may not be able to see who is around them. Still, the call can be made.
Sometimes this happens, sometimes it does not.
I am trying this on the same host, with the same browser, and multiple tabs open.

The earlier report was in error.
When logging in, players who arrive later may not be able to see who is around and cannot make calls.
Seems to happen when the server is under low load.

Yeah my problem is like that too.

But I tried sevral times and the characters, hided, appeared suddenly.

I mean I have no idea what the problem is.

plz let me know if you have any idea the software working right way...

@gusdnvkfks @shoshoi
Yes. I have the same problem. Well.., The reason may be the registration timing of phaserEvents. Especially, phaserEvents.emit(Event.PLAYER_JOINED) is often called before phaserEvents.on(Event.PLAYER_JOINED) under a given server conditions.
From now i have no idea for solution. As reference, phaser and colyseus tutorial page is in https://learn.colyseus.io/phaser/
In this tutorial, phaser#create block method calls joinOrCreate and defines onAdd callback. It may solve our problem.

import { Client, Room } from "colyseus.js";

// custom scene class
export class GameScene extends Phaser.Scene {
    // (...)

    client = new Client("ws://localhost:2567");
    room: Room;

    async create() {
      console.log("Joining room...");

      try {
        this.room = await client.joinOrCreate("my_room");
        console.log("Joined successfully!");

      } catch (e) {
        console.error(e);
      }
    }

    // (...)
}
export class GameScene extends Phaser.Scene {
    // (...)
    room: Room;

    // we will assign each player visual representation here
    // by their `sessionId`
    playerEntities: {[sessionId: string]: any} = {};

    // (...)
    async create() {
        // (...)

        // listen for new players
        this.room.state.players.onAdd((player, sessionId) => {
            const entity = this.physics.add.image(player.x, player.y, 'ship_0001');

            // keep a reference of it on `playerEntities`
            this.playerEntities[sessionId] = entity;
        });

        // (...)
    }
}

Yeah my problem is like that too with still latest version of Colyseus (0.15)

@kevinshen56714 , do you have any ideas for fixing this one? Thank and so appreciate!