GitHub Documentation Patreon donate button

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: }));
        // Redirect the user to the room
        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
      // Send the user home

    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!


© 2020 Endel Dreyer