import { WebSocketClient } from "websocket/mod.ts"
import type { WebSocketServer } from "websocket/mod.ts"
import type { WorkerPool } from "./worker_pool.ts"
export const handleSocket = (wss: WebSocketServer, workerPool: WorkerPool) => {
wss.on("connection", function (ws: WebSocketClient) {
const returnMessage = (message: string) => {
ws.send(message)
}
ws.on("message", function (message: string) {
const command = JSON.parse(message)
const { type } = command
if (type === "request") {
workerPool.handleMessage(command, returnMessage)
}
})
})
}
import { WebSocketClient } from "websocket/mod.ts"
import type { WebSocketServer } from "websocket/mod.ts"
import type { WorkerPool } from "./worker_pool.ts"
export const handleSocket = (wss: WebSocketServer, workerPool: WorkerPool) => {
wss.on("connection", function (ws: WebSocketClient) {
const returnMessage = (message: string) => {
ws.send(message)
}
ws.on("message", function (message: string) {
const command = JSON.parse(message)
const { type } = command
if (type === "request") {
workerPool.handleMessage(command, returnMessage)
}
})
})
}