Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. lavren1974
lavren1974

lavren1974

@lavren1974

Chat Follow Unfollow
1
Reputation
9
Posts
1.3k
Profile views
0
Followers
0
Following
Joined 19 Dec 2018, 08:53 Last Online 3 Nov 2019, 16:38

  • Profile
  • More
    • Continue chat with lavren1974
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
lavren1974 Follow

Posts made by lavren1974

RE: client.reconnect

Solved! Everything is working!!! Did the button click processing through the state on the client

posted in General Discussion • 16 Sept 2019, 16:45
RE: Room.onLeave() do not call on connection lost.

May try to track through room.onStateChange, i.e.
create on the server in a state, let's say the variable MyConnect: true when called

room.onStateChange((state) => {
				if (state.MyConnect != true) {
				 // Do something ...
				}
            });

If the connection is terminated, then state.MyConnect will be undefined, which means it will not equal true

posted in Questions & Help • 14 Sept 2019, 13:00
client.reconnect

// Initialization in the constructor

constructor(props) {
    super(props);
	
	...
	
    this.colyseus = new Colyseus.Client('wss://ws.matchscore.ru')

    this.GameBotRoom = this.colyseus.joinOrCreate("gamebot", {
        user_name: this.state.user_name,
        player_a: props.player_a,
        player_b: props.player_b,
        user_rank: this.state.user_rank,
        match_id: this.state.match_id,
        game_id: this.state.game_id,
        my_time: this.state.my_time,
    })
    this.GameBotRoom.then(room => {
        room.onStateChange.once((state) => {
            // console.log("room.onStateChange.once! state", state);
            this.setState(state);
        });
    })
	
	...
	
	}

// Next, listen to events from the client and to the client leaving the room

gameBotRoomRun = () => {
    this.GameBotRoom.then(room => {

        room.onStateChange((state) => {
            if (this.state.my_time_active === 0 && this.state.game_players[this.state.player_active] === this.state.user_name) {
                console.log("tttt off")
                room.send({ command: "time_off" });
            }

            this.setState(state);

        });

        room.onMessage((data) => {
            if (data.command === "redirect") {
                window.location.replace(data.link);
            } else if (data.command === "room_id") {
                //console.log("room_id - ", data.room_id);
                //console.log("session_id - ", data.session_id);
                this.setState({ room_id: data.room_id, session_id: data.session_id });

            }

        });

        room.onLeave((code) => {
            console.log("client left the room", code);

            this.test01();
        });

    })

}		

// Catch the silk on the element and send it to the server

handleClick = (i) => {

    if (this.state.gameStatus) {

        if (this.state.squares_valid[i] === this.state.player_active && this.state.game_players[this.state.player_active] === this.state.user_name) {

            this.GameBotRoom.then(room => {
                room.send({ command: "test", sector: i, xIsNext: this.state.xIsNext });
            });

        }
    }
}

// Everything works great! But I decided to add a response to reconnecting the client (loss of connection)

// Server

     async onLeave (client, consented: boolean) {
       // flag client as inactive for other users
       this.state.players[client.sessionId].connected = false;
     
       try {
         if (consented) {
             throw new Error("consented leave");
         }
     
         // allow disconnected client to reconnect into this room until 20 seconds
         await this.allowReconnection(client, 30);
     
         // client returned! let's re-activate it.
         this.state.players[client.sessionId].connected = true;
     
       } catch (e) {
     
         // 20 seconds expired. let's remove the client.
         delete this.state.players[client.sessionId];
       }
     }

// Client

serverReconnect = () => {

    //localhost
    //let client = new Colyseus.Client('ws://localhost:8014')
    //server

    let client =  new Colyseus.Client('wss://ws.matchscore.ru')


    client.reconnect(this.state.room_id, this.state.session_id).then(room => {
        // console.log("joined successfully", room);
        //this.setState({ pingServerTime: 60 });
        console.log("serverReconnect!!!")
        clearInterval(this.TimerId);

        //room.onClick += this.GameBotRoom.onClick 
        //this.GameBotRoom += room.onClick.onClick
        //room.onMessage += this.GameBotRoom.onMessage
        //room.onLeave += this.GameBotRoom.onLeave
        //room.onMessageCallback


        room.onStateChange((state) => {
            console.log("onStateChange - serverReconnect");
            this.setState(state);

        });

        //room.send({ command: "message", message: "message!!!" });
    });

}

// Reconnecting is working fine, client is being updated! But the previous one

 this.GameBotRoom = this.colyseus.joinOrCreate("gamebot", {.... 

through which all the logic of the game passes, does not send messages to the server, it loses connection and the process goes to serverReconnect
If you add a click response on serverReconnect, then it reconnects (which is expected ... with an error)

A room.onLeave from the initial

this.GameBotRoom.then(room => {

stops working when reconnecting, and in

client.reconnect(this.state.room_id, this.state.session_id).then(room => {

does not work...

Help with advice on how to redirect processing to its original state (I’ve been suffering for two days ...)

posted in General Discussion • 14 Sept 2019, 12:00
RE: When working through https, access to the server is blocked by the browser, does it work through http?

@michaelbest1

caddy server
https://caddyserver.com

posted in General Discussion • 10 Sept 2019, 15:35
RE: When working through https, access to the server is blocked by the browser, does it work through http?

@lavren1974

Solved!!!

caddyserver

ws.matchscore.ru {
  proxy / 127.0.0.1:8014 {
    transparent
    websocket
  }
}

client (ws to wss)

this.colyseus = new Colyseus.Client('wss://ws.matchscore.ru')

server (ws to wss)

gameServer.listen(port);
console.log(`Listening on wss://localhost:${port}`)
posted in General Discussion • 10 Sept 2019, 13:40
When working through https, access to the server is blocked by the browser, does it work through http?

When working through https, access to the server is blocked by the browser, does it work through http?

posted in General Discussion • 10 Sept 2019, 11:41
Вариант таймера комнаты (версия colyseus 0.10.7)

Re: Lobby System

a = 0;
update() {
    this.a++;
    console.log("update!", this.a);
}

onInit(options) {

    this.clock.setInterval(() => {this.update();}, 1000);

...

}
posted in Questions & Help • 16 Jun 2019, 06:50

© 2023 Endel Dreyer