{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+EĞRI" length;Ti³I" digest;TI"%2879e7ac2fb5ff9ef92c8b13a513267e;FI" source;TI"³ var AJAXTransport = (function(WebConsole) { var inherits = WebConsole.inherits; var EventEmitter = WebConsole.EventEmitter; var FORM_MIME_TYPE = 'application/x-www-form-urlencoded; charset=utf-8'; 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.initializeEventHandlers(); }; inherits(AJAXTransport, EventEmitter); // Initializes the default event handlers. AJAXTransport.prototype.initializeEventHandlers = function() { this.on('input', this.sendInput); this.on('configuration', this.sendConfiguration); this.once('initialization', function(cols, rows) { this.emit('configuration', cols, rows); this.pollForPendingOutput(); }); }; // Shorthand for creating XHR requests. AJAXTransport.prototype.createRequest = function(method, url, options) { options || (options = {}); var request = new XMLHttpRequest; 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)); } request.setRequestHeader('Content-Type', FORM_MIME_TYPE); 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 === XMLHttpRequest.DONE) { 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 === XMLHttpRequest.DONE) { 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"%a41250d8d18d68c0c333ea4371939536;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-12-13T19:33:55+02:00;TI" digest;TI"%c309ce3c30a9741f5d841d6e80b4af43;F{I" path;TI"P/Users/genadi/Development/web-console/lib/assets/javascripts/web-console.js;FI" mtime;TI"2013-12-13T19:33:55+02:00;TI" digest;TI"%9204a231f0963651e033ecdf0e1d3feb;F{I" path;TI"P/Users/genadi/Development/web-console/lib/assets/javascripts/web_console.js;FI" mtime;TI"2013-12-13T19:33:55+02:00;TI" digest;TI"%353eb1cce387e058e857d82c95745856;F{I" path;TI"L/Users/genadi/Development/web-console/vendor/assets/javascripts/term.js;FI" mtime;TI"2013-12-13T19:33:55+02:00;TI" digest;TI"%22f8da6d44f088fa7e9e840efd2ff53a;FI" _version;TI"%ac1cd7cf9811f9938e2b8937c60a24e6;F