mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-19 08:21:01 +00:00
32 lines
715 B
JavaScript
32 lines
715 B
JavaScript
|
'use strict';
|
||
|
|
||
|
(function () {
|
||
|
|
||
|
function FeedService($http, $window) {
|
||
|
var token = localStorage.getItem('access_token');
|
||
|
var proto = ($window.location.protocol == 'https:' ? 'wss' : 'ws');
|
||
|
var route = [proto, "://", $window.location.host, '/api/stream/user?access_token=', token].join('');
|
||
|
|
||
|
var wsCallback = undefined;
|
||
|
var ws = new WebSocket(route);
|
||
|
ws.onmessage = function(event) {
|
||
|
var data = angular.fromJson(event.data);
|
||
|
if (wsCallback != undefined) {
|
||
|
wsCallback(data);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
this.subscribe = function(callback) {
|
||
|
wsCallback = callback;
|
||
|
};
|
||
|
|
||
|
this.unsubscribe = function() {
|
||
|
wsCallback = undefined;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
angular
|
||
|
.module('drone')
|
||
|
.service('feed', FeedService);
|
||
|
})();
|