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($log, $window, $timeout, $location, Notification, AppConfig, AppCall) {
39 function mymethods(scope, elem, attrs) {
40 scope.logged=undefined; // neither thu neither false
42 $window.onbeforeunload = function () {
43 AppCall.get ("token", "reset", {/*query*/}, function () {
48 scope.online = function () {
49 elem.addClass ("online");
50 elem.removeClass ("offline");
54 scope.offline = function(){
55 elem.addClass ("offline");
56 elem.removeClass ("online");
60 scope.onerror = function() {
61 if (scope.logged !== false) {
62 Notification.warning ({message: "AppFramework Binder Lost", delay: 5000});
68 scope.onsuccess = function(jresp) {
70 if (jresp.request.status !== "success") {
71 Notification.warning ({message: jresp.request.info, delay: 5000});
76 if (jresp.request.token) AppConfig.session.token = jresp.request.token;
77 if (jresp.request.uuid) AppConfig.session.uuid = jresp.request.uuid;
78 if (jresp.request.timeout) AppConfig.session.timeout = jresp.request.timeout;
80 if (scope.logged !== true) {
81 Notification.success ({message: "AppFramework Binder Back to Live", delay: 3000});
83 if (scope.callback) scope.callback(jresp);
88 // Check Binder status
89 scope.getping = function() {
91 AppCall.get ("token", "ping", {/*query*/},function(jresp, errcode) {
92 if (errcode) scope.onerror();
93 else scope.onsuccess (jresp);
94 // restart a new timer for next ping
95 $timeout (scope.getping, AppConfig.session.pingrate*1000);
99 // Check Binder status
100 scope.refresh = function() {
102 AppCall.get ("token", "refresh", {/*query*/},function(jresp, errcode) {
103 if (errcode) scope.onerror();
104 else scope.onsuccess (jresp);
105 // restart a new timer for next refresh
106 $timeout (scope.refresh, AppConfig.session.timeout *250);
110 // Initial connection
111 scope.tkcreate = function() {
113 AppCall.get ("token", "create", {token: AppConfig.session.initial},function(jresp, errcode) {
114 if (errcode) scope.onerror();
115 else scope.onsuccess (jresp);
119 scope.icon = attrs.icon || "fi-lightbulb";
120 scope.hostname = $location.host();
121 scope.httpdport = $location.port();
122 scope.autolog = JSON.parse(attrs.autolog || false);
124 if (scope.autolog) scope.tkcreate();
126 // Init ping and refresh process
127 $timeout (scope.getping, AppConfig.session.pingrate*1000);
128 $timeout (scope.refresh, AppConfig.session.timeout *250);
142 console.log ("Token Refresh Loaded");