52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('insight.connection').controller('ConnectionController',
|
|
function($scope, $window, Status, getSocket, PeerSync) {
|
|
|
|
// Set initial values
|
|
$scope.apiOnline = true;
|
|
$scope.serverOnline = true;
|
|
$scope.clienteOnline = true;
|
|
|
|
var socket = getSocket($scope);
|
|
|
|
// Check for the node server connection
|
|
socket.on('disconnect', function() {
|
|
$scope.serverOnline = false;
|
|
});
|
|
|
|
socket.on('connect', function() {
|
|
$scope.serverOnline = true;
|
|
});
|
|
|
|
// Check for the api connection
|
|
$scope.getConnStatus = function() {
|
|
PeerSync.get({},
|
|
function(peer) {
|
|
$scope.apiOnline = peer.connected;
|
|
},
|
|
function() {
|
|
$scope.apiOnline = false;
|
|
});
|
|
};
|
|
|
|
socket.emit('subscribe', 'sync');
|
|
socket.on('status', function(sync) {
|
|
$scope.apiOnline = (sync.status !== 'aborted' && sync.status !== 'error');
|
|
});
|
|
|
|
// Check for the client conneciton
|
|
$window.addEventListener('offline', function() {
|
|
$scope.$apply(function() {
|
|
$scope.clienteOnline = false;
|
|
});
|
|
}, true);
|
|
|
|
$window.addEventListener('online', function () {
|
|
$scope.$apply(function() {
|
|
$scope.clienteOnline = true;
|
|
});
|
|
}, true);
|
|
|
|
});
|