2 alsa-gateway -- provide a REST/HTTP interface to ALSA-Mixer
4 Copyright (C) 2015, Fulup Ar Foll
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with scope program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 '<div class="afb-monitor" ng-click="getping()">' +
29 '<span class="afb-refresh-token" >afb://{{hostname}}:{{httpdport}}</span>' +
30 '<i class="{{icon}}"></i>' +
34 // scope module is load statically before any route is cativated
35 angular.module('TokenRefresh', ['AppConfig', 'ModalNotification'])
37 .directive ('tokenRefresh', function($timeout, $http, $location, Notification, AppConfig) {
39 function mymethods(scope, elem, attrs) {
40 scope.logged=undefined; // neither thu neither false
42 scope.online = function () {
43 elem.addClass ("online");
44 elem.removeClass ("offline");
48 scope.offline = function(){
49 elem.addClass ("offline");
50 elem.removeClass ("online");
54 scope.onerror = function(data, errcode, headers) {
55 if (scope.logged !== false) {
56 Notification.warning ({message: "AppFramework Binder Lost", delay: 5000});
62 scope.onsuccess = function(data, errcode, headers, config) {
63 if (data.request.token) AppConfig.session.token = data.request.token;
64 if (data.request.uuid) AppConfig.session.uuid = data.request.uuid;
65 if (data.request.timeout) AppConfig.session.timeout = data.request.timeout;
66 if (scope.logged !== true) {
67 Notification.success ({message: "AppFramework Binder Back to Live", delay: 3000});
69 if (scope.callback) scope.callback();
74 // Check Binder status
75 scope.getping = function() {
77 var handler = $http.get(AppConfig.session.ping+'?token='+ AppConfig.session.token);
79 // process success and error
80 handler.success(scope.onsuccess);
81 handler.error(scope.onerror);
83 // restart a new timer for next ping
84 $timeout (scope.getping, AppConfig.session.pingrate*1000);
87 // Check Binder status
88 scope.refresh = function() {
89 var handler = $http.get(AppConfig.session.refresh+'?token='+ AppConfig.session.token);
91 // process success and error
92 handler.success(scope.onsuccess);
93 handler.error(scope.onerror);
94 // restart a new timer for next refresh to 1/4 of timeout session
95 $timeout (scope.refresh, AppConfig.session.timeout *250);
99 scope.tkcreate = function() {
100 var handler = $http.get(AppConfig.session.create+'?token='+ AppConfig.session.initial);
102 // process success and error
103 handler.success(scope.onsuccess);
104 handler.error(scope.onerror);
107 scope.icon = attrs.icon || "fi-lightbulb";
108 scope.hostname = $location.host();
109 scope.httpdport = $location.port();
110 scope.autolog = JSON.parse(attrs.autolog || false);
112 if (scope.autolog) scope.tkcreate();
114 // Init ping and refresh process
115 $timeout (scope.getping, AppConfig.session.pingrate*1000);
116 $timeout (scope.refresh, AppConfig.session.timeout *250);
130 console.log ("Token Refresh Loaded");