From 3d25d845b1535dd4497f6c28bb1cc4c3fdc7d3e6 Mon Sep 17 00:00:00 2001 From: barnettZQG Date: Sun, 10 May 2020 18:21:15 +0800 Subject: [PATCH] remove js --- webcli/js/package.json | 14 --- webcli/js/src/hterm.ts | 92 ----------------- webcli/js/src/main.ts | 47 --------- webcli/js/src/websocket.ts | 60 ----------- webcli/js/src/webtty.ts | 149 --------------------------- webcli/js/src/xterm.ts | 105 ------------------- webcli/js/tsconfig.json | 20 ---- webcli/js/typings/libapps/index.d.ts | 51 --------- webcli/js/webpack.config.js | 29 ------ 9 files changed, 567 deletions(-) delete mode 100644 webcli/js/package.json delete mode 100644 webcli/js/src/hterm.ts delete mode 100644 webcli/js/src/main.ts delete mode 100644 webcli/js/src/websocket.ts delete mode 100644 webcli/js/src/webtty.ts delete mode 100644 webcli/js/src/xterm.ts delete mode 100644 webcli/js/tsconfig.json delete mode 100644 webcli/js/typings/libapps/index.d.ts delete mode 100644 webcli/js/webpack.config.js diff --git a/webcli/js/package.json b/webcli/js/package.json deleted file mode 100644 index 45753be65..000000000 --- a/webcli/js/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "devDependencies": { - "license-loader": "^0.5.0", - "ts-loader": "^2.0.3", - "typescript": "^2.3.2", - "uglifyjs-webpack-plugin": "^1.0.0-beta.2", - "webpack": "^2.5.1", - "webpack-cli": "^3.3.11" - }, - "dependencies": { - "libapps": "github:yudai/libapps#release-hterm-1.70", - "xterm": "^2.7.0" - } -} diff --git a/webcli/js/src/hterm.ts b/webcli/js/src/hterm.ts deleted file mode 100644 index b49a22fac..000000000 --- a/webcli/js/src/hterm.ts +++ /dev/null @@ -1,92 +0,0 @@ -import * as bare from "libapps"; - -export class Hterm { - elem: HTMLElement; - - term: bare.hterm.Terminal; - io: bare.hterm.IO; - - columns: number; - rows: number; - - // to "show" the current message when removeMessage() is called - message: string; - - constructor(elem: HTMLElement) { - this.elem = elem; - bare.hterm.defaultStorage = new bare.lib.Storage.Memory(); - this.term = new bare.hterm.Terminal(); - this.term.getPrefs().set("send-encoding", "raw"); - this.term.decorate(this.elem); - - this.io = this.term.io.push(); - this.term.installKeyboard(); - }; - - info(): { columns: number, rows: number } { - return { columns: this.columns, rows: this.rows }; - }; - - output(data: string) { - if (this.term.io != null) { - this.term.io.writeUTF8(data); - } - }; - - showMessage(message: string, timeout: number) { - this.message = message; - if (timeout > 0) { - this.term.io.showOverlay(message, timeout); - } else { - this.term.io.showOverlay(message, null); - } - }; - - removeMessage(): void { - // there is no hideOverlay(), so show the same message with 0 sec - this.term.io.showOverlay(this.message, 0); - } - - setWindowTitle(title: string) { - this.term.setWindowTitle(title); - }; - - setPreferences(value: object) { - Object.keys(value).forEach((key) => { - this.term.getPrefs().set(key, value[key]); - }); - }; - - onInput(callback: (input: string) => void) { - this.io.onVTKeystroke = (data) => { - callback(data); - }; - this.io.sendString = (data) => { - callback(data); - }; - }; - - onResize(callback: (colmuns: number, rows: number) => void) { - this.io.onTerminalResize = (columns: number, rows: number) => { - this.columns = columns; - this.rows = rows; - callback(columns, rows); - }; - }; - - deactivate(): void { - this.io.onVTKeystroke = function(){}; - this.io.sendString = function(){}; - this.io.onTerminalResize = function(){}; - this.term.uninstallKeyboard(); - } - - reset(): void { - this.removeMessage(); - this.term.installKeyboard(); - } - - close(): void { - this.term.uninstallKeyboard(); - } -} diff --git a/webcli/js/src/main.ts b/webcli/js/src/main.ts deleted file mode 100644 index 21cc8adc8..000000000 --- a/webcli/js/src/main.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Hterm } from "./hterm"; -import { Xterm } 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; -declare var ws_uri: string; -declare var t_id: string; -declare var s_id: string; -declare var c_id: string; -declare var md5: string; - -const elem = document.getElementById("terminal"); - -if (elem !== null) { - var term: Terminal; - if (gotty_term == "hterm") { - term = new Hterm(elem); - } else { - term = new Xterm(elem); - } - //const url = ws_uri - const httpsEnabled = window.location.protocol == "https:"; - const url = ws_uri - ? ws_uri - : (httpsEnabled ? "wss://" : "ws://") + - window.location.host + - window.location.pathname + - "ws"; - //const args = window.location.search; - const args = { - T_id: t_id, - S_id: s_id, - C_id: c_id, - Md5: md5 - }; - 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(); - }); -} diff --git a/webcli/js/src/websocket.ts b/webcli/js/src/websocket.ts deleted file mode 100644 index 7f651776f..000000000 --- a/webcli/js/src/websocket.ts +++ /dev/null @@ -1,60 +0,0 @@ -export class ConnectionFactory { - url: string; - protocols: string[]; - - constructor(url: string, protocols: string[]) { - this.url = url; - this.protocols = protocols; - }; - - create(): Connection { - return new Connection(this.url, this.protocols); - }; -} - -export class Connection { - bare: WebSocket; - - - constructor(url: string, protocols: string[]) { - this.bare = new WebSocket(url, protocols); - } - - open() { - // nothing todo for websocket - }; - - close() { - this.bare.close(); - }; - - send(data: string) { - this.bare.send(data); - }; - - isOpen(): boolean { - if (this.bare.readyState == WebSocket.CONNECTING || - this.bare.readyState == WebSocket.OPEN) { - return true - } - return false - } - - onOpen(callback: () => void) { - this.bare.onopen = (event) => { - callback(); - } - }; - - onReceive(callback: (data: string) => void) { - this.bare.onmessage = (event) => { - callback(event.data); - } - }; - - onClose(callback: () => void) { - this.bare.onclose = (event) => { - callback(); - }; - }; -} diff --git a/webcli/js/src/webtty.ts b/webcli/js/src/webtty.ts deleted file mode 100644 index d9f253277..000000000 --- a/webcli/js/src/webtty.ts +++ /dev/null @@ -1,149 +0,0 @@ -export const protocols = ["webtty"]; - -export const msgInputUnknown = '0'; -export const msgInput = '1'; -export const msgPing = '2'; -export const msgResizeTerminal = '3'; - -export const msgUnknownOutput = '0'; -export const msgOutput = '1'; -export const msgPong = '2'; -export const msgSetWindowTitle = '3'; -export const msgSetPreferences = '4'; -export const msgSetReconnect = '5'; - - -export interface Terminal { - info(): { columns: number, rows: number }; - output(data: string): void; - showMessage(message: string, timeout: number): void; - removeMessage(): void; - setWindowTitle(title: string): void; - setPreferences(value: object): void; - onInput(callback: (input: string) => void): void; - onResize(callback: (colmuns: number, rows: number) => void): void; - reset(): void; - deactivate(): void; - close(): void; -} - -export interface Connection { - open(): void; - close(): void; - send(data: string): void; - isOpen(): boolean; - onOpen(callback: () => void): void; - onReceive(callback: (data: string) => void): void; - onClose(callback: () => void): void; -} - -export interface ConnectionFactory { - create(): Connection; -} - - -export class WebTTY { - term: Terminal; - connectionFactory: ConnectionFactory; - args: {}; - authToken: string; - reconnect: number; - - constructor(term: Terminal, connectionFactory: ConnectionFactory, args: {}, authToken: string) { - this.term = term; - this.connectionFactory = connectionFactory; - this.args = args; - this.authToken = authToken; - this.reconnect = -1; - }; - - open() { - let connection = this.connectionFactory.create(); - let pingTimer: number; - let reconnectTimeout: number; - - const setup = () => { - connection.onOpen(() => { - const termInfo = this.term.info(); - - // connection.send(JSON.stringify( - // { - // Arguments: this.args, - // AuthToken: this.authToken, - // } - // )); - - connection.send(JSON.stringify(this.args)); - - const resizeHandler = (colmuns: number, rows: number) => { - connection.send( - msgResizeTerminal + JSON.stringify( - { - columns: colmuns, - rows: rows - } - ) - ); - }; - - this.term.onResize(resizeHandler); - resizeHandler(termInfo.columns, termInfo.rows); - - this.term.onInput( - (input: string) => { - connection.send(msgInput + input); - } - ); - - pingTimer = window.setInterval(() => { - connection.send(msgPing) - }, 30 * 1000); - - }); - - connection.onReceive((data) => { - const payload = data.slice(1); - switch (data[0]) { - case msgOutput: - this.term.output(atob(payload)); - break; - case msgPong: - break; - case msgSetWindowTitle: - this.term.setWindowTitle(payload); - break; - case msgSetPreferences: - const preferences = JSON.parse(payload); - this.term.setPreferences(preferences); - break; - case msgSetReconnect: - const autoReconnect = JSON.parse(payload); - console.log("Enabling reconnect: " + autoReconnect + " seconds") - this.reconnect = autoReconnect; - break; - } - }); - - connection.onClose(() => { - clearInterval(pingTimer); - this.term.deactivate(); - this.term.showMessage("Connection Closed", 0); - if (this.reconnect > 0) { - reconnectTimeout = window.setTimeout(() => { - connection = this.connectionFactory.create(); - this.term.reset(); - setup(); - }, this.reconnect * 1000); - } - }); - - connection.open(); - } - - setup(); - return () => { - clearTimeout(reconnectTimeout); - connection.close(); - } - }; -}; diff --git a/webcli/js/src/xterm.ts b/webcli/js/src/xterm.ts deleted file mode 100644 index 093750cf0..000000000 --- a/webcli/js/src/xterm.ts +++ /dev/null @@ -1,105 +0,0 @@ -import * as bare from "xterm"; -import { lib } from "libapps" - - -bare.loadAddon("fit"); - -export class Xterm { - elem: HTMLElement; - term: bare; - resizeListener: () => void; - decoder: lib.UTF8Decoder; - - message: HTMLElement; - messageTimeout: number; - messageTimer: number; - - - constructor(elem: HTMLElement) { - this.elem = elem; - this.term = new bare(); - - this.message = elem.ownerDocument.createElement("div"); - this.message.className = "xterm-overlay"; - this.messageTimeout = 2000; - - this.resizeListener = () => { - this.term.fit(); - this.term.scrollToBottom(); - this.showMessage(String(this.term.cols) + "x" + String(this.term.rows), this.messageTimeout); - }; - - this.term.on("open", () => { - this.resizeListener(); - window.addEventListener("resize", () => { this.resizeListener(); }); - }); - - this.term.open(elem, true); - - this.decoder = new lib.UTF8Decoder() - }; - - info(): { columns: number, rows: number } { - return { columns: this.term.cols, rows: this.term.rows }; - }; - - output(data: string) { - this.term.write(this.decoder.decode(data)); - }; - - showMessage(message: string, timeout: number) { - this.message.textContent = message; - this.elem.appendChild(this.message); - - if (this.messageTimer) { - clearTimeout(this.messageTimer); - } - if (timeout > 0) { - this.messageTimer = window.setTimeout(() => { - this.elem.removeChild(this.message); - }, timeout); - } - }; - - removeMessage(): void { - if (this.message.parentNode == this.elem) { - this.elem.removeChild(this.message); - } - } - - setWindowTitle(title: string) { - document.title = title; - }; - - setPreferences(value: object) { - }; - - onInput(callback: (input: string) => void) { - this.term.on("data", (data) => { - callback(data); - }); - - }; - - onResize(callback: (colmuns: number, rows: number) => void) { - this.term.on("resize", (data) => { - callback(data.cols, data.rows); - }); - }; - - deactivate(): void { - this.term.off("data"); - this.term.off("resize"); - this.term.blur(); - } - - reset(): void { - this.removeMessage(); - this.term.clear(); - } - - close(): void { - window.removeEventListener("resize", this.resizeListener); - this.term.destroy(); - } -} diff --git a/webcli/js/tsconfig.json b/webcli/js/tsconfig.json deleted file mode 100644 index e9f56ed39..000000000 --- a/webcli/js/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "strictNullChecks": true, - "noUnusedLocals" : true, - "noImplicitThis": true, - "alwaysStrict": true, - "outDir": "./", - "declaration": true, - "sourceMap": true, - "target": "es5", - "module": "commonJS", - "baseUrl": ".", - "paths": { - "*": ["./typings/*"] - } - }, - "exclude": [ - "node_modules" - ] -} diff --git a/webcli/js/typings/libapps/index.d.ts b/webcli/js/typings/libapps/index.d.ts deleted file mode 100644 index 81eb66d0c..000000000 --- a/webcli/js/typings/libapps/index.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -export declare namespace hterm { - export class Terminal { - io: IO; - onTerminalReady: () => void; - - constructor(); - getPrefs(): Prefs; - decorate(HTMLElement); - installKeyboard(): void; - uninstallKeyboard(): void; - setWindowTitle(title: string): void; - reset(): void; - softReset(): void; - } - - export class IO { - writeUTF8: ((data: string) => void); - writeUTF16: ((data: string) => void); - onVTKeystroke: ((data: string) => void) | null; - sendString: ((data: string) => void) | null; - onTerminalResize: ((columns: number, rows: number) => void) | null; - - push(): IO; - writeUTF(data: string); - showOverlay(message: string, timeout: number | null); - } - - export class Prefs { - set(key: string, value: string): void; - } - - export var defaultStorage: lib.Storage; -} - -export declare namespace lib { - export interface Storage { - } - - export interface Memory { - new (): Storage; - Memory(): Storage - } - - export var Storage: { - Memory: Memory - } - - export class UTF8Decoder { - decode(str: string) - } -} diff --git a/webcli/js/webpack.config.js b/webcli/js/webpack.config.js deleted file mode 100644 index 9aa60bc3a..000000000 --- a/webcli/js/webpack.config.js +++ /dev/null @@ -1,29 +0,0 @@ -const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); - -module.exports = { - entry: "./src/main.ts", - output: { - filename: "./gotty-bundle.js" - }, - devtool: "source-map", - resolve: { - extensions: [".ts", ".tsx", ".js"], - }, - module: { - rules: [ - { - test: /\.tsx?$/, - loader: "ts-loader", - exclude: /node_modules/ - }, - { - test: /\.js$/, - include: /node_modules/, - loader: 'license-loader' - } - ] - }, - plugins: [ - new UglifyJSPlugin() - ] -};