controller and vsorc data viewers done
[VSoRC/.git] / node_modules / xterm-addon-attach / out / AttachAddon.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 class AttachAddon {
4     constructor(socket, options) {
5         this._disposables = [];
6         this._socket = socket;
7         this._socket.binaryType = 'arraybuffer';
8         this._bidirectional = (options && options.bidirectional === false) ? false : true;
9     }
10     activate(terminal) {
11         this._disposables.push(addSocketListener(this._socket, 'message', ev => {
12             const data = ev.data;
13             terminal.write(typeof data === 'string' ? data : new Uint8Array(data));
14         }));
15         if (this._bidirectional) {
16             this._disposables.push(terminal.onData(data => this._sendData(data)));
17         }
18         this._disposables.push(addSocketListener(this._socket, 'close', () => this.dispose()));
19         this._disposables.push(addSocketListener(this._socket, 'error', () => this.dispose()));
20     }
21     dispose() {
22         this._disposables.forEach(d => d.dispose());
23     }
24     _sendData(data) {
25         if (this._socket.readyState !== 1) {
26             return;
27         }
28         this._socket.send(data);
29     }
30 }
31 exports.AttachAddon = AttachAddon;
32 function addSocketListener(socket, type, handler) {
33     socket.addEventListener(type, handler);
34     return {
35         dispose: () => {
36             if (!handler) {
37                 return;
38             }
39             socket.removeEventListener(type, handler);
40         }
41     };
42 }
43 //# sourceMappingURL=AttachAddon.js.map