Fix TypeScript: add @types/ws and RawData type for WebSocket message
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
11
backend/package-lock.json
generated
11
backend/package-lock.json
generated
@@ -25,6 +25,7 @@
|
||||
"@types/node": "^20.14.0",
|
||||
"@types/nodemailer": "^7.0.11",
|
||||
"@types/pg": "^8.11.6",
|
||||
"@types/ws": "^8.18.1",
|
||||
"tsx": "^4.15.7",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
@@ -657,6 +658,16 @@
|
||||
"pg-types": "^2.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/abstract-logging": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz",
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"@types/node": "^20.14.0",
|
||||
"@types/nodemailer": "^7.0.11",
|
||||
"@types/pg": "^8.11.6",
|
||||
"@types/ws": "^8.18.1",
|
||||
"tsx": "^4.15.7",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FastifyPluginAsync } from 'fastify'
|
||||
import fastifyWebsocket from '@fastify/websocket'
|
||||
import type { WebSocket } from 'ws'
|
||||
import type { WebSocket, RawData } from 'ws'
|
||||
|
||||
// hotel slug → set of connected clients
|
||||
const hotelRooms = new Map<string, Set<WebSocket>>()
|
||||
@@ -18,7 +18,7 @@ const ws: FastifyPluginAsync = async (fastify) => {
|
||||
if (!hotelRooms.has(hotel)) hotelRooms.set(hotel, new Set())
|
||||
hotelRooms.get(hotel)!.add(socket)
|
||||
|
||||
socket.on('message', (raw) => {
|
||||
socket.on('message', (raw: RawData) => {
|
||||
const data = raw.toString()
|
||||
const peers = hotelRooms.get(hotel)
|
||||
if (!peers) return
|
||||
|
||||
Reference in New Issue
Block a user