Code Monkey home page Code Monkey logo

Comments (10)

arief0303 avatar arief0303 commented on May 22, 2024 2

Can someone please elaborate the syntax in more detail? I'm facing difficulty in this exact scenario. As every time I leave a room , i'm getting "WebSocket is already in CLOSING or CLOSED state." error. Thank you.

from colyseus.

seiyria avatar seiyria commented on May 22, 2024 1

This is something I do as well (I have an RPG where each map is a room). Basically, I do it exactly as endel described - I tell the client to teleport, and the client initiates the request. I do some cleanup on the server, save the player, then when it leaves the room and joins the next one, the x, y, etc are already set. When the next version comes out, you'll be able to do promise validation in canJoin which will make it so you can check the database to verify that the map you're on is the map you should be on (for example).

from colyseus.

endel avatar endel commented on May 22, 2024 1

Hi @xfause, there are a couple of different ways of achieving this.

What I do on mazmorra is:

  • the server sends a message to the client, with the new level info (e.g. "go to level 7")
  • the client receives that message, and disconnects from the previous room, and connects to the next one, given the provided info from the server

A more "secure" way of handling this, would be to use the matchMaker API in the server-side, and send the "seat reservation" data through a message for the client, and the client can the call .consumeSeatReservation().

You still need to connect and disconnect from the rooms manually, as the framework does not consider how your front-end is structured.

from colyseus.

endel avatar endel commented on May 22, 2024

Hi @oyed,

Currently, the only way to achieve this is by manually sending a message from the server to the client you want to move, and, from the client-side, request to join into that room. See dummy example below:

Server-side:

// "previous_room" handler
this.send(client, { letsMoveTo: "next_room" });

Client-side

var previousRoom = client.join("previous_room");

previousRoom.onData.add(function(data) {
    var nextRoom = client.join(data.letsMoveTo);
});

from colyseus.

oyed avatar oyed commented on May 22, 2024

@endel Thanks - can I persist Client (Player) Data through rooms?

from colyseus.

endel avatar endel commented on May 22, 2024

@oyed you're welcome! You'd need to persist the user data somewhere in between connections, such as a database or in memory.

I wouldn't recommend persisting in NodeJS's process, since when upgrading to the next version of the server (0.6.x) will break things. In the current version (0.5.x) it will be fine because it's a single process. Version 0.6.x will introduce multiple processes, and your rooms may live in a different process.

from colyseus.

oyed avatar oyed commented on May 22, 2024

Thanks for the help!

from colyseus.

xfause avatar xfause commented on May 22, 2024

after 3 years. is there any update?
new method like jumpToRoom()?
or this solution still useable?

from colyseus.

atuncer avatar atuncer commented on May 22, 2024

why can't we force join a client

from colyseus.

endel avatar endel commented on May 22, 2024

@atuncer the problem I see currently in allowing the SERVER to force the client to join is that we don't have a declarative way for the CLIENT to properly listen to this event and set up its callbacks.

I'm very open to an API/feature proposal to allow this. It would be nice to have this feature for version 1.0 with a good API.

from colyseus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.