From af9b443865ab0286e2ae8fa50567ecdbfcc3ced1 Mon Sep 17 00:00:00 2001 From: "Chen, Tai-Lin" Date: Mon, 26 Feb 2024 16:09:40 +0800 Subject: [PATCH] update socket.ts --- app/src/utils/{socket.js => socket.ts} | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) rename app/src/utils/{socket.js => socket.ts} (75%) diff --git a/app/src/utils/socket.js b/app/src/utils/socket.ts similarity index 75% rename from app/src/utils/socket.js rename to app/src/utils/socket.ts index 56b12da..46a25fe 100644 --- a/app/src/utils/socket.js +++ b/app/src/utils/socket.ts @@ -1,13 +1,15 @@ import io from 'socket.io-client' class SocketWrapper { + socket: any + listeners: any constructor() { this.socket = null this.listeners = [] } - connect(session) { - return new Promise((resolve, reject) => { + connect(session: any) { + return new Promise((resolve, reject) => { this.disconnect() this.socket = io('', { @@ -28,7 +30,7 @@ class SocketWrapper { }) } - on(event, callback) { + on(event: any, callback: any) { this.listeners.push({ event, callback }) if (this.socket) { this.socket.on(event, callback) @@ -36,12 +38,14 @@ class SocketWrapper { } bindListeners() { - this.listeners.forEach(({ event, callback }) => { - this.socket.on(event, callback) - }) + this.listeners.forEach( + ({ event, callback }: { event: any; callback: any }) => { + this.socket.on(event, callback) + } + ) } - emit(event, data) { + emit(event: any, data: any) { if (!this.socket) { console.warn('Socket is not connected!') return