attach(this.Xterm);
}
})(function (Xterm) {
+ 'use strict';
+
/**
- * Attaches the current terminal to the given socket
+ * This module provides methods for attaching a terminal to a WebSocket
+ * stream.
*
- * @param {WebSocket} socket - The socket to attach the current terminal
+ * @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
+ * 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
+ * frequency of 1 rendering per 10ms.
*/
- Xterm.prototype.attach = function (socket, bidirectional, buffered) {
- var term = this;
-
+ exports.attach = function (term, socket, biderectional, buffered) {
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
- this.socket = socket;
+ term.socket = socket;
term._flushBuffer = function () {
term.write(term._attachSocketBuffer);
};
/**
- * Detaches the current terminal from the given 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
+ * terminal.
*/
- Xterm.prototype.detach = function (socket) {
- var term = this;
-
+ exports.detach = function (term, socket) {
term.off('data', term._sendData);
socket = (typeof socket == 'undefined') ? term.socket : socket;
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;
});
\ No newline at end of file