forked from noxious/server
25 lines
645 B
TypeScript
25 lines
645 B
TypeScript
import { Server } from 'socket.io'
|
|
import { TSocket } from '#application/types'
|
|
import { gameLogger } from '#application/logger'
|
|
import WeatherManager from '#managers/weatherManager'
|
|
|
|
export default class Weather {
|
|
constructor(
|
|
private readonly io: Server,
|
|
private readonly socket: TSocket
|
|
) {}
|
|
|
|
public listen(): void {
|
|
this.socket.on('weather', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(): Promise<void> {
|
|
try {
|
|
const weather = await WeatherManager.getWeatherState()
|
|
this.socket.emit('weather', weather)
|
|
} catch (error: any) {
|
|
gameLogger.error('error', error.message)
|
|
}
|
|
}
|
|
}
|