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
'use strict';
import {EventEmitter} from 'events/events';
import {Socket} from './utils/socket';
import {BehaviorSubject} from 'rxjs';
import {ConnectEvt, User as _User } from './model';
import {DataStore as _DataStore, Browser as _Browser, Video as _Video, Monitor as _Monitor} from './model';
const scheme = document.location.protocol === 'https:' ? 'wss' : 'ws';
const port = document.location.port ? ':' + document.location.port : '';
const hostname = document.location.hostname;
const wsURL = `${scheme}://${hostname}${port}/koko/ws/`;
export let TermWS = null;
export const emitter = new(EventEmitter);
export const sep = '/';
export let Video = new _Video();
export let Monitor = new _Monitor();
export let User = new _User();
export const DataStore: _DataStore = {
socket: TermWS,
Nav: [{}],
NavShow: true,
Path: {},
error: {},
msg: {},
logLevel: 4,
showLeftBar: true,
windowSize: [],
autoLogin: false,
guacamoleToken: '',
guacamoleTokenTime: 0
};
export let Browser = new _Browser();
export const i18n = new Map();
export async function getWsSocket() {
if (TermWS) {
return TermWS;
}
TermWS = new Socket(wsURL, 'ssh');
const nsConn = await TermWS.connect();
if (!nsConn) {
console.log('Try to using socket.io protocol');
}
DataStore.socket = TermWS;
return TermWS;
}
export const connectEvt = new BehaviorSubject<ConnectEvt>(new ConnectEvt(null, null));
export function translate(value) {
if (i18n.has(value.toLowerCase())) {
return i18n.get(value.toLowerCase());
} else {
return value;
}
}