Page 1 of 1

MultiHandler in Javascript Extension?

Posted: 10 May 2021, 07:27
by cevans
Back in SFS 1x , all client requests/commands came through the "handleRequest" handler and from there I parsed the command string and routed the request to appropriate module in other parts of the server code.

With SFS2X I'm using Javascript extensions I was hoping to utilize a similar flow where all client messages goto a single handler and from there I can route them to other parts of the code. I know Java extensions accomplish this through creating a MultiHandler class. But what would be the best way to accomplish this functionality with SFS2X Javascript extensions?|

Re: MultiHandler in Javascript Extension?

Posted: 10 May 2021, 13:43
by Lapo
Hi,
the introductory example in this page:
http://docs2x.smartfoxserver.com/Extens ... uick-start
should clarify your question.

In SFS2X you define one handler for each different request and bind it to a different method/function. This is a better approach than sending all requests to a single function with a long list of IF statements.

Hope it helps

Re: MultiHandler in Javascript Extension?

Posted: 11 May 2021, 03:01
by cevans
Well I was hoping to do something like this where you have a command like, "register.profile" and I can parse the command and send all "register" prefixed requests to a particular module in the backend.

So I wouldn't have a ton of IF/ELSE statements, it would just be a few conditionals to route a group of requests to the relevant module. SFS 1x had this ability and SFS 2X has this ability with Java extensions via the Multihandler class. I was just wondering if Javascript extensions could also take advantage of this workflow.

I was hoping to avoid having to add a listener for every single request command for the entire application all in the init(). I wanted to keep things in their separate module.

Re: MultiHandler in Javascript Extension?

Posted: 11 May 2021, 07:44
by Lapo
I see what you mean.
That approach is only available in Java.

Cheers