MultiHandler in Javascript Extension?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

cevans
Posts: 15
Joined: 02 Jul 2007, 11:00

MultiHandler in Javascript Extension?

Postby cevans » 10 May 2021, 07:27

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?|
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: MultiHandler in Javascript Extension?

Postby Lapo » 10 May 2021, 13:43

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
Lapo
--
gotoAndPlay()
...addicted to flash games
cevans
Posts: 15
Joined: 02 Jul 2007, 11:00

Re: MultiHandler in Javascript Extension?

Postby cevans » 11 May 2021, 03:01

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.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: MultiHandler in Javascript Extension?

Postby Lapo » 11 May 2021, 07:44

I see what you mean.
That approach is only available in Java.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 57 guests