MCPcopy Create free account
hub / github.com/codicocodes/speedtyper.dev / SocketLatest

Class SocketLatest

packages/webapp-next/common/services/Socket.ts:3–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import { connect, Socket as SocketIOSocket } from "socketio-latest";
2
3export default class SocketLatest {
4 socket: SocketIOSocket;
5
6 constructor(serverUrl: string) {
7 this.socket = connect(serverUrl, {
8 withCredentials: true,
9 reconnection: false,
10 });
11 this.socket.on("disconnect", (err) => {
12 console.log("disconnected from server", err);
13 });
14 this.socket.on("connect", () => {
15 console.log("connected!!!!");
16 });
17 }
18
19 disconnect() {
20 if (this.socket) this.socket.disconnect();
21 }
22
23 subscribe(event: string, cb: (error: string | null, msg: any) => void) {
24 if (!this.socket) return true;
25 this.socket.on(event, (msg: any) => {
26 return cb(null, msg);
27 });
28 }
29
30 emit(event: string, data?: any) {
31 if (this.socket) this.socket.emit(event, data);
32 }
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected