-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.ts
62 lines (55 loc) · 1.25 KB
/
client.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { DEFAULT_EXTENSIONS } from '@babel/core';
import net from 'net';
export class Client {
/**
* This key is used to uniquely identify the client inside the server.
*
* @type {string}
*/
key: string;
/**
* The socket instance corresponding to the connection.
*
* @type {net.Socket}
*/
socket: net.Socket;
private options: ClientOptions;
constructor(
key: string,
socket: net.Socket,
options: ClientOptions = DEFAULT_OPTIONS
) {
this.key = key;
this.socket = socket;
this.options = options;
}
updateOptions(data: Partial<ClientOptions>) {
this.options = { ...this.options, ...data };
}
sendPong() {
this.socket.write('PONG\r\n');
}
sendOk() {
if (this.options.verbose) {
this.socket.write('+OK\r\n');
}
}
}
export interface ClientOptions {
verbose: boolean;
pedantic: boolean;
tls_required: boolean;
auth_token?: string;
user?: string;
pass?: string;
name?: string;
lang: string;
version: string;
protocol?: number;
echo?: boolean;
sig?: string;
jwt?: string;
no_responders?: boolean;
headers?: boolean;
nkey?: string;
}