{I" class:ETI"ProcessedAsset;FI"logical_path;TI"$web_console/console_sessions.js;FI" pathname;TI"a/Users/genadi/Development/web-console/app/assets/javascripts/web_console/console_sessions.js;FI"content_type;TI"application/javascript;TI" mtime;Tl+#C'RI" length;TièI" digest;TI"%040e5423b2699928009c6ee02064a96b;FI" source;TI"è var AJAXTransport = (function(WebConsole) { var inherits = WebConsole.inherits; var EventEmitter = WebConsole.EventEmitter; // Use an IE friendly implementation of XMLHttpRequest. XHR = (function() { try { return XMLHttpRequest; } catch (e) { return function() { return new ActiveXObject('Microsoft.XMLHTTP'); }; } }).call(this); var AJAXTransport = function(options) { EventEmitter.call(this); options || (options = {}); this.url = (typeof options.url === 'string') ? { input: options.url, pendingOutput: options.url, configuration: options.url } : options.url; this.pendingInput = ''; this.on('input', this.sendInput); this.on('configuration', this.sendConfiguration); this.once('initialization', function(cols, rows) { this.emit('configuration', cols, rows); this.pollForPendingOutput(); }); }; inherits(AJAXTransport, EventEmitter); // Shorthand for creating XHR requests. AJAXTransport.prototype.createRequest = function(method, url, options) { options || (options = {}); var request = new XHR(); request.open(method, url); if (typeof options.form === 'object') { var content = [], form = options.form; for (var key in form) { var value = form[key]; content.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); } var formMimeType = 'application/x-www-form-urlencoded; charset=utf-8'; request.setRequestHeader('Content-Type', formMimeType); request.data = content.join('&'); } return request; }; AJAXTransport.prototype.pollForPendingOutput = function() { var request = this.createRequest('GET', this.url.pendingOutput); var self = this; request.onreadystatechange = function() { if (request.readyState === 4) { if (request.status === 200) { self.emit('pendingOutput', request.responseText); self.pollForPendingOutput(); } else { self.emit('disconnect', request); } } }; request.send(null); }; // Send the input to the server. // // Each key press is encoded to an intermediate format, before it is sent to // the server. // // WebConsole#keysPressed is an alias for WebConsole#sendInput. AJAXTransport.prototype.sendInput = function(input) { input || (input = ''); if (this.disconnected) return; if (this.sendingInput) return this.pendingInput += input; // Indicate that we are starting to send input. this.sendingInput = true; var request = this.createRequest('PUT', this.url.input, { form: { input: this.pendingInput + input } }); // Clear the pending input. this.pendingInput = ''; var self = this; request.onreadystatechange = function() { if (request.readyState === 4) { self.sendingInput = false; if (self.pendingInput) self.sendInput(); } }; request.send(request.data); }; // Send the terminal configuration to the server. // // Right now by configuration, we understand the terminal widht and terminal // height. // // WebConsole#resized is an alias for WebConsole#sendconfiguration. AJAXTransport.prototype.sendConfiguration = function(cols, rows) { if (this.disconnected) return; var request = this.createRequest('PUT', this.url.configuration, { form: { width: cols, height: rows } }); // Just send the configuration and don't care about any output. request.send(request.data); }; return AJAXTransport; }).call(this, WebConsole); window.addEventListener('load', function() { var geometry = calculateFitScreenGeometry(); config.terminal.cols = geometry[0]; config.terminal.rows = geometry[1]; var terminal = window.terminal = new WebConsole.Terminal(config.terminal); terminal.on('data', function(data) { transport.emit('input', data); }); var transport = new AJAXTransport(config.transport); transport.on('pendingOutput', function(response) { var json = JSON.parse(response); if (json.output) terminal.write(json.output); }); transport.on('disconnect', function() { terminal.destroy(); }); transport.emit('initialization', terminal.cols, terminal.rows); // Utilities // --------- function calculateFitScreenGeometry() { // Currently, resizing term.js is broken. E.g. opening vi causes it to go // back to 80x24 and fail with off-by-one error. Other stuff, like chip8 // are rendered incorrectly and so on. // // To work around it, create a temporary terminal, just so we can get the // best dimensions for the screen. var temporary = new WebConsole.Terminal; try { return temporary.fitScreen(); } finally { temporary.destroy(); } } }); ;TI"dependency_digest;TI"%fb820ddbbb1c385f5a6e10088fc879fa;FI"required_paths;T[ I"L/Users/genadi/Development/web-console/vendor/assets/javascripts/term.js;FI"P/Users/genadi/Development/web-console/lib/assets/javascripts/web_console.js;FI"P/Users/genadi/Development/web-console/lib/assets/javascripts/web-console.js;FI"a/Users/genadi/Development/web-console/app/assets/javascripts/web_console/console_sessions.js;FI"dependency_paths;T[ {I" path;TI"a/Users/genadi/Development/web-console/app/assets/javascripts/web_console/console_sessions.js;FI" mtime;TI"2013-09-04T17:26:43+03:00;TI" digest;TI"%34e4adf5fe5145b0cfd41bd1116aee12;F{I" path;TI"P/Users/genadi/Development/web-console/lib/assets/javascripts/web-console.js;FI" mtime;TI"2013-09-04T17:26:43+03:00;TI" digest;TI"%d240f0e6310482d53ffae035ebba6892;F{I" path;TI"P/Users/genadi/Development/web-console/lib/assets/javascripts/web_console.js;FI" mtime;TI"2013-09-04T17:26:43+03:00;TI" digest;TI"%b0b11ad19970e89280db0406dbf919cf;F{I" path;TI"L/Users/genadi/Development/web-console/vendor/assets/javascripts/term.js;FI" mtime;TI"2013-09-04T17:26:43+03:00;TI" digest;TI"%d7311a5bea44b9574c5f21c9902c6cc9;FI" _version;TI"%2cf3622cbba861b85d33ffabfa420c13;F