-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManager.ts
More file actions
34 lines (28 loc) · 898 Bytes
/
Manager.ts
File metadata and controls
34 lines (28 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Manager as M, Socket } from 'socket.io-client'
import { SocketOptions } from 'socket.io-client/build/esm/socket'
export class Manager extends M {
private readonly sockets: { [key: string]: Socket } = {}
private readonly latestSocketNsp = null
create_socket(nsp: string, opts?: Partial<SocketOptions> | undefined): Socket {
//TODO: 최근사용한 소켓 커넥션 종료
if (this.sockets.hasOwnProperty(nsp)) {
return this.sockets[nsp]
}
// if (this.latestSocketNsp) {
// }
const socket = this.socket(nsp, opts)
socket.publicId = nsp
socket.listen = function bindEventListnerOnSocket(ev, lisnter) {
if (this.hasListeners(ev)) {
socket.off(ev)
}
socket.on(ev, lisnter)
return socket
}
this.sockets[nsp] = socket
return socket
}
isExistNsp(url: string) {
return !!this.sockets[url]
}
}