define(["jquery", "util", "session", "storage", "require"], function ($, util, session, storage, require) {
var playback = util.Module("playback");
var assert = util.assert;
var ALWAYS_REPLAY = {
"cursor-update": true,
"scroll-update": true
};
playback.getLogs = function (url) {
if (url.search(/^local:/) === 0) {
return $.Deferred(function (def) {
storage.get("recording." + url.substr("local:".length)).then(function (logs) {
if (! logs) {
def.resolve(null);
return;
}
logs = parseLogs(logs);
def.resolve(logs);
}, function (error) {
def.reject(error);
});
});
}
return $.Deferred(function (def) {
$.ajax({
url: url,
dataType: "text"
}).then(
function (logs) {
logs = parseLogs(logs);
def.resolve(logs);
},
function (error) {
def.reject(error);
});
});
};
function parseLogs(logs) {
logs = logs.replace(/\r\n/g, '\n');
logs = logs.split(/\n/g);
var result = [];
for (var i=0; i<logs.length; i++) {
var line = logs[i];
line = line.replace(/^\s+/, "").replace(/\s+$/, "");
if (line.search(/\/\*/) === 0) {
var last = line.search(/\*\//);
if (last == -1) {
console.warn("bad line:", line);
continue;
}
line = line.substr(last+2);
}
line = line.replace(/^\s+/, "");
if (! line) {
continue;
}
line = JSON.parse(line);
result.push(line);
}
return Logs(result);
}
var Logs = util.Class({
constructor: function (logs, fromStorage) {
this.logs = logs;
this.fromStorage = fromStorage;
this.pos = 0;
},
play: function () {
this.start = Date.now();
if (this.pos >= this.logs.length) {
this.unload();
return;
}
if (this.pos !== 0) {