From 7f33100132e10b93cbee04c3022f83576a114c80 Mon Sep 17 00:00:00 2001 From: "Chen, Tai-Lin" Date: Mon, 25 Mar 2024 15:48:37 +0800 Subject: [PATCH] update --- app/src/utils/socket.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/utils/socket.ts b/app/src/utils/socket.ts index 46a25fe..987f619 100644 --- a/app/src/utils/socket.ts +++ b/app/src/utils/socket.ts @@ -1,8 +1,8 @@ -import io from 'socket.io-client' +import { io, Socket } from 'socket.io-client' class SocketWrapper { - socket: any - listeners: any + socket: Socket | null + listeners: { event: any; callback: any }[] constructor() { this.socket = null this.listeners = [] @@ -40,7 +40,7 @@ class SocketWrapper { bindListeners() { this.listeners.forEach( ({ event, callback }: { event: any; callback: any }) => { - this.socket.on(event, callback) + if (this.socket !== null) this.socket.on(event, callback) } ) }