Commit 07f61094 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Improve code to switch cameras in mobiles with more than 2 cameras

parent 8608a1b9
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
}); });
} }
function selectMediaDevice(current_device_id, force_new_device) { function selectMediaDevice(camera_list, current_device_id, force_new_device) {
return getVideoDeviceList() return getVideoDeviceList()
.push(function (info_list) { .push(function (info_list) {
var j, var j,
...@@ -193,12 +193,17 @@ ...@@ -193,12 +193,17 @@
device = info_list[j]; device = info_list[j];
if (device.kind === 'videoinput') { if (device.kind === 'videoinput') {
if ((!current_device_id) || if ((!current_device_id) ||
(camera_list.indexOf(device.deviceId) === -1 &&
(force_new_device && (device.deviceId !== current_device_id)) || (force_new_device && (device.deviceId !== current_device_id)) ||
(!force_new_device && (device.deviceId === current_device_id))) { (!force_new_device && (device.deviceId === current_device_id)))) {
return device.deviceId; return device.deviceId;
} }
} }
} }
if (len > 0) {
return info_list[0].deviceId;
}
throw new Error("no media found"); throw new Error("no media found");
}); });
} }
...@@ -228,7 +233,6 @@ ...@@ -228,7 +233,6 @@
len = gadget.state.page_count, len = gadget.state.page_count,
thumbnail_dom_list = []; thumbnail_dom_list = [];
return gadget.getTranslationList(["Page", "New Page"]) return gadget.getTranslationList(["Page", "New Page"])
.push(function (result_list) { .push(function (result_list) {
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
...@@ -508,20 +512,27 @@ ...@@ -508,20 +512,27 @@
.setState({ .setState({
display_step: 'display_video', display_step: 'display_video',
page: 1, page: 1,
page_count: 0 page_count: 0,
camera_list: []
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
// This method is called during the ERP5 form rendering // This method is called during the ERP5 form rendering
// changeState is used to ensure not resetting the gadget current display // changeState is used to ensure not resetting the gadget current display
// if not needed // if not needed
var gadget = this, var gadget = this,
camera_list = gadget.state.camera_list,
default_value = JSON.parse(options.value); default_value = JSON.parse(options.value);
return selectMediaDevice(gadget.state.device_id, false)
return selectMediaDevice(camera_list, gadget.state.device_id, false)
.push(function (device_id) { .push(function (device_id) {
if (camera_list.indexOf(device_id) === -1) {
camera_list.push(device_id);
}
return gadget.changeState({ return gadget.changeState({
store_new_image_cropped_method: options.store_new_image_cropped_method, store_new_image_cropped_method: options.store_new_image_cropped_method,
active_process: default_value.active_process, active_process: default_value.active_process,
image_list: default_value.image_list, image_list: default_value.image_list,
camera_list: camera_list,
preferred_cropped_canvas_data: JSON.parse(options.preferred_cropped_canvas_data), preferred_cropped_canvas_data: JSON.parse(options.preferred_cropped_canvas_data),
preferred_image_settings_data: JSON.parse(options.preferred_image_settings_data), preferred_image_settings_data: JSON.parse(options.preferred_image_settings_data),
device_id: device_id, device_id: device_id,
...@@ -666,11 +677,18 @@ ...@@ -666,11 +677,18 @@
} }
if (evt.target.className.indexOf("change-camera-btn") !== -1) { if (evt.target.className.indexOf("change-camera-btn") !== -1) {
return selectMediaDevice(gadget.state.device_id, true) return selectMediaDevice(gadget.state.camera_list, gadget.state.device_id, true)
.push(function (device_id) { .push(function (device_id) {
var camera_list = gadget.state.camera_list;
if (camera_list.indexOf(device_id) === -1) {
camera_list.push(device_id);
} else {
camera_list = [device_id];
}
return gadget.changeState({ return gadget.changeState({
display_step: 'display_video', display_step: 'display_video',
preferred_cropped_canvas_data: {}, preferred_cropped_canvas_data: {},
camera_list: camera_list,
device_id: device_id device_id: device_id
}); });
}); });
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>981.62898.35786.34542</string> </value> <value> <string>981.63771.9766.25975</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1582163875.18</float> <float>1582221430.61</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment