Add xterm itegration
* Move to TypeScript from legacy JavaScript * Add support of xterm.js * Hterm is still available for backward compatibility
This commit is contained in:
30
js/src/main.ts
Normal file
30
js/src/main.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { TermHterm } from "./hterm";
|
||||
import { TermXterm } from "./xterm";
|
||||
import { Terminal, WebTTY, protocols } from "./webtty";
|
||||
import { ConnectionFactory } from "./websocket";
|
||||
|
||||
// @TODO remove these
|
||||
declare var gotty_auth_token: string;
|
||||
declare var gotty_term: string;
|
||||
|
||||
const elem = document.getElementById("terminal")
|
||||
|
||||
if (elem !== null) {
|
||||
var term: Terminal;
|
||||
if (gotty_term == "hterm") {
|
||||
term = new TermHterm(elem);
|
||||
} else {
|
||||
term = new TermXterm(elem);
|
||||
}
|
||||
const httpsEnabled = window.location.protocol == "https:";
|
||||
const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';
|
||||
const args = window.location.search;
|
||||
const factory = new ConnectionFactory(url, protocols);
|
||||
const wt = new WebTTY(term, factory, args, gotty_auth_token);
|
||||
const closer = wt.open();
|
||||
|
||||
window.addEventListener("unload", () => {
|
||||
closer();
|
||||
term.close();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user