Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 371734aeeb
Fetching contributors…

Cannot retrieve contributors at this time

142 lines (125 sloc) 5.148 kb
<!DOCTYPE HTML>
<html>
<head>
<script src="js/vt/parse.js"></script>
<script src="js/vt/emulate.js"></script>
<script src="js/ttyrec-browser.js"></script>
<script src="js/binary-read.js"></script>
<script src="js/vt/font.js"></script>
<script src="js/vt/canvasview.js"></script>
<script>
var tty_data;
var nextFrameIdx = 0;
var accurateTimeInterval = 1000/60; // max 60fps
var frameJumpMax = 20;
var viewReady = false;
var playReady = false;
var initialState;
var vtview;
setTimeout(function(){
vtview = new VTCanvasView(document.getElementById('canvas'), {
onReady: function () {
viewReady = true;
readyCheck();
},
fontName: 'fixed-9x18'
});
initialState = { vtview: vtview.freeze(), nextFrameIdx: 0 };
}, 20);
get_binary_data_async("/jsttyplay/tty/demo", function (data, err) {
if ( err ) throw err;
tty_data = TTYRecParse(data);
playReady = true;
readyCheck();
});
function readyCheck() {
if ( viewReady && playReady )
go();
}
var time_diff;
function go() {
var now = (new Date()).getTime()/1000;
time_diff = now - tty_data[nextFrameIdx].time;
nextFrame();
}
var nextFrameTimeout;
function nextFrame() {
var now = (new Date()).getTime()/1000;
var framesCounted = 0;
while ( framesCounted < frameJumpMax && nextFrameIdx < tty_data.length && tty_data[nextFrameIdx].time + time_diff - now < 0 ) {
record = tty_data[nextFrameIdx++];
vtview.parseData(record.data);
framesCounted++;
}
vtview.draw();
if ( nextFrameIdx < tty_data.length )
nextFrameTimeout = setTimeout(nextFrame, (tty_data[0].time + time_diff - (new Date()).getTime()/1000) * 1000 + accurateTimeInterval);
}
setTimeout(function () {
var freezeData;
document.getElementById("pause").addEventListener('click', function (evt) {
if ( nextFrameTimeout ) {
clearTimeout(nextFrameTimeout);
nextFrameTimeout = null;
}
evt.preventDefault();
}, false);
document.getElementById("play").addEventListener('click', function (evt) {
if ( !nextFrameTimeout )
go();
evt.preventDefault();
}, false);
document.getElementById("playpause").addEventListener('click', function (evt) {
evt.preventDefault();
}, false);
document.getElementById("freeze").addEventListener('click', function (evt) {
freezeData = { vtview: vtview.freeze(), nextFrameIdx: nextFrameIdx };
evt.preventDefault();
}, false);
document.getElementById("thaw").addEventListener('click', function (evt) {
evt.preventDefault();
var wasplaying = false;
if ( freezeData ) {
if ( nextFrameTimeout ) {
wasplaying = true;
clearTimeout(nextFrameTimeout);
nextFrameTimeout = null;
}
nextFrameIdx = freezeData.nextFrameIdx;
vtview.thaw( freezeData.vtview );
vtview.draw();
if ( wasplaying )
go();
}
}, false);
document.getElementById("rewind").addEventListener('click', function (evt) {
evt.preventDefault();
var wasplaying = false;
if ( freezeData ) {
if ( nextFrameTimeout ) {
wasplaying = true;
clearTimeout(nextFrameTimeout);
nextFrameTimeout = null;
}
nextFrameIdx = initialState.nextFrameIdx;
vtview.thaw( initialState.vtview );
vtview.draw();
if ( wasplaying )
go();
}
}, false);
}, 100);
</script>
</head>
<body>
<canvas id="canvas" width=80 height=24>No canvas support!</canvas>
<form>
<input type="submit" value="Play" id="play">
<input type="submit" value="Pause" id="pause">
<input type="submit" value="PlayPause" id="playpause">
<input type="submit" value="Freeze" id="freeze">
<input type="submit" value="Thaw" id="thaw">
<input type="submit" value="Rewind" id="rewind">
</form>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.