Browse Source

commit all files

pull/3/head
Krishna Srinivas 11 years ago
parent
commit
bcfd600aea
  1. 86
      app.js
  2. 10
      package.json
  3. 10482
      public/hterm.js
  4. 5144
      public/hterm_all.js
  5. 30
      public/index.html
  6. 62
      public/wetty.js

86
app.js

@ -0,0 +1,86 @@
var express = require('express');
var http = require('http');
var https = require('https');
var path = require('path');
var ws = require('websocket').server;
var pty = require('pty.js');
var fs = require('fs');
var opts = require('optimist')
.options({
sslkey: {
demand: false,
description: 'path to SSL key'
},
sslcert: {
demand: false,
description: 'path to SSL certificate'
},
port: {
demand: true,
alias: 'p',
description: 'port'
}
}).boolean('allow_discovery').argv;
var runhttps = false;
if (opts.sslkey && opts.sslcert) {
runhttps = true;
opts['ssl'] = {};
opts.ssl['key'] = fs.readFileSync(path.resolve(opts.sslkey));
opts.ssl['cert'] = fs.readFileSync(path.resolve(opts.sslcert));
}
process.on('uncaughtException', function(e) {
console.error('Error: ' + e);
});
var httpserv;
var app = express();
app.use('/', express.static(path.join(__dirname, 'public')));
if (runhttps) {
httpserv = https.createServer(opts.ssl, app).listen(opts.port, function() {
console.log('https on port ' + opts.port);
});
} else {
httpserv = http.createServer(app).listen(opts.port, function() {
console.log('http on port ' + opts.port);
});
}
var wss = new ws({
httpServer: httpserv
});
wss.on('request', function(request) {
var term;
var conn = request.accept('wetty', request.origin);
console.log((new Date()) + ' Connection accepted.');
conn.on('message', function(msg) {
var data = JSON.parse(msg.utf8Data);
if (!term) {
term = pty.spawn('/bin/login', [], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
term.on('data', function(data) {
conn.send(JSON.stringify({
data: data
}));
});
}
if (!data)
return;
if (data.rowcol) {
term.resize(data.col, data.row);
} else if (data.data) {
term.write(data.data);
}
});
})

10
package.json

@ -0,0 +1,10 @@
{
"name": "Wetty",
"version": "0.0.5",
"dependencies": {
"express": "3.5.1",
"websocket": "",
"pty.js": "",
"optimist": ""
}
}

10482
public/hterm.js

File diff suppressed because it is too large

5144
public/hterm_all.js

File diff suppressed because it is too large

30
public/index.html

@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>wtf</title>
<script src="hterm_all.js"></script>
<script src="hterm.js"></script>
<script src="wetty.js"></script>
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0px;
}
#terminal {
display: block;
position: relative;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="terminal"></div>
</body>
</html>

62
public/wetty.js

@ -0,0 +1,62 @@
var term;
var ws;
function Wetty(argv) {
this.argv_ = argv;
this.io = null;
this.pid_ = -1;
}
Wetty.prototype.run = function() {
this.io = this.argv_.io.push();
this.io.onVTKeystroke = this.sendString_.bind(this);
this.io.sendString = this.sendString_.bind(this);
this.io.onTerminalResize = this.onTerminalResize.bind(this);
}
Wetty.prototype.sendString_ = function(str) {
ws.send(JSON.stringify({
data: str
}));
};
Wetty.prototype.onTerminalResize = function(col, row) {
if (ws)
ws.send(JSON.stringify({
rowcol: true,
col: col,
row: row
}));
};
ws = new WebSocket(((window.location.protocol === 'https:') ? 'wss://' : 'ws://') + window.location.host, 'wetty');
ws.onopen = function() {
lib.init(function() {
term = new hterm.Terminal();
window.term = term;
term.decorate(document.getElementById('terminal'));
term.setCursorPosition(0, 0);
term.setCursorVisible(true);
term.runCommandClass(Wetty, document.location.hash.substr(1));
ws.send(JSON.stringify({
rowcol: true,
col: term.screenSize.width,
row: term.screenSize.height
}));
});
}
ws.onmessage = function(msg) {
if (!msg || !msg.data)
return;
var data = JSON.parse(msg.data);
if (term)
term.io.writeUTF16(data.data);
}
ws.onerror = function(e) {
console.log("WebSocket connection error");
}
ws.onclose = function() {
console.log("WebSocket connection closed");
}
Loading…
Cancel
Save