2014-03-02 05:43:20 +00:00
|
|
|
;// Live commit updates
|
|
|
|
|
|
|
|
if(typeof(Drone) === 'undefined') { Drone = {}; }
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
Drone.CommitUpdates = function(socket) {
|
|
|
|
if(typeof(socket) === "string") {
|
|
|
|
var url = [(window.location.protocol == 'https:' ? 'wss' : 'ws'),
|
|
|
|
'://',
|
|
|
|
window.location.host,
|
|
|
|
socket].join('')
|
|
|
|
this.socket = new WebSocket(url);
|
|
|
|
} else {
|
|
|
|
this.socket = socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lineFormatter = new Drone.LineFormatter();
|
|
|
|
this.attach();
|
|
|
|
}
|
|
|
|
|
|
|
|
Drone.CommitUpdates.prototype = {
|
|
|
|
lineBuffer: "",
|
|
|
|
autoFollow: false,
|
|
|
|
|
|
|
|
startOutput: function(el) {
|
|
|
|
if(typeof(el) === 'string') {
|
|
|
|
this.el = document.getElementById(el);
|
|
|
|
} else {
|
|
|
|
this.el = el;
|
|
|
|
}
|
|
|
|
|
2014-03-02 07:08:30 +00:00
|
|
|
if(!this.reqId) {
|
|
|
|
this.updateScreen();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
stopOutput: function() {
|
|
|
|
this.stoppingRefresh = true;
|
2014-03-02 05:43:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
attach: function() {
|
2014-03-02 07:08:30 +00:00
|
|
|
this.socket.onopen = this.onOpen;
|
|
|
|
this.socket.onerror = this.onError;
|
2014-03-02 05:43:20 +00:00
|
|
|
this.socket.onmessage = this.onMessage.bind(this);
|
2014-03-02 07:08:30 +00:00
|
|
|
this.socket.onclose = this.onClose;
|
2014-03-02 05:43:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateScreen: function() {
|
|
|
|
if(this.lineBuffer.length > 0) {
|
|
|
|
this.el.innerHTML += this.lineBuffer;
|
|
|
|
this.lineBuffer = '';
|
|
|
|
|
|
|
|
if (this.autoFollow) {
|
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-02 07:08:30 +00:00
|
|
|
if(this.stoppingRefresh) {
|
|
|
|
this.stoppingRefresh = false;
|
|
|
|
} else {
|
|
|
|
window.requestAnimationFrame(this.updateScreen.bind(this));
|
|
|
|
}
|
2014-03-02 05:43:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onOpen: function() {
|
|
|
|
console.log('output websocket open');
|
|
|
|
},
|
|
|
|
|
|
|
|
onError: function(e) {
|
|
|
|
console.log('websocket error: ' + e);
|
|
|
|
},
|
|
|
|
|
|
|
|
onMessage: function(e) {
|
|
|
|
this.lineBuffer += this.lineFormatter.format(e.data);
|
|
|
|
},
|
|
|
|
|
|
|
|
onClose: function(e) {
|
|
|
|
console.log('output websocket closed: ' + JSON.stringify(e));
|
2014-06-21 21:22:38 +00:00
|
|
|
window.location.reload();
|
2014-03-02 05:43:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Polyfill rAF for older browsers
|
|
|
|
window.requestAnimationFrame = window.requestAnimationFrame ||
|
|
|
|
window.webkitRequestAnimationFrame ||
|
|
|
|
function(callback, element) {
|
|
|
|
return window.setTimeout(function() {
|
|
|
|
callback(+new Date());
|
|
|
|
}, 1000 / 60);
|
|
|
|
};
|
|
|
|
|
2014-03-02 07:08:30 +00:00
|
|
|
window.cancelRequestAnimationFrame = window.cancelRequestAnimationFrame ||
|
|
|
|
window.cancelWebkitRequestAnimationFrame ||
|
|
|
|
function(fn) {
|
|
|
|
window.clearTimeout(fn);
|
|
|
|
};
|
|
|
|
|
2014-03-02 05:43:20 +00:00
|
|
|
})();
|