Skip to content

Commit

Permalink
update typings
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Oct 22, 2024
1 parent 6eacc22 commit a3c579a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/index.d.ts → src/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="node" />

declare module 'postcss-lighten-darken' {
import type { AcceptedPlugin, PluginCreator } from 'postcss'

Expand Down
2 changes: 0 additions & 2 deletions src/online-players/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export default fp(
async app => {
// verify the player is online
async function verifyPlayer(steamId: SteamId64) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const playerSockets = [...app.websocketServer.clients].filter(
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
socket => socket.player?.steamId === steamId,
)
logger.debug(`verify online status for ${steamId} (${playerSockets.length} sockets)`)
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions src/ws/gateway.ts → src/websocket/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export class Gateway extends EventEmitter implements Broadcaster {
}

broadcast(messageFn: MessageFn) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
;(this.app.websocketServer.clients as Set<WebSocket>).forEach(async client => {
this.app.websocketServer.clients.forEach(async client => {
const send = async (msg: string) =>
new Promise<void>((resolve, reject) => {
if (client.readyState !== WebSocket.OPEN) {
Expand Down Expand Up @@ -117,8 +116,7 @@ export class Gateway extends EventEmitter implements Broadcaster {
toPlayers(...players: SteamId64[]): Broadcaster {
return {
broadcast: (messageFn: MessageFn) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
;(this.app.websocketServer.clients as Set<WebSocket>).forEach(async client => {
this.app.websocketServer.clients.forEach(async client => {
if (client.player && players.includes(client.player.steamId)) {
const send = async (msg: string) =>
new Promise<void>((resolve, reject) => {
Expand Down
10 changes: 3 additions & 7 deletions src/ws/index.ts → src/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { logger } from '../logger'
import { Gateway } from './gateway'
import { extractClientIp } from './extract-client-ip'
import websocket from '@fastify/websocket'
import { WebSocket } from 'ws'
import { secondsToMilliseconds } from 'date-fns'
import type { SteamId64 } from '../shared/types/steam-id-64'

Expand All @@ -14,7 +13,7 @@ declare module 'fastify' {
}

declare module 'ws' {
interface WebSocket {
export default interface WebSocket {
isAlive: boolean
player?: {
steamId: SteamId64
Expand All @@ -31,8 +30,7 @@ export default fp(
})

const isAliveInterval = setInterval(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
;(app.websocketServer.clients as Set<WebSocket>).forEach(client => {
app.websocketServer.clients.forEach(client => {
if (!client.isAlive) {
client.terminate()
return
Expand All @@ -43,14 +41,12 @@ export default fp(
})
}, secondsToMilliseconds(30))

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
app.websocketServer.on('connection', (client: WebSocket) => {
app.websocketServer.on('connection', client => {
client.isAlive = true
client.on('error', logger.error)
client.on('pong', () => (client.isAlive = true))
})

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
app.websocketServer.on('close', () => {
clearInterval(isAliveInterval)
})
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"tsc-alias": {
"resolveFullPaths": true,
"verbose": false
}
},
"files": ["src/ambient.d.ts"]
}

0 comments on commit a3c579a

Please sign in to comment.