-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.js
44 lines (32 loc) · 1 KB
/
session.js
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
"use strict";
import { Client } from "./networking.js";
import { TelnetMessageProcessor } from "./protocolprocessor.js";
export const SessionState = {
INIT: 'init',
NEGOTIATION: 'negotiation',
ACTIVE: 'active'
};
// TODO: Terminal, Codepage, etc. in Session config
class SessionSingleton {
constructor() {
this.state = SessionState.INIT;
this.config = new SessionConfiguration();
this.messageProcessor = new TelnetMessageProcessor();
this.client = new Client();
}
start() {
this.client.connect(this.config.port, this.config.host);
this.state = SessionState.NEGOTIATION;
this.client.onReceive(data => {
const result = this.messageProcessor.process(data);
result.forEach(element => this.client.write(element.serialize().buffer));
});
}
}
class SessionConfiguration {
constructor() {
this.port = 23;
this.host = null;
}
}
export const Session = new SessionSingleton();