<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to access the current room in Redux?]]></title><description><![CDATA[<p>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,</p>
<pre><code class="language-javascript">export const createRoomAsync = (options = {}) =&gt; (dispatch) =&gt; {
  return colyseus.create(&quot;room_name&quot;, options).then((room) =&gt; {
    // Update the local store
    dispatch(joinRoom({ id: room.id }));
    // Redirect the user to the room
    dispatch(push(`/room/${room.id}`));

    return room;
  });
};
</code></pre>
<p>and then another one to leave the room</p>
<pre><code class="language-javascript">export const leaveRoomAsync = () =&gt; async (dispatch) =&gt; {
  // Leave the room - how to access the room instance?
  // room.leave();

  // Update the store
  dispatch(leaveRoom());
  // Send the user home
  dispatch(push(&quot;/&quot;));
};
</code></pre>
<p>With Redux you cannot store non-serialisable objects in the store, so I can't store <code>room</code> in the store with all its methods when created. So how do I access the room instance outside of the function that created it?<br />
Ideally, I'd like to call a method like <code>colyseus.getCurrentRoom()</code> , but nothing like seems to exist in the API.<br />
Any help would be appreciated!</p>
]]></description><link>http://discuss.colyseus.io/topic/407/how-to-access-the-current-room-in-redux</link><generator>RSS for Node</generator><lastBuildDate>Tue, 12 May 2026 21:37:57 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/407.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 11 Oct 2020 05:20:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to access the current room in Redux? on Invalid Date]]></title><description><![CDATA[<p>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,</p>
<pre><code class="language-javascript">export const createRoomAsync = (options = {}) =&gt; (dispatch) =&gt; {
  return colyseus.create(&quot;room_name&quot;, options).then((room) =&gt; {
    // Update the local store
    dispatch(joinRoom({ id: room.id }));
    // Redirect the user to the room
    dispatch(push(`/room/${room.id}`));

    return room;
  });
};
</code></pre>
<p>and then another one to leave the room</p>
<pre><code class="language-javascript">export const leaveRoomAsync = () =&gt; async (dispatch) =&gt; {
  // Leave the room - how to access the room instance?
  // room.leave();

  // Update the store
  dispatch(leaveRoom());
  // Send the user home
  dispatch(push(&quot;/&quot;));
};
</code></pre>
<p>With Redux you cannot store non-serialisable objects in the store, so I can't store <code>room</code> in the store with all its methods when created. So how do I access the room instance outside of the function that created it?<br />
Ideally, I'd like to call a method like <code>colyseus.getCurrentRoom()</code> , but nothing like seems to exist in the API.<br />
Any help would be appreciated!</p>
]]></description><link>http://discuss.colyseus.io/post/1339</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1339</guid><dc:creator><![CDATA[5tormTrooper]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to How to access the current room in Redux? on Thu, 28 Jan 2021 17:36:20 GMT]]></title><description><![CDATA[<p>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 <code>room</code> in a variable there like <code>this.room</code> which can be accessed from any other component on my whole application.</p>
<pre><code>class ActivityRoom {
    constructor() {
        this.client = new Colyseus.Client(clientUrl);
    }

    connect = async (username, rating, photoUrl) =&gt; {
        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();
}
}
</code></pre>
<p>then call the <code>leaveRoom</code> like <code>ActivityRoom.leaveRoom</code> from any other Component i want.</p>
]]></description><link>http://discuss.colyseus.io/post/1421</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1421</guid><dc:creator><![CDATA[premdasvm]]></dc:creator><pubDate>Thu, 28 Jan 2021 17:36:20 GMT</pubDate></item></channel></rss>