Navigation

    Colyseus
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. premdasvm
    premdasvm

    premdasvm

    @premdasvm

    Chat Follow Unfollow
    0
    Reputation
    1
    Posts
    743
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

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

    Posts made by premdasvm

    RE: How to access the current room in Redux?

    what i did was create a new Helper class file (Javascript Class), then added all the Colyseus functionalities and listeners and everything there. so I can store the room in a variable there like this.room which can be accessed from any other component on my whole application.

    class ActivityRoom {
        constructor() {
            this.client = new Colyseus.Client(clientUrl);
        }
    
        connect = async (username, rating, photoUrl) => {
            this.name = username;
            this.rating = rating;
            this.photoUrl = photoUrl;
            try {
                const room = await this.client.joinById('AR1', {
                    username,
                    rating,
                    photoUrl
                });
                this.room = room;
                this.sessionId = room.sessionId;
                this.Room_Listeners();
            } catch (error) {}
            console.error(error);
        }
    };
    
    leaveRoom() {
        this.room.leave();
    }
    }
    

    then call the leaveRoom like ActivityRoom.leaveRoom from any other Component i want.

    posted in Questions & Help •