From 7f4ba007882efb3fea8c934f7637bd424f399cf5 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 16 Aug 2015 11:29:07 +0300 Subject: [PATCH] netcam_keepalive option is now automatically detected from http version --- src/config.py | 8 +++----- src/utils.py | 15 ++++++++++----- static/js/main.js | 20 +++++++++++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/config.py b/src/config.py index 5c7d91c..235d763 100644 --- a/src/config.py +++ b/src/config.py @@ -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]) diff --git a/src/utils.py b/src/utils.py index 1a3346d..a3fe0b8 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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]: diff --git a/static/js/main.js b/static/js/main.js index 72c0399..569d93f 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -2864,7 +2864,18 @@ function runAddCameraDialog() { } data.cameras.forEach(function (info) { - addCameraSelect.append(''); + var 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) { -- 2.39.5