<?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[a user login 2 device]]></title><description><![CDATA[<p>hello,<br />
i want to close old connection when 1 user login on 2 device<br />
My mean is:<br />
onAuth (options){<br />
	return true;<br />
}</p>
<p>requestJoin (options: any, isNew: boolean) {	<br />
	return true;<br />
}</p>
<p>onJoin (client) {<br />
	if(userId in this.players){<br />
		var old_client = this.players[userId];<br />
		old_client.close();<br />
	}<br />
	this.players[userId] = client;<br />
}<br />
How to do this?</p>
]]></description><link>http://discuss.colyseus.io/topic/187/a-user-login-2-device</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 03:07:28 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/187.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Dec 2018 08:29:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to a user login 2 device on Invalid Date]]></title><description><![CDATA[<p>hello,<br />
i want to close old connection when 1 user login on 2 device<br />
My mean is:<br />
onAuth (options){<br />
	return true;<br />
}</p>
<p>requestJoin (options: any, isNew: boolean) {	<br />
	return true;<br />
}</p>
<p>onJoin (client) {<br />
	if(userId in this.players){<br />
		var old_client = this.players[userId];<br />
		old_client.close();<br />
	}<br />
	this.players[userId] = client;<br />
}<br />
How to do this?</p>
]]></description><link>http://discuss.colyseus.io/post/609</link><guid isPermaLink="true">http://discuss.colyseus.io/post/609</guid><dc:creator><![CDATA[jack1604]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to a user login 2 device on Invalid Date]]></title><description><![CDATA[<p>Hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/269">@jack1604</a>, you're on the right track.</p>
<p>You must have a way to identify users uniquely, not based on <code>client.id</code> or <code>client.sessionId</code> for that. Ideally you'd use authentication (<code>onAuth</code>) with an external service, which will ensure you'll have a unique id per user.</p>
<p>The <code>client.id</code> will be the same if you open multiple tabs in the same browser. You can use that for testing. Not suitable for a real scenario, though.</p>
<p>Having this unique id, you can create a map of player by ids (e.g. <code>this.players</code>), and close his previous connection, exactly as in your example:</p>
<pre><code>var old_client = this.players[userId];
old_client.close();
</code></pre>
<p>Cheers</p>
]]></description><link>http://discuss.colyseus.io/post/611</link><guid isPermaLink="true">http://discuss.colyseus.io/post/611</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>