should i use one websocket connection for all functions or should i
create new websocket connection for every interactive function of my
app?
You should have only one websocket connection, there is no reason to use multiple websockets.
From my personal experience:
Best design would be to use a REST API to handle actions comming from client and use Websocket only for notifications. using REST would manage the parsing for you.
Anyway, if you want all your app to communicate through websocket protocol, you can send through the socket something like
msg = {
"action": "fly",
"data": "plane"
}
Then handle it in your server side using a switch case statement:
switch(msg.action){
case 'fly':
serverCommand.fly(msg.data);
break;
// other statements
}
Or you can even do (no parsing needed):
serverCommand[msg.action](msg.data);
What I want to say is: you don't need to open multiple websockets to solve performance issues.
By opening multiple websocket for same client your code will be hardly maintainable and you will lost the DRY principle.
Take a look at that answer, which not recommend to open multiple sockets.
And this answer which enumarate all the case where you may want to open multiple websockets for same client (pay attention, that it says that uses case are not commons)