Skip to content

Commit

Permalink
Merge branch 'main' into feature_networkConnection
Browse files Browse the repository at this point in the history
Signed-off-by: Himanshu Gupta <opensrc0@gmail.com>
  • Loading branch information
opensrc0 committed May 18, 2024
2 parents bfda0ff + ed56e1d commit 82302b1
Show file tree
Hide file tree
Showing 27 changed files with 588 additions and 504 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"react/jsx-fragments": ["off" ],
"react/jsx-props-no-spreading": ["off"],
"func-names": ["off"],
"no-restricted-exports": ["off"]
"no-restricted-exports": ["off"],
"import/no-named-as-default": 0,
"react/require-default-props": ["off"]
},
"parserOptions": {
"ecmaVersion":"latest"
Expand Down
3 changes: 2 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ import Share from 'fe-pilot/Share';
> 00. :white_check_mark: &nbsp; [FaceDetector](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/FaceDetector/README.md)
> 00. :white_check_mark: &nbsp; [LiveLocation](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LiveLocationTracking/README.md)
> 00. :white_check_mark: &nbsp; [LocateMe](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LocateMe/README.md)
> 00. :white_check_mark: &nbsp; [NetworkConnection](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/NetworkConnection/README.md)
> 00. :white_check_mark: &nbsp; [PhoneBook](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/PhoneBook/README.md)
> 00. :white_check_mark: &nbsp; [Scanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Scanner/README.md)
> 00. :white_check_mark: &nbsp; [Share](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Share/README.md)
> 00. :white_check_mark: &nbsp; [SnapScanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/SnapScanner/README.md)
> 00. :white_check_mark: &nbsp; [TextToSpeech](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/TextToSpeech/README.md)
> 00. :white_check_mark: &nbsp; [VoiceRecognition](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/VoiceRecognition/README.md)
> 00. :white_check_mark: &nbsp; [Vibrate](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Vibrate/README.md)
> 00. :white_check_mark: &nbsp; [WakeLock](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WakeLock/README.md)
> 00. :white_check_mark: &nbsp; [WhatsappShare](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WhatsappShare/README.md)
> 00. :white_check_mark: &nbsp; [NetworkConnection](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/NetworkConnection/README.md)
> </details>
## Online Editor Templates
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ import Share from 'fe-pilot/Share';
4. :white_check_mark: &nbsp; [FaceDetector](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/FaceDetector/README.md)
5. :white_check_mark: &nbsp; [LiveLocation](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LiveLocationTracking/README.md)
6. :white_check_mark: &nbsp; [LocateMe](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/LocateMe/README.md)
7. :white_check_mark: &nbsp; [PhoneBook](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/PhoneBook/README.md)
8. :white_check_mark: &nbsp; [Scanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Scanner/README.md)
9. :white_check_mark: &nbsp; [Share](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Share/README.md)
10. :white_check_mark: &nbsp; [TextToSpeech](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/TextToSpeech/README.md)
11. :white_check_mark: &nbsp; [VoiceRecognition](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/VoiceRecognition/README.md)
12. :white_check_mark: &nbsp; [Vibrate](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Vibrate/README.md)
13. :white_check_mark: &nbsp; [WakeLock](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WakeLock/README.md)
14. :white_check_mark: &nbsp; [WhatsappShare](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WhatsappShare/README.md)
15. :white_check_mark: &nbsp; [NetworkConnection](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/NetworkConnection/README.md)
7. :white_check_mark: &nbsp; [NetworkConnection](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/NetworkConnection/README.md)
8. :white_check_mark: &nbsp; [PhoneBook](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/PhoneBook/README.md)
9. :white_check_mark: &nbsp; [Scanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Scanner/README.md)
10. :white_check_mark: &nbsp; [Share](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Share/README.md)
11. :white_check_mark: &nbsp; [SnapScanner](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/SnapScanner/README.md)
12. :white_check_mark: &nbsp; [TextToSpeech](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/TextToSpeech/README.md)
13. :white_check_mark: &nbsp; [VoiceRecognition](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/VoiceRecognition/README.md)
14. :white_check_mark: &nbsp; [Vibrate](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/Vibrate/README.md)
15. :white_check_mark: &nbsp; [WakeLock](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WakeLock/README.md)
16. :white_check_mark: &nbsp; [WhatsappShare](https://github.com/opensrc0/fe-pilot/blob/main/__app/component/WhatsappShare/README.md)
</details>

## Online Editor Templates
Expand Down
49 changes: 18 additions & 31 deletions __app/component/Scanner/Scanner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-inner-declarations */
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
Expand All @@ -20,22 +19,21 @@ const failureMsgDefault = {
const isBrowserSupport = () => globalThis.navigator?.mediaDevices && globalThis.BarcodeDetector;

function Scanner({
successCb,
failureCb,
loadingCb,
successMsg,
failureMsg: failureMsgProps,
cameraType,
zIndex,
successCb = () => {},
failureCb = () => {},
loadingCb = () => {},
successMsg = 'Scanned successfully',
failureMsg: failureMsgProps = { ...failureMsgDefault },
cameraType = 'back',
zIndex = 9,
children,
}) {
} = {}) {
let list = null;
let video = null;
let facingMode;
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const [flash, setFlash] = useState(false);
const [isBrowser, setIsBrowser] = useState(false);

const stopStreaming = () => {
if (mediaStream) {
Expand Down Expand Up @@ -79,11 +77,11 @@ function Scanner({
};

const createVideo = async (id) => {
document.getElementById('streaming-video')?.remove();
document.getElementById('fe-pilot-video')?.remove();

video = document.createElement('video');

video.id = 'streaming-video';
video.id = 'fe-pilot-video';
video.srcObject = mediaStream;
video.autoplay = true;
video.play();
Expand All @@ -98,7 +96,7 @@ function Scanner({
video.style.objectFit = 'fill';
video.style.transform = 'rotateY(180deg)';
list = document.getElementById(id);
list.before(video);
list.insertBefore(video, list.firstChild);
};

const startStreaming = async () => {
Expand All @@ -119,7 +117,7 @@ function Scanner({
return mediaStream;
};

const startVideo = async (id = 'camera') => {
const startVideo = async (id = 'fe-pilot-scanner') => {
mediaStream = await startStreaming();
createVideo(id);
detectCodes();
Expand Down Expand Up @@ -155,9 +153,8 @@ function Scanner({

const handleBrowserSupport = () => {
if (isBrowserSupport()) {
facingMode = cameraType === 'back' ? 'environment' : 'user';
handleLoading({ loadingCb });

facingMode = cameraType === 'back' ? 'environment' : 'user';
startVideo();
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
Expand All @@ -167,17 +164,15 @@ function Scanner({
};

useEffect(() => {
setIsBrowser(true);
handleBrowserSupport();

return () => {
allClear();
};
}, []);

return isBrowser && isBrowserSupport() && (
<div id="scanner">
<div id="camera" />
return isBrowserSupport() && (
<div id="fe-pilot-scanner">
{
React.Children.map(children, (child) => React.cloneElement(child, {
zIndex,
Expand All @@ -195,6 +190,8 @@ function Scanner({
}

Scanner.propTypes = {
// eslint-disable-next-line react/no-unused-prop-types
showForever: PropTypes.bool,
successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
Expand All @@ -204,18 +201,8 @@ Scanner.propTypes = {
cameraType: PropTypes.oneOf(['back', 'front']),
};

Scanner.defaultProps = {
successCb: () => {},
failureCb: () => {},
loadingCb: () => {},
successMsg: '',
failureMsg: { ...failureMsgDefault },
zIndex: 9,
cameraType: 'back',
};

const WScanner = Wrapper(Scanner, isBrowserSupport);

export { WScanner as Scanner };

export default Scanner;
export default WScanner;
98 changes: 0 additions & 98 deletions __app/component/Scanner/ScannerCamera.js

This file was deleted.

34 changes: 11 additions & 23 deletions __app/component/Scanner/ScannerClose.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react';

function ScannerClose({
onClose,
children,
zIndex,
allClear,
top,
bottom,
left,
right,
color,
position,
zIndex = 9,
color = 'white',
top = 'auto',
bottom = '25%',
left = 'auto',
right = '72%',
position = 'absolute',

onClose = () => {},
children,
}) {
const setClose = () => {
onClose();
Expand All @@ -19,6 +20,7 @@ function ScannerClose({

return (
<div
id="fe-pilot-scanner-close"
style={{
top,
bottom,
Expand All @@ -38,20 +40,6 @@ function ScannerClose({
);
}

ScannerClose.propTypes = {

};

ScannerClose.defaultProps = {
color: 'white',
top: 'auto',
bottom: '25%',
left: 'auto',
right: '72%',
position: 'absolute',
onClose: () => {},
};

export { ScannerClose };

export default ScannerClose;
28 changes: 8 additions & 20 deletions __app/component/Scanner/ScannerFacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import React from 'react';
function ScannerFacing({
toggleCamera,
children,
zIndex,
top,
bottom,
left,
right,
color,
position,
zIndex = 9,
color = 'white',
top = 'auto',
bottom = '25%',
left = 'auto',
right = '37%',
position = 'absolute',
}) {
return (
<div
id="fe-pilot-scanner-facing"
style={{
top,
bottom,
Expand All @@ -32,19 +33,6 @@ function ScannerFacing({
);
}

ScannerFacing.propTypes = {

};

ScannerFacing.defaultProps = {
color: 'white',
top: 'auto',
bottom: '25%',
left: 'auto',
right: '37%',
position: 'absolute',
};

export { ScannerFacing };

export default ScannerFacing;
Loading

0 comments on commit 82302b1

Please sign in to comment.