Skip to content

Home Information - Your home, your data, organized.

Python

Added base code for dealing with audio. WIP.

Anthony Cassandraa6d0614a4ad2
diff --git a/src/hi/apps/alert/enums.py b/src/hi/apps/alert/enums.py
index 765a7da9..d9bbb3e0 100644
--- a/src/hi/apps/alert/enums.py
+++ b/src/hi/apps/alert/enums.py
@@ -1,19 +1,22 @@
from hi.apps.common.enums import LabeledEnum
+from hi.apps.config.enums import AudioSignal
class AlarmLevel(LabeledEnum):
- NONE = ( 'None' , '' , 0 )
- INFO = ( 'Info' , '' , 10 )
- WARNING = ( 'Warning' , '' , 100 )
- CRITICAL = ( 'Critical' , '' , 1000 )
+ NONE = ( 'None' , '' , 0 , None )
+ INFO = ( 'Info' , '' , 10 , AudioSignal.INFO )
+ WARNING = ( 'Warning' , '' , 100 , AudioSignal.WARNING )
+ CRITICAL = ( 'Critical' , '' , 1000 , AudioSignal.CRITICAL )
def __init__( self,
label : str,
description : str,
- priority : int ):
+ priority : int,
+ audio_signal : AudioSignal ):
super().__init__( label, description )
self.priority = priority
+ self.audio_signal = audio_signal
return
diff --git a/src/hi/apps/alert/transient_models.py b/src/hi/apps/alert/transient_models.py
index 1f13b37a..d1cf6b61 100644
--- a/src/hi/apps/alert/transient_models.py
+++ b/src/hi/apps/alert/transient_models.py
@@ -12,3 +12,13 @@ class Alarm:
alarm_level : AlarmLevel
alarm_lifetime_secs : int
timestamp : datetime
+
+ @property
+ def audio_signal_name(self):
+
+ # TODO: Currently based only on the alarm level, but eventually
+ # allow alarm-specific sounds. e.g., tornado siren sound when
+ # there's a weather alert.
+
+ return str(self.alarm_level.audio_signal)
+
diff --git a/src/hi/apps/api/views.py b/src/hi/apps/api/views.py
index 80d0885f..11339822 100644
--- a/src/hi/apps/api/views.py
+++ b/src/hi/apps/api/views.py
@@ -2,6 +2,7 @@ from datetime import datetime
import json
import logging
+from django.core.exceptions import BadRequest
from django.http import HttpResponse
from django.views.generic import View
@@ -29,7 +30,9 @@ class StatusView( View ):
try:
last_server_datetime = datetime.fromisoformat( last_server_timestamp.replace("Z", "+00:00") )
except (TypeError, ValueError):
- logger.warning( f'Bad client timestamp param "{last_server_timestamp}"' )
+ msg = f'Missing or invalid date/time format "{last_server_timestamp}".'
+ logger.warning( msg )
+ raise BadRequest( msg )
server_start_datetime = SettingsManager().get_server_start_datetime()
server_datetime = datetimeproxy.now()
@@ -54,6 +57,3 @@ class StatusView( View ):
content_type='application/json',
status = 200,
)
-
-
-
diff --git a/src/hi/apps/attribute/attribute_enums.py b/src/hi/apps/attribute/attribute_enums.py
index f094d60d..b9c55ffb 100644
--- a/src/hi/apps/attribute/attribute_enums.py
+++ b/src/hi/apps/attribute/attribute_enums.py
@@ -1,6 +1,6 @@
from typing import List, Tuple
-from hi.apps.config.enums import Theme
+from hi.apps.config.enums import AudioFile, Theme
from hi.constants import TIMEZONE_NAME_LIST
@@ -19,10 +19,12 @@ class AttributeEnums:
TIMEZONE_CHOICES_ID = 'hi.timezone'
THEME_CHOICES_ID = 'hi.theme'
+ AUDIO_FILE_CHOICES_ID = 'hi.audio.file'
ID_TO_CHOICES = {
TIMEZONE_CHOICES_ID: [ ( x, x ) for x in TIMEZONE_NAME_LIST ],
THEME_CHOICES_ID: Theme.choices(),
+ AUDIO_FILE_CHOICES_ID: AudioFile.choices(),
}
@classmethod
diff --git a/src/hi/apps/config/context_processors.py b/src/hi/apps/config/context_processors.py
new file mode 100644
index 00000000..92c40e94
--- /dev/null
+++ b/src/hi/apps/config/context_processors.py
@@ -0,0 +1,8 @@
+from .settings_manager import SettingsManager
+
+
+def settings_context(request):
+ settings_manager = SettingsManager()
+ return {
+ 'CONSOLE_AUDIO_MAP': settings_manager.get_console_audio_map(),
+ }
diff --git a/src/hi/apps/config/enums.py b/src/hi/apps/config/enums.py
index 2865021b..284d5284 100644
--- a/src/hi/apps/config/enums.py
+++ b/src/hi/apps/config/enums.py
@@ -1,5 +1,6 @@
from hi.apps.attribute.enums import AttributeValueType
from hi.apps.common.enums import LabeledEnum
+from hi.apps.common.utils import get_absolute_static_path
class ConfigPageType(LabeledEnum):
@@ -24,6 +25,35 @@ class ConfigPageType(LabeledEnum):
def default(self):
return ConfigPageType.SETTINGS
+
+class AudioFile(LabeledEnum):
+ # Predefined sounds in statically served files.
+
+ BICYCLE_BELL = ( 'Bicycle Bell' , '' , 'bicycle-bell.wav' )
+ BOING_SPRING = ( 'Boing Spring' , '' , 'boing-spring.wav' )
+ BUZZER = ( 'Buzzer' , '' , 'buzzer.wav' )
+ CHIME = ( 'Chime' , '' , 'chime.wav' )
+ CRITICAL = ( 'Critical' , '' , 'critical.wav' )
+ FINAL_REVEAL_BELL = ( 'Final Reveal Bell' , '' , 'final-reveal-bell.wav' )
+ INDUSTRIAL_ALARM = ( 'Industrial Alarm' , '' , 'industrial-alarm.wav' )
+ INFO = ( 'Info' , '' , 'info.wav' )
+ STORE_DOOR_CHIME = ( 'Store Door Chime' , '' , 'store-door-chime.wav' )
+ TORNADO_SIREN = ( 'Tornado Siren' , '' , 'tornado-siren.wav' )
+ WARNING = ( 'Warning' , '' , 'warning.wav' )
+ WEATHER_ALERT = ( 'Weather Alert' , '' , 'weather-alert.wav' )
+
+ @property
+ def url(self):
+ return get_absolute_static_path( f'audio/{self.base_filename}' )
+
+ def __init__( self,
+ label : str,
+ description : str,
+ base_filename : str ):
+ super().__init__( label, description )
+ self.base_filename = base_filename
+ return
+
class SubsystemType(LabeledEnum):
@@ -69,6 +99,36 @@ class SubsystemAttributeType(LabeledEnum):
False,
'',
)
+ INFO_AUDIO_FILE = (
+ 'Info Alert Sound',
+ 'The sound to play when an INFO level alert arrives.',
+ SubsystemType.ALERTS,
+ AttributeValueType.ENUM,
+ 'hi.audio.file',
+ True,
+ False,
+ AudioFile.INFO,
+ )
+ WARNING_AUDIO_FILE = (
+ 'Warning Alert Sound',
+ 'The sound to play when an WARNING level alert arrives.',
+ SubsystemType.ALERTS,
+ AttributeValueType.ENUM,
+ 'hi.audio.file',
+ True,
+ False,
+ AudioFile.WARNING,
+ )
+ CRITICAL_AUDIO_FILE = (
+ 'Critical Alert Sound',
+ 'The sound to play when an CRITICAL level alert arrives.',
+ SubsystemType.ALERTS,
+ AttributeValueType.ENUM,
+ 'hi.audio.file',
+ True,
+ False,
+ AudioFile.CRITICAL,
+ )
def __init__( self,
label : str,
@@ -87,3 +147,18 @@ class SubsystemAttributeType(LabeledEnum):
self.is_required = is_required
self.initial_value = initial_value
return
+
+
+class AudioSignal(LabeledEnum):
+
+ INFO = ( 'Info' , '', SubsystemAttributeType.INFO_AUDIO_FILE )
+ WARNING = ( 'Warning' , '', SubsystemAttributeType.WARNING_AUDIO_FILE)
+ CRITICAL = ( 'Critical' , '', SubsystemAttributeType.CRITICAL_AUDIO_FILE )
+
+ def __init__( self,
+ label : str,
+ description : str,
+ subsystem_attribute_type : str ):
+ super().__init__( label, description )
+ self.subsystem_attribute_type = subsystem_attribute_type
+ return
diff --git a/src/hi/apps/config/settings_manager.py b/src/hi/apps/config/settings_manager.py
index d9b582b0..15c218b7 100644
--- a/src/hi/apps/config/settings_manager.py
+++ b/src/hi/apps/config/settings_manager.py
@@ -1,7 +1,7 @@
from datetime import datetime
import logging
from threading import local
-from typing import List
+from typing import Dict, List
from django.db import transaction
from django.db.models.signals import post_save, post_delete
@@ -11,7 +11,7 @@ from hi.apps.attribute.enums import AttributeType
import hi.apps.common.datetimeproxy as datetimeproxy
from hi.apps.common.singleton import Singleton
-from .enums import SubsystemType, SubsystemAttributeType
+from .enums import AudioFile, AudioSignal, SubsystemType, SubsystemAttributeType
from .models import Subsystem, SubsystemAttribute
logger = logging.getLogger(__name__)
@@ -37,7 +37,18 @@ class SettingsManager( Singleton ):
continue
continue
return
-
+
+ def get_console_audio_map( self ) -> Dict[ str, str ]:
+ console_audio_map = dict()
+ for audio_signal in AudioSignal:
+ if audio_signal.subsystem_attribute_type:
+ attr_value = self.get_setting_value( audio_signal.subsystem_attribute_type )
+ if attr_value:
+ audio_file = AudioFile.from_name( attr_value )
+ console_audio_map[str(audio_signal)] = audio_file.url
+ continue
+ return console_audio_map
+
def get_server_start_datetime( self ) -> datetime:
return self._server_start_datetime
diff --git a/src/hi/apps/config/templates/config/panes/console_settings.html b/src/hi/apps/config/templates/config/panes/console_settings.html
new file mode 100644
index 00000000..98e5497c
--- /dev/null
+++ b/src/hi/apps/config/templates/config/panes/console_settings.html
@@ -0,0 +1,6 @@
+<div id="hi-console-audio" style="display: none;">
+ {% for signal_name, signal_sound_url in CONSOLE_AUDIO_MAP.items %}
+ <audio id="hi-audio-signal-{{ signal_name }}" src="{{ signal_sound_url }}"
+ preload="auto" loop="true" hidden="hidden" ></audio>
+ {% endfor %}
+</div>
diff --git a/src/hi/apps/config/views.py b/src/hi/apps/config/views.py
index 06a11775..3238e56e 100644
--- a/src/hi/apps/config/views.py
+++ b/src/hi/apps/config/views.py
@@ -110,14 +110,20 @@ class ConfigSettingsView( ConfigPageView ):
subsystem_attribute_formset_list.append( subsystem_attribute_formset )
continue
- if all_valid:
- with transaction.atomic():
- for subsystem_attribute_formset in subsystem_attribute_formset_list:
- subsystem_attribute_formset.save()
- continue
-
- context = {
- 'subsystem_attribute_formset_list': subsystem_attribute_formset_list,
- }
- return render( request, 'config/panes/settings_form.html', context )
+ if not all_valid:
+ context = {
+ 'subsystem_attribute_formset_list': subsystem_attribute_formset_list,
+ }
+ return render( request, 'config/panes/settings_form.html', context )
+
+ with transaction.atomic():
+ for subsystem_attribute_formset in subsystem_attribute_formset_list:
+ subsystem_attribute_formset.save()
+ continue
+
+ # Some settings (e.g., audio files) define what gets loaded into
+ # the initial HTML, so refresh the page to ensure they get updated.
+ #
+ return antinode.refresh_response()
+
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index 755a45ed..582446f9 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -181,6 +181,7 @@ TEMPLATES = [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'hi.context_processors.constants_context',
+ 'hi.apps.config.context_processors.settings_context',
],
},
},
@@ -285,10 +286,11 @@ PIPELINE = {
'js_after_content_custom': {
'source_filenames': (
'js/main.js',
- 'js/sound.js',
+ 'js/settings.js',
+ 'js/audio.js',
'js/svg-utils.js',
'js/watchdog.js',
- 'js/polling.js',
+ 'js/status.js',
'js/edit.js',
'js/edit-dragdrop.js',
'js/svg-icon.js',
diff --git a/src/hi/static/audio/bicycle-bell.wav b/src/hi/static/audio/bicycle-bell.wav
new file mode 100644
index 00000000..b110a388
Binary files /dev/null and b/src/hi/static/audio/bicycle-bell.wav differ
diff --git a/src/hi/static/audio/boing-spring.wav b/src/hi/static/audio/boing-spring.wav
new file mode 100644
index 00000000..b04b59d0
Binary files /dev/null and b/src/hi/static/audio/boing-spring.wav differ
diff --git a/src/hi/static/audio/buzzer.wav b/src/hi/static/audio/buzzer.wav
new file mode 100644
index 00000000..6bc8b181
Binary files /dev/null and b/src/hi/static/audio/buzzer.wav differ
diff --git a/src/hi/static/audio/chime.wav b/src/hi/static/audio/chime.wav
new file mode 100644
index 00000000..53cb1a69
Binary files /dev/null and b/src/hi/static/audio/chime.wav differ
diff --git a/src/hi/static/audio/critical.wav b/src/hi/static/audio/critical.wav
new file mode 100644
index 00000000..df5ad2d3
Binary files /dev/null and b/src/hi/static/audio/critical.wav differ
diff --git a/src/hi/static/audio/final-reveal-bell.wav b/src/hi/static/audio/final-reveal-bell.wav
new file mode 100644
index 00000000..313148fd
Binary files /dev/null and b/src/hi/static/audio/final-reveal-bell.wav differ
diff --git a/src/hi/static/audio/industrial-alarm.wav b/src/hi/static/audio/industrial-alarm.wav
new file mode 100644
index 00000000..512bfaf4
Binary files /dev/null and b/src/hi/static/audio/industrial-alarm.wav differ
diff --git a/src/hi/static/audio/info.wav b/src/hi/static/audio/info.wav
new file mode 100644
index 00000000..871652bc
Binary files /dev/null and b/src/hi/static/audio/info.wav differ
diff --git a/src/hi/static/audio/store-door-chime.wav b/src/hi/static/audio/store-door-chime.wav
new file mode 100644
index 00000000..995e3c32
Binary files /dev/null and b/src/hi/static/audio/store-door-chime.wav differ
diff --git a/src/hi/static/audio/tornado-siren.wav b/src/hi/static/audio/tornado-siren.wav
new file mode 100644
index 00000000..29204e54
Binary files /dev/null and b/src/hi/static/audio/tornado-siren.wav differ
diff --git a/src/hi/static/audio/warning.wav b/src/hi/static/audio/warning.wav
new file mode 100644
index 00000000..7af34c37
Binary files /dev/null and b/src/hi/static/audio/warning.wav differ
diff --git a/src/hi/static/audio/weather-alert.wav b/src/hi/static/audio/weather-alert.wav
new file mode 100644
index 00000000..af6e04ae
Binary files /dev/null and b/src/hi/static/audio/weather-alert.wav differ
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index 44d1a57a..e9389c90 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -187,7 +187,7 @@ a.underline:visited {
left: 50%;
transform: translate(-50%, -50%);
padding: 1rem;
- z-index: 200;
+ z-index: 999;
text-align: center;
font-size: 2rem;
font-weight: bold;
diff --git a/src/hi/static/js/audio.js b/src/hi/static/js/audio.js
new file mode 100644
index 00000000..d42e7c6c
--- /dev/null
+++ b/src/hi/static/js/audio.js
@@ -0,0 +1,133 @@
+(function() {
+ window.Hi = window.Hi || {};
+
+ const HiAudio = {
+
+ WARNING_SIGNAL_NAME: 'warning',
+ INFO_SIGNAL_NAME: 'info',
+
+ init: function() {
+ startAudioPolling();
+ },
+ startAudibleSignal: function( signalName ) {
+ _startAudibleSignal( signalName );
+ },
+ };
+
+ window.Hi.audio = HiAudio;
+
+ window.addEventListener('load', function() {
+ HiAudio.init();
+ });
+
+ const AudioPollingWatchdogType = 'audioPolling';
+ const AudioPollingStartDelayMs = 5 * 1000;
+ const AudioPollingIntervalMs = 3 * 60 * 1000;
+
+ let gAudioPollingTimer = null;
+ let gCurrentMaxSignalName = null;
+
+ function startAudioPolling() {
+ Hi.watchdog.add( AudioPollingWatchdogType,
+ checkAudioStatus,
+ AudioPollingIntervalMs );
+ gAudioPollingTimer = setTimeout( checkAudioStatus, AudioPollingStartDelayMs );
+ }
+
+ function setAudioPollingTimer() {
+ clearAudioPollingTimer();
+ gAudioPollingTimer = setTimeout( checkAudioStatus, AudioPollingIntervalMs );
+ }
+
+ function clearAudioPollingTimer() {
+ if ( gAudioPollingTimer ) {
+ clearTimeout( gAudioPollingTimer );
+ gAudioPollingTimer = null;
+ }
+ }
+
+ function checkAudioStatus() {
+ clearAudioPollingTimer();
+ try {
+ Hi.watchdog.ok( AudioPollingWatchdogType );
+
+ if ( gCurrentMaxSignalName ) {
+ if ( Hi.DEBUG ) { console.log( "Audio max signal found." ); }
+ _startAudibleSignal( gCurrentMaxSignalName );
+ }
+ } catch (e) {
+ console.error( `Exception in audio polling: ${e} (line=${e.lineNumber})` );
+ } finally {
+ setAudioPollingTimer();
+ }
+ }
+
+ const SignalAudioIdPrefix = 'hi-audio-signal';
+ const AudibleSignalDurationMs = 5 * 1000;
+
+ let gAudibleSignalTimer = null;
+ let gActiveAudibleSignalName = null;
+
+ function setAudibleSignalTimer( ) {
+ clearAudibleSignalTimer();
+ gAudibleSignalTimer = setTimeout( endAudibleSignal, AudibleSignalDurationMs );
+ }
+
+ function clearAudibleSignalTimer( ) {
+ if ( gAudibleSignalTimer ) {
+ clearTimeout( gAudibleSignalTimer );
+ gAudibleSignalTimer = null;
+ }
+ }
+
+ function getAudioElementId( signalName ) {
+ return `${SignalAudioIdPrefix}-${signalName}`;
+ }
+
+ function _startAudibleSignal( signalName ) {
+ if ( Hi.DEBUG ) { console.log( `Starting audio signal = ${signalName}` ); }
+ try {
+ stopAudio( );
+ clearAudibleSignalTimer();
+ if ( ! Hi.settings.isAudioEnabled() ) {
+ return;
+ }
+ let id = getAudioElementId( signalName );
+ let elem = document.getElementById(id);
+ if ( ! elem ) {
+ if ( Hi.DEBUG ) { console.log( `Missing audio tag for ${signalName}` ); }
+ return;
+ }
+ else {
+ elem.currentTime = 0;
+ elem.play();
+ gActiveAudibleSignalName = signalName;
+ setAudibleSignalTimer();
+ }
+ }
+ catch (e) {
+ console.error( `Exception starting audible signal: ${e} (line=${e.lineNumber})` );
+ }
+ }
+
+ function endAudibleSignal( ) {
+ stopAudio();
+ clearAudibleSignalTimer();
+
+ // Always "reset" this so we do not signal too frequently
+ setAudioPollingTimer();
+ }
+
+ function stopAudio( ) {
+ if ( ! gActiveAudibleSignalName ) {
+ return;
+ }
+ let id = getAudioElementId( gActiveAudibleSignalName );
+ let elem = document.getElementById(id);
+ if ( elem ) {
+ elem.pause();
+ }
+ gActiveAudibleSignalName = null;
+ }
+
+})();
diff --git a/src/hi/static/js/settings.js b/src/hi/static/js/settings.js
new file mode 100644
index 00000000..157c8c69
--- /dev/null
+++ b/src/hi/static/js/settings.js
@@ -0,0 +1,52 @@
+(function() {
+
+ window.Hi = window.Hi || {};
+
+ const HiSettings = {
+ enableAudio: function() {
+ _enableAudio( );
+ },
+ disableAudio: function() {
+ _disableAudio( );
+ },
+ isAudioEnabled: function() {
+ _isAudioEnabled( );
+ }
+ };
+
+ window.Hi.settings = HiSettings;
+
+ /*
+ SETTINGS
+
+ - Adjustable settings relevant for the console.
+ */
+
+ const AudioStateSettingName = 'audioState';
+ const AudioStateEnabled = 'enabled';
+ const AudioStateDisabled = 'disabled';
+
+ function setConsoleSetting( name, value ) {
+ $.cookie( name, value, { path: '/' } );
+ }
+
+ function getConsoleSetting( name ) {
+ return $.cookie( name );
+ }
+
+ function _enableAudio() {
+ setConsoleSetting( AudioStateSettingName, AudioStateEnabled );
+ }
+
+ function _disableAudio() {
+ setConsoleSetting( AudioStateSettingName, AudioStateDisabled );
+ }
+
+ function _isAudioEnabled() {
+ var audioState = getConsoleSetting( AudioStateSettingName );
+ if ( audioState && ( audioState == AudioStateDisabled ))
+ return false;
+ return true;
+ }
+
+})();
diff --git a/src/hi/static/js/sound.js b/src/hi/static/js/sound.js
deleted file mode 100644
index 45922c8b..00000000
--- a/src/hi/static/js/sound.js
+++ /dev/null
@@ -1,20 +0,0 @@
-(function() {
- window.Hi = window.Hi || {};
-
- const HiSound = {
- startAudibleSignal: function( signalName ) {
- _startAudibleSignal( signalName );
- },
- };
-
- window.Hi.sound = HiSound;
-
- function _startAudibleSignal( signalName ) {
- if ( Hi.DEBUG ) { console.log( `Starting audible signal: ${signalName}` ); }
-
-
- // TBD
-
- }
-
-})();
diff --git a/src/hi/static/js/polling.js b/src/hi/static/js/status.js
similarity index 85%
rename from src/hi/static/js/polling.js
rename to src/hi/static/js/status.js
index c041bb3d..e25f6e42 100644
--- a/src/hi/static/js/polling.js
+++ b/src/hi/static/js/status.js
@@ -1,16 +1,16 @@
(function() {
window.Hi = window.Hi || {};
- const HiPolling = {
+ const HiStatus = {
init: function() {
- startPolling();
+ startServerPolling();
},
};
- window.Hi.polling = HiPolling;
+ window.Hi.status = HiStatus;
window.addEventListener('load', function() {
- HiPolling.init();
+ HiStatus.init();
});
/*
@@ -20,8 +20,9 @@
*/
const ServerPollingWatchdogType = 'serverPolling';
+ const ServerPollingStartDelayMs = 1000;
const ServerPollingIntervalMs = 5 * 1000;
- const PollingErrorNotifyTimeMs = 15 * 1000;
+ const PollingErrorNotifyTimeMs = 60 * 1000;
const ServerErrorMessageSelector = '#hi-server-error-msg';
const ServerPollingUrl = '/api/status';
const ServerStartTimestampAttr = 'startTimestamp';
@@ -29,27 +30,38 @@
const LastServerTimestampParam = 'lastTimestamp';
const CssClassUpdateMap = 'cssClassUpdateMap';
- let gPollingTimer = null;
+ let gServerPollingTimer = null;
let gCssClassElementCache = {};
let gLastServerPollSuccessTime = (new Date()).getTime();
let gIsServerErrorShowing = false;
let gLastStartServerDate = null;
let gLastServerDate = null;
- function startPolling() {
+ function startServerPolling() {
Hi.watchdog.add( ServerPollingWatchdogType,
fetchServerResponse,
ServerPollingIntervalMs );
- fetchServerResponse();
+ gServerPollingTimer = setTimeout( fetchServerResponse, ServerPollingStartDelayMs );
+ }
+
+ function setServerPollingTimer() {
+ gServerPollingTimer = setTimeout( fetchServerResponse, ServerPollingIntervalMs );
+ }
+
+ function clearServerPollingTimer() {
+ if ( gServerPollingTimer ) {
+ clearTimeout( gServerPollingTimer );
+ gServerPollingTimer = null;
+ }
}
function fetchServerResponse() {
if ( Hi.DEBUG ) { console.log( "Polling server..." ); }
- clearPollingTimer();
+ clearServerPollingTimer();
let url = ServerPollingUrl;
if ( gLastServerDate ) {
- const lastTimestampString = gLastServerDate.toISOString();
+ const lastTimestampString = encodeURIComponent( gLastServerDate.toISOString() );
url += `?${LastServerTimestampParam}=${lastTimestampString}`;
}
@@ -66,26 +78,25 @@
Hi.watchdog.ok( ServerPollingWatchdogType );
gLastServerPollSuccessTime = (new Date()).getTime();
handleServerResponse( data, status, xhr );
- return false;
-
+
} catch (e) {
console.error( `Exception parsing server response: ${e} (line=${e.lineNumber})` );
} finally {
- gPollingTimer = setTimeout( fetchServerResponse, ServerPollingIntervalMs );
+ setServerPollingTimer();
}
- },
+ },
error: function (xhr, ajaxOptions, thrownError) {
try {
Hi.watchdog.ok( ServerPollingWatchdogType );
console.error( `Server polling error [${xhr.status}] : ${thrownError}` );
handlePollingError();
- return false;
+
} catch (e) {
console.error( `Exception handling polling error: ${e} (line=${e.lineNumber})` );
} finally {
- gPollingTimer = setTimeout( fetchServerResponse, ServerPollingIntervalMs );
+ setServerPollingTimer();
}
- }
+ }
});
}
@@ -180,13 +191,6 @@
return elements;
}
- function clearPollingTimer() {
- if ( gPollingTimer ) {
- clearTimeout( gPollingTimer );
- gPollingTimer = null;
- }
- }
-
function handlePollingError() {
var nowTime = (new Date()).getTime();
var elapsedMs = nowTime - gLastServerPollSuccessTime;
@@ -203,7 +207,7 @@
}
$(ServerErrorMessageSelector).show();
gIsServerErrorShowing = true;
- Hi.sound.startAudibleSignal( "warning" );
+ Hi.sound.startAudibleSignal( Hi.sound.WARNING_SIGNAL_NAME );
}
function clearServerError() {
@@ -212,7 +216,7 @@
}
$(ServerErrorMessageSelector).hide();
gIsServerErrorShowing = false;
- Hi.sound.startAudibleSignal( "info" );
+ Hi.sound.startAudibleSignal( Hi.sound.INFO_SIGNAL_NAME );
}
})();
diff --git a/src/hi/templates/pages/base.html b/src/hi/templates/pages/base.html
index b1a5f0be..0d842a25 100644
--- a/src/hi/templates/pages/base.html
+++ b/src/hi/templates/pages/base.html
@@ -26,11 +26,11 @@
{% block content %}{% endblock %}
+ {% include "config/panes/console_settings.html" %}
+
<div id="hi-server-error-msg">
WARNING
- <div>
- Server Is Down !
- </div>
+ <div>Server Is Down !</div>
</div>
{% block footer_pre_javascript %}{% endblock %}