Navigation

    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Users
    1. Home
    2. sunq0001
    • Continue chat with sunq0001
    • Start new chat with sunq0001
    • Flag Profile
    • block_user
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    sunq0001

    @sunq0001

    0
    Reputation
    4
    Posts
    49
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    sunq0001 Follow

    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
      sunq0001
    • 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
      sunq0001
    • 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
      sunq0001
    • 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
      sunq0001