1 import { type RawData
, WebSocketServer
} from
'ws'
3 import { requestHandlerPool
} from
'./pool.js'
4 import { type DataPayload
, type MessagePayload
, MessageType
} from
'./types.js'
7 const wss
= new WebSocketServer({ port
}, () => {
9 `⚡️[ws server]: WebSocket server is started at ws://localhost:${port}/`
13 const emptyFunction
= (): void => {
17 wss
.on('connection', ws
=> {
18 ws
.on('error', console
.error
)
19 ws
.on('message', (message
: RawData
) => {
20 const { type, data
} = JSON
.parse(
21 // eslint-disable-next-line @typescript-eslint/no-base-to-string
23 ) as MessagePayload
<DataPayload
>
25 case MessageType
.echo
:
27 .execute({ data
}, 'echo')
31 type: MessageType
.echo
,
39 case MessageType
.factorial
:
41 .execute({ data
}, 'factorial')
45 type: MessageType
.factorial
,