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. premdasvm
premdasvm

premdasvm

@premdasvm

Chat Follow Unfollow
0
Reputation
1
Posts
682
Profile views
0
Followers
0
Following
Joined 28 Jan 2021, 17:24 Last Online 10 Feb 2021, 06:58

  • 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 • 28 Jan 2021, 17:34

© 2023 Endel Dreyer