Commit 9a064fec authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: samsung browser randomize the device ID

Try to get the cropper options from previous device ID
parent 82c40e30
Pipeline #11405 failed with stage
in 0 seconds
...@@ -829,7 +829,38 @@ ...@@ -829,7 +829,38 @@
return getPreferredDevice(gadget) return getPreferredDevice(gadget)
.push(function (preferred_device_id) { .push(function (preferred_device_id) {
return selectMediaDevice(camera_list, preferred_device_id, false); return RSVP.all([
selectMediaDevice(camera_list, preferred_device_id, false),
preferred_device_id
]);
})
.push(function (result_list) {
var device_id = result_list[0],
preferred_device_id = result_list[1];
if (device_id !== preferred_device_id) {
// Previous camera used in the same session was not found
// Samsung browser seems to randomize the device ID every time
// it is accessed
// Duplicate previous crop options
return gadget.session_storage_jio.get(CROPPER_DATA_JIO_KEY + preferred_device_id)
.push(function (data) {
return gadget.session_storage_jio.put(
CROPPER_DATA_JIO_KEY + device_id,
data
);
}, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
// If no previous crop data found, nothing to do
return;
}
throw error;
})
.push(function () {
return device_id;
});
}
return device_id;
}) })
.push(function (device_id) { .push(function (device_id) {
if (camera_list.indexOf(device_id) === -1) { if (camera_list.indexOf(device_id) === -1) {
...@@ -851,10 +882,18 @@ ...@@ -851,10 +882,18 @@
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
var gadget = this, var gadget = this,
display_step, display_step,
thumbnail_container; thumbnail_container,
result;
// ALL DOM modifications must be done only in this method // ALL DOM modifications must be done only in this method
// this prevent concurrency issue on DOM access // this prevent concurrency issue on DOM access
// Remember the current device id
if (modification_dict.hasOwnProperty('device_id')) {
result = new RSVP.Queue(putPreferredDevice(gadget, gadget.state.device_id));
} else {
result = new RSVP.Queue();
}
// Only refresh the full gadget content after the first render call // Only refresh the full gadget content after the first render call
// or if the display_step is modified // or if the display_step is modified
// or if displaying another image // or if displaying another image
...@@ -864,26 +903,45 @@ ...@@ -864,26 +903,45 @@
display_step = modification_dict.display_step; display_step = modification_dict.display_step;
} }
if (display_step === 'display_video' || modification_dict.hasOwnProperty('device_id')) { if (display_step === 'display_video' || modification_dict.hasOwnProperty('device_id')) {
return result
.push(function () {
return renderVideoCapture(gadget); return renderVideoCapture(gadget);
});
} }
if (display_step === 'crop_picture') { if (display_step === 'crop_picture') {
return result
.push(function () {
return captureAndRenderPicture(gadget); return captureAndRenderPicture(gadget);
});
} }
if (display_step === 'auto_crop_picture') { if (display_step === 'auto_crop_picture') {
return result
.push(function () {
return captureAndRenderPicture(gadget, true); return captureAndRenderPicture(gadget, true);
});
} }
if (display_step === 'show_picture') { if (display_step === 'show_picture') {
return result
.push(function () {
return renderSubmittedPicture(gadget); return renderSubmittedPicture(gadget);
});
} }
if (display_step) { if (display_step) {
// Ease developper work by raising for not handled cases // Ease developper work by raising for not handled cases
return result
.push(function () {
throw new Error('Unhandled display step: ' + gadget.state.display_step); throw new Error('Unhandled display step: ' + gadget.state.display_step);
});
} }
// Only refresh the thumbnail area // Only refresh the thumbnail area
// if display_step is not modified // if display_step is not modified
return buildPreviousThumbnailDom(gadget) return result
.push(function () {
return buildPreviousThumbnailDom(gadget);
})
.push(function (result) { .push(function (result) {
thumbnail_container = gadget.element.querySelector('.thumbnail-list'); thumbnail_container = gadget.element.querySelector('.thumbnail-list');
thumbnail_container.parentElement.replaceChild( thumbnail_container.parentElement.replaceChild(
...@@ -977,15 +1035,12 @@ ...@@ -977,15 +1035,12 @@
} else { } else {
camera_list = [device_id]; camera_list = [device_id];
} }
return putPreferredDevice(gadget, device_id)
.push(function () {
return gadget.changeState({ return gadget.changeState({
display_step: 'display_video', display_step: 'display_video',
camera_list: camera_list, camera_list: camera_list,
device_id: device_id device_id: device_id
}); });
}); });
});
} }
if (evt.target.className.indexOf("show-img") !== -1) { if (evt.target.className.indexOf("show-img") !== -1) {
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>986.29418.46329.12509</string> </value> <value> <string>986.32279.2119.1979</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>1599470361.92</float> <float>1599642009.31</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