From e80ebd564e2216cf66d839520e91c4d17ec9e177 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Wed, 30 Jan 2013 16:42:11 -0500 Subject: [PATCH] parse in the client too, limit to 50fps --- index.html | 72 ++++++++++++++++++++++++++++++++++++++++++------------- server.coffee | 25 ++++++++++++------- terminal.coffee | 12 +++++++--- 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index e70dfc7..a38d705 100644 --- a/index.html +++ b/index.html @@ -3,9 +3,11 @@ Remote Terminal Viewer + diff --git a/server.coffee b/server.coffee index 1d0422b..32daeff 100644 --- a/server.coffee +++ b/server.coffee @@ -1,7 +1,7 @@ handler = (req, res) -> - err = (req, res) -> - res.writeHead(404, 'Content-Type': 'text/plain') - return res.end("Error loading #{req.url}") + reply_err = (req, res, msg) -> + res.writeHead(200, 'Content-Type': 'text/plain') + return res.end("Error loading #{req.url} \"#{msg}\"") switch req.url when '/', '/index.html' filename = __dirname + '/index.html' @@ -9,14 +9,24 @@ handler = (req, res) -> when '/jquery.js' filename = '/usr/share/javascript/jquery/jquery.min.js' type = 'text/javascript' + when '/terminal.js' + filename = __dirname + '/terminal.coffee' + type = 'text/javascript' else - return err req, res - fs.readFile filename, (err, data) -> - return err req, res if err + return reply_err req, res + fs.readFile filename, 'utf8', (err, data) -> + return reply_err req, res, err if err + + if filename.substr(filename.length - 7) is '.coffee' + try + data = coffee.compile data + catch e + return reply_err req, res, "server faild to compile #{filename}: #{JSON.stringify(e)}" res.writeHead(200, 'Content-Type': type) res.end(data) +coffee = require 'coffee-script' app = require('http').createServer(handler) io = require('socket.io').listen(app) fs = require('fs') @@ -43,8 +53,7 @@ process.stdin.setEncoding 'utf8' process.stdin.on 'data', (data) -> term.update data - # FIXME send data, and have client parse it for s in sockets - s.emit 'init', width: term.width, height: term.height, x: term.x, y: term.y, a: term.a, text: term.text, attributes: term.attributes + s.emit 'data', data process.stdin.on 'end', -> process.exit() diff --git a/terminal.coffee b/terminal.coffee index 34c7515..c7dbd7f 100644 --- a/terminal.coffee +++ b/terminal.coffee @@ -1,5 +1,11 @@ -async = require 'async' -fs = require 'fs' +# this file is used by the client and server. + +# work around lack of module system in the browser: +if exports? + my_exports = exports +else + window.terminal = {} + my_exports = window.terminal class Terminal # public: @@ -191,5 +197,5 @@ class Terminal return -1 unless parts? return parts[0].length -exports.new = (width, height) -> +my_exports.new = (width, height) -> return new Terminal width, height -- 1.7.10.4