]> www.vanbest.org Git - motioneye-debian/commitdiff
netcam_keepalive option is now automatically detected from http version
authorCalin Crisan <ccrisan@gmail.com>
Sun, 16 Aug 2015 08:29:07 +0000 (11:29 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 16 Aug 2015 08:29:07 +0000 (11:29 +0300)
src/config.py
src/utils.py
static/js/main.js

index 5c7d91cb7bacd6142785ab4e7cda23e338fe5efb..235d763e920782ff98d9cd274e1243dfa6df0acf 100644 (file)
@@ -507,6 +507,9 @@ def add_camera(device_details):
         if device_details['username']:
             camera_config['netcam_userpass'] = device_details['username'] + ':' + device_details['password']
         
+        camera_config['netcam_keepalive'] = device_details.get('keep_alive')
+        camera_config['netcam_tolerant_check'] = True
+
         if device_details.get('camera_index') == 'udp':
             camera_config['rtsp_uses_tcp'] = False
         
@@ -726,11 +729,6 @@ def motion_camera_ui_to_dict(ui, old_config=None):
                 data['hue'] = max(1, int(round(int(ui['hue']) * 2.55)))
     
     else: # assuming netcam
-        # leave netcam_url unchanged
-        # leave netcam_userpass unchanged
-        data['netcam_keepalive'] = True
-        data['netcam_tolerant_check'] = True
-        
         if data.get('netcam_url', old_config.get('netcam_url', '')).startswith('rtsp'):
             # motion uses the configured width and height for RTSP cameras
             width = int(ui['resolution'].split('x')[0])
index 1a3346d3c59aaf94f51ebb333ddc065473708fbf..a3fe0b8bf9550653402af934e3ac754388efa26f 100644 (file)
@@ -348,6 +348,7 @@ def test_mjpeg_url(data, auth_modes, allow_jpeg, callback):
     
     called = [False]
     status_2xx = [False]
+    http_11 = [False]
 
     def do_request(on_response):
         if data['username']:
@@ -372,19 +373,23 @@ def test_mjpeg_url(data, auth_modes, allow_jpeg, callback):
             called[0] = True
 
             if content_type in ['image/jpg', 'image/jpeg', 'image/pjpg'] and allow_jpeg:
-                callback([{'id': 1, 'name': 'JPEG Network Camera'}])
+                callback([{'id': 1, 'name': 'JPEG Network Camera', 'keep_alive': http_11[0]}])
             
             elif content_type.startswith('multipart/x-mixed-replace'):
-                callback([{'id': 1, 'name': 'MJPEG Network Camera'}])
+                callback([{'id': 1, 'name': 'MJPEG Network Camera', 'keep_alive': http_11[0]}])
             
             else:
                 callback(error='not a supported network camera')
 
         else:
             # check for the status header
-            m = re.match('^http/1.\d (\d+) ', header)
-            if m and int(m.group(1)) / 100 == 2:
-                status_2xx[0] = True
+            m = re.match('^http/1.(\d) (\d+) ', header)
+            if m:
+                if int(m.group(2)) / 100 == 2:
+                    status_2xx[0] = True
+                
+                if m.group(1) == '1':
+                    http_11[0] = True
 
     def on_response(response):
         if not called[0]:
index 72c0399c2dffb7d3f32161ed4797ec2cbc8662c7..569d93fc9cbc1219aa927732dc89467271cb812c 100644 (file)
@@ -2864,7 +2864,18 @@ function runAddCameraDialog() {
             }
 
             data.cameras.forEach(function (info) {
-                addCameraSelect.append('<option value="' + info.id + '">' + info.name + '</option>');
+                var option = $('<option value="' + info.id + '">' + info.name + '</option>');
+                option[0]._extra_attrs = {};
+                Object.keys(info).forEach(function (key) {
+                    if (key == 'id' || key == 'name') {
+                        return;
+                    }
+                    
+                    var value = info[key];
+                    option[0]._extra_attrs[key] = value;
+                });
+
+                addCameraSelect.append(option);
             });
             
             if (!data.cameras || !data.cameras.length) {
@@ -2922,6 +2933,13 @@ function runAddCameraDialog() {
                 data.proto = 'v4l2';
                 data.uri = addCameraSelect.val();
             }
+            
+            /* add all extra attributes */
+            var option = addCameraSelect.find('option:eq(' + addCameraSelect[0].selectedIndex + ')')[0];
+            Object.keys(option._extra_attrs).forEach(function (key) {
+                var value = option._extra_attrs[key];
+                data[key] = value;
+            });
 
             beginProgress();
             ajax('POST', baseUri + 'config/add/', data, function (data) {