From b1b1c1eb9c0ffb53553f964c0f298e5d71076614 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 28 Feb 2015 12:18:02 +0200 Subject: [PATCH] remote camera fixes --- src/handlers.py | 8 ++++---- src/remote.py | 2 +- static/js/main.js | 33 +++++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/handlers.py b/src/handlers.py index 767c6aa..12ebe92 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -211,7 +211,7 @@ class ConfigHandler(BaseHandler): self.finish_json(ui_config) - else: + else: # remote camera def on_response(remote_ui_config=None, error=None): if error: return self.finish_json({'error': 'Failed to get remote camera configuration for %(url)s: %(msg)s.' % { @@ -495,7 +495,7 @@ class ConfigHandler(BaseHandler): else: remote_ui_config['id'] = camera_id - + if not remote_ui_config['enabled'] and local_config['@enabled']: # if a remote camera is disabled, make sure it's disabled locally as well local_config['@enabled'] = False @@ -525,11 +525,11 @@ class ConfigHandler(BaseHandler): check_finished() else: # remote camera - if local_config.get('@enabled'): + if local_config.get('@enabled') or self.get_argument('force', None) == 'true': remote.get_config(local_config, on_response_builder(camera_id, local_config)) else: # don't try to reach the remote of the camera is disabled - on_response_builder(camera_id, local_config)(None) + on_response_builder(camera_id, local_config)(error=True) if length[0] == 0: self.finish_json({'cameras': []}) diff --git a/src/remote.py b/src/remote.py index 836e439..e299029 100644 --- a/src/remote.py +++ b/src/remote.py @@ -33,7 +33,7 @@ def _make_request(host, port, username, password, uri, method='GET', data=None, 'uri': uri or ''} query = dict(query or {}) - query['_username'] = username + query['_username'] = username or '' query['_admin'] = 'true' # always use the admin account if url.count('?'): diff --git a/static/js/main.js b/static/js/main.js index c45a19a..dee8761 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1233,7 +1233,7 @@ function dict2CameraUi(dict) { /* errors while getting the configuration */ $('#videoDeviceSwitch')[0].error = true; - $('#videoDeviceSwitch')[0].checked = false; + $('#videoDeviceSwitch')[0].checked = true; /* so that the user can explicitly disable the camera */ updateConfigUi(); return; @@ -1913,14 +1913,18 @@ function fetchCurrentConfig(onFetch) { var enabledCameras = cameras.filter(function (camera) {return camera['enabled'];}); if (enabledCameras.length > 0) { /* prefer the first enabled camera */ cameraSelect[0].selectedIndex = cameras.indexOf(enabledCameras[0]); - fetchCurrentCameraConfig(); + fetchCurrentCameraConfig(onFetch); } - else if (cameras.length) { /* a disabled camera */ + else if (cameras.length) { /* only disabled cameras */ cameraSelect[0].selectedIndex = 0; - fetchCurrentCameraConfig(); + fetchCurrentCameraConfig(onFetch); } else { /* no camera at all */ cameraSelect[0].selectedIndex = -1; + + if (onFetch) { + onFetch(data); + } } updateConfigUi(); @@ -1930,8 +1934,12 @@ function fetchCurrentConfig(onFetch) { /* normal user with no cameras doesn't make too much sense - force login */ doLogout(); } + + if (onFetch) { + onFetch(data); + } } - + var mainLoadingProgressImg = $('img.main-loading-progress'); if (mainLoadingProgressImg.length) { mainLoadingProgressImg.animate({'opacity': 0}, 200, function () { @@ -1942,10 +1950,6 @@ function fetchCurrentConfig(onFetch) { else { recreateCameraFrames(cameras); } - - if (onFetch) { - onFetch(data); - } }); } @@ -1972,13 +1976,14 @@ function fetchCurrentConfig(onFetch) { function fetchCurrentCameraConfig(onFetch) { var cameraId = $('#cameraSelect').val(); if (cameraId != null) { - ajax('GET', baseUri + 'config/' + cameraId + '/get/', null, function (data) { + ajax('GET', baseUri + 'config/' + cameraId + '/get/?force=true', null, function (data) { if (data == null || data.error) { showErrorMessage(data && data.error); dict2CameraUi(null); if (onFetch) { onFetch(null); } + return; } @@ -1990,6 +1995,9 @@ function fetchCurrentCameraConfig(onFetch) { } else { dict2CameraUi({}); + if (onFetch) { + onFetch({}); + } } } @@ -2337,9 +2345,14 @@ function runAddCameraDialog() { function updateUi() { content.find('tr.motioneye, tr.netcam').css('display', 'none'); + usernameEntry.val(''); + usernameEntry.removeAttr('readonly'); + if (deviceSelect.val() == 'motioneye') { content.find('tr.motioneye').css('display', 'table-row'); addCameraSelect.hide(); + usernameEntry.val('admin'); + usernameEntry.attr('readonly', 'readonly'); } else if (deviceSelect.val() == 'netcam') { content.find('tr.netcam').css('display', 'table-row'); -- 2.39.5