This repository has been archived by the owner on Aug 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddons_attach_attach.js.html
192 lines (155 loc) · 16.3 KB
/
addons_attach_attach.js.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>addons/attach/attach.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module-xterm_src_xterm.html">xterm/src/xterm</a><ul class='methods'><li data-type='method'><a href="module-xterm_src_xterm.html#.bindBlur">bindBlur</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindCopy">bindCopy</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindCut">bindCut</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindDrop">bindDrop</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindFocus">bindFocus</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindKeys">bindKeys</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.bindPaste">bindPaste</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.click">click</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.loadAddon">loadAddon</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#.prepareCopiedTextForClipboard">prepareCopiedTextForClipboard</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#bell">bell</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#bindMouse">bindMouse</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#blankLine">blankLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#blur">blur</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#ch">ch</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#charAttributes">charAttributes</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#charPosAbsolute">charPosAbsolute</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#clearSelection">clearSelection</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorBackward">cursorBackward</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorBackwardTab">cursorBackwardTab</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorCharAbsolute">cursorCharAbsolute</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorDown">cursorDown</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorForward">cursorForward</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorForwardTab">cursorForwardTab</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorNextLine">cursorNextLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorPos">cursorPos</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorPrecedingLine">cursorPrecedingLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#cursorUp">cursorUp</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deleteChars">deleteChars</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deleteColumns">deleteColumns</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deleteLines">deleteLines</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#destroy">destroy</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#deviceStatus">deviceStatus</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#disableModifiers">disableModifiers</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#enableLocatorReporting">enableLocatorReporting</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseAttr">eraseAttr</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseChars">eraseChars</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseInDisplay">eraseInDisplay</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseInLine">eraseInLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseLeft">eraseLeft</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseLine">eraseLine</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseRectangle">eraseRectangle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#eraseRight">eraseRight</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#error">error</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#evaluateKeyEscapeSequence">evaluateKeyEscapeSequence</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#fillRectangle">fillRectangle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#focus">focus</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#handler">handler</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#handleTitle">handleTitle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#HPositionRelative">HPositionRelative</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#HVPosition">HVPosition</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#index">index</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#initGlobal">initGlobal</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#initMouseTracking">initMouseTracking</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertChars">insertChars</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertColumns">insertColumns</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertLines">insertLines</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#insertRow">insertRow</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#is">is</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#keyDown">keyDown</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#keyPress">keyPress</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#leaseContentEditable">leaseContentEditable</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#linePosAbsolute">linePosAbsolute</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#loadLEDs">loadLEDs</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#log">log</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#maxRange">maxRange</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#mediaCopy">mediaCopy</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#nextStop">nextStop</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#open">open</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#prevStop">prevStop</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#refresh">refresh</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#repeatPrecedingCharacter">repeatPrecedingCharacter</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#requestAnsiMode">requestAnsiMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#requestPrivateMode">requestPrivateMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#reset">reset</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#resetMode">resetMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#resetTitleModes">resetTitleModes</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#resize">resize</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#restoreCursor">restoreCursor</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#restorePrivateValues">restorePrivateValues</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#reverseIndex">reverseIndex</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#saveCursor">saveCursor</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scroll">scroll</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scrollDisp">scrollDisp</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scrollDown">scrollDown</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#scrollUp">scrollUp</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#send">send</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#sendDeviceAttributes">sendDeviceAttributes</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setAttrInRectangle">setAttrInRectangle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setCharProtectionAttr">setCharProtectionAttr</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setConformanceLevel">setConformanceLevel</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setCursorStyle">setCursorStyle</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setgCharset">setgCharset</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setgLevel">setgLevel</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setMode">setMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setPointerMode">setPointerMode</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setResources">setResources</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setScrollRegion">setScrollRegion</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#setupStops">setupStops</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#showCursor">showCursor</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#softReset">softReset</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#tabClear">tabClear</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#tabSet">tabSet</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#updateRange">updateRange</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#VPositionRelative">VPositionRelative</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#write">write</a></li><li data-type='method'><a href="module-xterm_src_xterm.html#writeln">writeln</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-xterm_addons_attach_attach.html">xterm/addons/attach/attach</a><ul class='methods'><li data-type='method'><a href="module-xterm_addons_attach_attach.html#.attach">attach</a></li><li data-type='method'><a href="module-xterm_addons_attach_attach.html#.detach">detach</a></li></ul></li><li><a href="module-xterm_addons_fit_fit.html">xterm/addons/fit/fit</a></li><li><a href="module-xterm_addons_linkify_linkify.html">xterm/addons/linkify/linkify</a><ul class='methods'><li data-type='method'><a href="module-xterm_addons_linkify_linkify.html#.findLinkMatch">findLinkMatch</a></li><li data-type='method'><a href="module-xterm_addons_linkify_linkify.html#.linkify">linkify</a></li><li data-type='method'><a href="module-xterm_addons_linkify_linkify.html#.linkifyTerminalLine">linkifyTerminalLine</a></li></ul></li></ul><h3>Events</h3><ul><li><a href="module-xterm_addons_linkify_linkify.html#~event:linkify">linkify</a></li><li><a href="module-xterm_addons_linkify_linkify.html#~event:linkify:line">linkify:line</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">addons/attach/attach.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Implements the attach method, that
* attaches the terminal to a WebSocket stream.
*
* The bidirectional argument indicates, whether the terminal should
* send data to the socket as well and is true, by default.
*/
(function (attach) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = attach(require('../../src/xterm'));
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../src/xterm'], attach);
} else {
/*
* Plain browser environment
*/
attach(this.Xterm);
}
})(function (Xterm) {
'use strict';
/**
* This module provides methods for attaching a terminal to a WebSocket
* stream.
*
* @module xterm/addons/attach/attach
*/
var exports = {};
/**
* Attaches the given terminal to the given socket.
*
* @param {Xterm} term - The terminal to be attached to the given socket.
* @param {WebSocket} socket - The socket to attach the current terminal.
* @param {boolean} bidirectional - Whether the terminal should send data
* to the socket as well.
* @param {boolean} buffered - Whether the rendering of incoming data
* should happen instantly or at a maximum
* frequency of 1 rendering per 10ms.
*/
exports.attach = function (term, socket, bidirectional, buffered) {
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
term.socket = socket;
term._flushBuffer = function () {
term.write(term._attachSocketBuffer);
term._attachSocketBuffer = null;
clearTimeout(term._attachSocketBufferTimer);
term._attachSocketBufferTimer = null;
};
term._pushToBuffer = function (data) {
if (term._attachSocketBuffer) {
term._attachSocketBuffer += data;
} else {
term._attachSocketBuffer = data;
setTimeout(term._flushBuffer, 10);
}
};
term._getMessage = function (ev) {
if (buffered) {
term._pushToBuffer(ev.data);
} else {
term.write(ev.data);
}
};
term._sendData = function (data) {
socket.send(data);
};
socket.addEventListener('message', term._getMessage);
if (bidirectional) {
term.on('data', term._sendData);
}
socket.addEventListener('close', term.detach.bind(term, socket));
socket.addEventListener('error', term.detach.bind(term, socket));
};
/**
* Detaches the given terminal from the given socket
*
* @param {Xterm} term - The terminal to be detached from the given socket.
* @param {WebSocket} socket - The socket from which to detach the current
* terminal.
*/
exports.detach = function (term, socket) {
term.off('data', term._sendData);
socket = (typeof socket == 'undefined') ? term.socket : socket;
if (socket) {
socket.removeEventListener('message', term._getMessage);
}
delete term.socket;
};
/**
* Attaches the current terminal to the given socket
*
* @param {WebSocket} socket - The socket to attach the current terminal.
* @param {boolean} bidirectional - Whether the terminal should send data
* to the socket as well.
* @param {boolean} buffered - Whether the rendering of incoming data
* should happen instantly or at a maximum
* frequency of 1 rendering per 10ms.
*/
Xterm.prototype.attach = function (socket, bidirectional, buffered) {
return exports.attach(this, socket, bidirectional, buffered);
};
/**
* Detaches the current terminal from the given socket.
*
* @param {WebSocket} socket - The socket from which to detach the current
* terminal.
*/
Xterm.prototype.detach = function (socket) {
return exports.detach(this, socket);
};
return exports;
});
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Jul 14 2016 13:31:36 GMT+0000 (UTC) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>