]> www.vanbest.org Git - motioneye-debian/commitdiff
remote camera fixes
authorCalin Crisan <ccrisan@gmail.com>
Sat, 28 Feb 2015 10:18:02 +0000 (12:18 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 28 Feb 2015 10:18:02 +0000 (12:18 +0200)
src/handlers.py
src/remote.py
static/js/main.js

index 767c6aa5b275985794d734bd4a16a4e6c1198592..12ebe92312ffa842772388bc28329b05c297e165 100644 (file)
@@ -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': []})
index 836e43974258ae3ab9ccdfb62ef8cbd67b245743..e2990298618640c83f5dc80eacd21429332ca14b 100644 (file)
@@ -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('?'):
index c45a19a8c7435c0642c99865b1ba585052b916e0..dee87610814a3bcdaa00e4f8a52e050c764ef6de 100644 (file)
@@ -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');