Hi, @endel
Thanks a lot for your explanation quickly.
It is helpful to clear confusion in my mind.
sunq0001
@sunq0001
Posts made by sunq0001
-
RE: Client create room only, but both `onCreate` and `onJoin` are triggered in Server
-
Client create room only, but both `onCreate` and `onJoin` are triggered in Server
I try to use H5 client to test the demo. Firstly, client create the room, then click the button to join the room.
client.js
const client = new Colyseus.Client(ws_origin_url); client.create('chat').then(room =>{ console.log('room has been created'); }); playButton.addEventListener('click', ()=>{ client.join("chat", { mode: "chit-chat" }).then(room => { console.log("joined successfully", JSON.stringify(room)); }).catch(e => { console.error("join error", e); }); })
chatRoom.js
import { Room } from "colyseus"; export class ChatRoom extends Room { private maxClient = 4; constructor() { super(); } onCreate(options) { console.log("chat room created", JSON.stringify(options)); } onJoin(client, options){ console.log(`client: ${JSON.stringify(client)} has joined this room ${JSON.stringify(options)}` ); } }
when i request the web page, the console shows.
chat room created {"mode":"chit-chat"} client: {"sessionId":"BdiirrQTY","readyState":1} has joined this room {}
This means that both
onCreate
andonJoin
are triggered inchatRoom.js
. but client hasn'tjoin
yet , as i haven't click theplayButton
.once i clicked the
playButton
, the client join the room. in server console, it showsclient: {"sessionId":"u01i6ij3l","readyState":1} has joined this room {"mode":"chit-chat"}
pls notice that the sessionID has changed. Although it is the same client in the same web route.
In Sum, two questions:
-
client only creates the room, but server
onCreate
andonJoin
both are triggered. Is it reasonable? i assume that when the client creates room, onlyonCreate
is triggered; when the client joins the room, thenonJoin
triggered. -
The same client, same route, but sessionID is different before and after
join
the room. why is sessionID changed? can we make it no change because it is the same client?
Very appreciate if anyone can answer.
-
-
RE: how to create rooms with my own Room.id?
@sunq0001 I saw the reply in github, thanks a lot. we can close it.
-
how to create rooms with my own Room.id?
I found that all room id is generated automatically, such as
"id":"pc_SOfe8u"
, and so as session id such as"sessionId":"xYrMyDFdH"
, and also websocket url:connection":{"url":"ws://localhost:2567/1O39f7sxi/pc_SOfe8u?sessionId=xYrMyDFdH"
.it seems that i can't control or manage this information on my own. If I want to issue my own customized room.id, session.id or url, how to do?