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. sunq0001
  3. Posts
  • Profile
  • More
    • Continue chat with sunq0001
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

Posts made by sunq0001

RE: Client create room only, but both `onCreate` and `onJoin` are triggered in Server

Hi, @endel
Thanks a lot for your explanation quickly.
It is helpful to clear confusion in my mind.

posted in Questions & Help • 1 Dec 2020, 05:31
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 and onJoin are triggered in chatRoom.js. but client hasn't join yet , as i haven't click the playButton.

once i clicked the playButton, the client join the room. in server console, it shows

client: {"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 and onJoin both are triggered. Is it reasonable? i assume that when the client creates room, only onCreate is triggered; when the client joins the room, then onJoin 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.

posted in Questions & Help • 1 Dec 2020, 03:42
RE: how to create rooms with my own Room.id?

@sunq0001 I saw the reply in github, thanks a lot. we can close it.

posted in Questions & Help • 27 Nov 2020, 03:10
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?

posted in Questions & Help • 27 Nov 2020, 03:06

© 2023 Endel Dreyer