Page 1 of 1

How to add custom validation before user join room

Posted: 01 Nov 2021, 18:44
by hng
How to add custom validation before user join room.

I want to check if user already join the specific room before but got disconnected and from client the user login again and want to join room again the server need to reject the user if less than 1 hour.

in Room Extension :

Code: Select all

 addEventHandler(SFSEventType.USER_JOIN_ROOM, event -> {
    if(SomeCheckFunc()){
       SFSErrorData errorData = new SFSErrorData(SFSErrorCode.JOIN_ROOM_LOCKED);
                errorData.addParameter("Error bla bla bla");
                throw new SFSJoinRoomException("error", errorData);
    }
 }



and in client :

Code: Select all


        sfs.addEventListener(SFSEvent.ROOM_JOIN, evt -> {
            showGameRoom();
        });
       
        sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, evt -> {
            System.out.println("Room joining failed: " + evt.getArguments().get("errorMessage"));
        });


ROOM_JOIN_ERROR is NEVER called. Is there anyway add validation on server side and force trigger ROOM_JOIN_ERROR in client ?

I know I can create custom handle in server and in client listen to extension response before continue room join or not but this have 2 issue, first not secure since final validation logic in client and second it is not practice need two step in client and server.

please any suggestion/clue

Re: How to add custom validation before user join room

Posted: 05 Nov 2021, 15:13
by Lapo
Sorry for the late reply.
This was posted in the wrong section of the forum, under SFS1.x while it's actually SFS2X. I have now moved the topic.

The server-side event USER_JOIN_ROOM is triggered after a User has already joined a Room, so what you're trying to accomplish won't work.
To validate a User before he enters a specific Room you would need to send an ExtensionRequest from client side and validate it on the server side before joining the client also from the server side (via --> SFSApi.joinRoom())

If something is unclear let me know.
Cheers

Re: How to add custom validation before user join room

Posted: 09 Nov 2021, 04:28
by hng
Thank you very much for you clarification

Re: How to add custom validation before user join room

Posted: 16 Nov 2021, 04:08
by kirito
Thanks for creating this thread, Pal. Saved my time :) Lapwhatsapp modo, big help..i appreciate your help. Hoping for the same support in the future.