feat: implement SocketManager for websocket communication, creating a singleton instance and attaching it to the window object
This commit is contained in:
28
src/services/SocketManager.js
Normal file
28
src/services/SocketManager.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { io } from 'socket.io-client';
|
||||||
|
|
||||||
|
|
||||||
|
class SocketManager {
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
this.socket = io('', {
|
||||||
|
transports: ["websocket"],
|
||||||
|
autoConnect: false
|
||||||
|
});
|
||||||
|
|
||||||
|
this.emit = this.emit.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
emit(event, ...args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create singleton instance
|
||||||
|
const socketManager = new SocketManager();
|
||||||
|
|
||||||
|
// Attach to window object
|
||||||
|
window.socketManager = socketManager;
|
||||||
|
|
||||||
|
export default socketManager;
|
||||||
Reference in New Issue
Block a user