]> git.proxmox.com Git - mirror_xterm.js.git/blob - addons/attach/attach.js
e7cac84d7189766c5cf620ce719ec18d654018e1
[mirror_xterm.js.git] / addons / attach / attach.js
1 /*
2 * Implements the attach method, that
3 * attaches the terminal to a WebSocket stream.
4 *
5 * The bidirectional argument indicates, whether the terminal should
6 * send data to the socket as well and is true, by default.
7 */
8
9 (function (attach) {
10 if (typeof define == 'function') {
11 /*
12 * Require.js is available
13 */
14 define(['../../src/xterm'], attach);
15 } else {
16 /*
17 * Plain browser environment
18 */
19 attach(this.Xterm);
20 }
21 })(function (Xterm) {
22 Xterm.prototype.attach = function (socket, bidirectional) {
23 var term = this;
24
25 bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
26 this.socket = socket;
27
28 socket.addEventListener('message', function (ev) {
29 term.write(ev.data);
30 });
31
32 if (bidirectional) {
33 this.on('data', function (data) {
34 socket.send(data);
35 });
36 }
37 };
38 });