2014-06-22 09:04:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('app').service('stdout', ['$window', function($window) {
|
|
|
|
var callback = undefined;
|
|
|
|
var websocket = undefined;
|
|
|
|
|
|
|
|
this.subscribe = function(path, _callback) {
|
|
|
|
callback = _callback;
|
|
|
|
|
|
|
|
var proto = ($window.location.protocol == 'https:' ? 'wss' : 'ws');
|
|
|
|
var route = [proto, "://", $window.location.host, '/ws/stdout/', path].join('');
|
|
|
|
|
|
|
|
websocket = new WebSocket(route);
|
|
|
|
websocket.onmessage = function(event) {
|
|
|
|
if (callback != undefined) {
|
|
|
|
callback(event.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
this.unsubscribe = function() {
|
|
|
|
callback = undefined;
|
2014-07-11 23:00:04 +00:00
|
|
|
if (websocket != undefined) {
|
2014-06-22 09:04:07 +00:00
|
|
|
websocket.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|