mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-18 08:26:45 +02:00
50e368c24a
fixed bug where include of pr template raised angularjs error
35 lines
939 B
JavaScript
35 lines
939 B
JavaScript
/*global angular, WebSocket, localStorage, console */
|
|
angular.module('app').service('stdout', ['$window', function ($window) {
|
|
'use strict';
|
|
|
|
var callback,
|
|
websocket,
|
|
token = localStorage.getItem('access_token');
|
|
|
|
this.subscribe = function (path, _callback) {
|
|
callback = _callback;
|
|
|
|
var proto = ($window.location.protocol === 'https:' ? 'wss' : 'ws'),
|
|
route = [proto, "://", $window.location.host, '/api/stream/stdout/', path, '?access_token=', token].join('');
|
|
|
|
websocket = new WebSocket(route);
|
|
websocket.onmessage = function (event) {
|
|
if (callback !== undefined) {
|
|
callback(event.data);
|
|
}
|
|
};
|
|
websocket.onclose = function (event) {
|
|
console.log('websocket closed at ' + path);
|
|
};
|
|
};
|
|
|
|
this.unsubscribe = function () {
|
|
callback = undefined;
|
|
if (websocket !== undefined) {
|
|
console.log('unsubscribing websocket at ' + websocket.url);
|
|
websocket.close();
|
|
websocket = undefined;
|
|
}
|
|
};
|
|
}]);
|