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. 5tormTrooper
5tormTrooper

5tormTrooper

@5tormTrooper

Chat Follow Unfollow
0
Reputation
1
Posts
763
Profile views
0
Followers
0
Following
Joined 11 Oct 2020, 05:17 Last Online 26 Oct 2020, 19:18

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

Posts made by 5tormTrooper

How to access the current room in Redux?

Hey all, has anyone managed to implement Colyseus with Redux a React client? I'm having an issue where I don't know how to access the room instance from outside the function that created/joined it. For example, I have a thunk to create a room,

export const createRoomAsync = (options = {}) => (dispatch) => {
  return colyseus.create("room_name", options).then((room) => {
    // Update the local store
    dispatch(joinRoom({ id: room.id }));
    // Redirect the user to the room
    dispatch(push(`/room/${room.id}`));

    return room;
  });
};

and then another one to leave the room

export const leaveRoomAsync = () => async (dispatch) => {
  // Leave the room - how to access the room instance?
  // room.leave();

  // Update the store
  dispatch(leaveRoom());
  // Send the user home
  dispatch(push("/"));
};

With Redux you cannot store non-serialisable objects in the store, so I can't store room in the store with all its methods when created. So how do I access the room instance outside of the function that created it?
Ideally, I'd like to call a method like colyseus.getCurrentRoom() , but nothing like seems to exist in the API.
Any help would be appreciated!

posted in Questions & Help • 11 Oct 2020, 05:20

© 2023 Endel Dreyer