Skip to content

Commit

Permalink
Merge pull request #43 from opensrc0/main
Browse files Browse the repository at this point in the history
fix(facedetector, livelocation tracking): default props pass in params instead of using prop-types
  • Loading branch information
opensrc0 committed Jun 14, 2024
2 parents 19799da + dcb42e5 commit 25b3745
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 124 deletions.
8 changes: 8 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ Thanks goes to these wonderful people
</a>
<br />
</td>
<td align="center" valign="top" width="14.28%">
<a target="_blank" href="https://github.com/100beats">
<img src="https://avatars.githubusercontent.com/u/172108056?v=4" width="64px;" alt="100beats" />
<br />
<sub><b>100beats</b></sub>
</a>
<br />
</td>
</tr>
</tbody>
</table>
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ Thanks goes to these wonderful people
</a>
<br />
</td>
<td align="center" valign="top" width="14.28%">
<a target="_blank" href="https://github.com/100beats">
<img src="https://avatars.githubusercontent.com/u/172108056?v=4" width="64px;" alt="100beats" />
<br />
<sub><b>100beats</b></sub>
</a>
<br />
</td>
</tr>
</tbody>
</table>
Expand Down
48 changes: 23 additions & 25 deletions __app/component/FaceDetector/FaceDetector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-inner-declarations */
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { handleError, handleLoading } from '../services/handlerService';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

let mediaStream = null;
Expand All @@ -14,23 +13,24 @@ const failureMsgDefault = {
flashUnsupported: 'Flash is not supporting in your device',
};

const isBrowserSupport = () => navigator?.mediaDevices && globalThis.FaceDetector;

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

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

const stopStreaming = () => {
Expand Down Expand Up @@ -58,6 +58,12 @@ function FaceDetector({

if (getFaces[0]) {
setFaces(getFaces);
handleSuccess({
msgType: 'SUCCESSFUL',
msg: successMsg,
successCb,
data: [...getFaces],
});
// cancelAnimationFrame(videoUnmount);
// stopStreaming();
// clearTimeout(unmoutRenderLoop);
Expand Down Expand Up @@ -159,15 +165,14 @@ function FaceDetector({
};

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

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

return isBrowser && FaceDetector.isBrowserSupport() && (
return isBrowserSupport() && (
<div id="face-detector">
<div id="camera" style={{ position: 'absolute' }} />
{
Expand Down Expand Up @@ -199,9 +204,8 @@ function FaceDetector({
);
}

FaceDetector.isBrowserSupport = () => navigator?.mediaDevices && globalThis.FaceDetector;

FaceDetector.propTypes = {
// showForever: PropTypes.bool,
// successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
Expand All @@ -211,14 +215,8 @@ FaceDetector.propTypes = {
cameraType: PropTypes.oneOf(['back', 'front']),
};

FaceDetector.defaultProps = {
// successCb: () => {},
failureCb: () => {},
loadingCb: () => {},
// successMsg: '',
failureMsg: { ...failureMsgDefault },
zIndex: 9,
cameraType: 'back',
};
const WFaceDetector = Wrapper(FaceDetector, isBrowserSupport);

export { WFaceDetector as FaceDetector };

export default Wrapper(FaceDetector);
export default WFaceDetector;
2 changes: 2 additions & 0 deletions __app/component/FaceDetector/FaceDetectorClose.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ function FaceDetectorClose({
);
}

export { FaceDetectorClose };

export default FaceDetectorClose;
2 changes: 2 additions & 0 deletions __app/component/FaceDetector/FaceDetectorFacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ function FaceDetectorFacing({
);
}

export { FaceDetectorFacing };

export default FaceDetectorFacing;
6 changes: 4 additions & 2 deletions __app/component/FaceDetector/FaceDetectorFlash.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

function FaceDetector({
function FaceDetectorFlash({
toggleFlash,
children,
zIndex,
Expand Down Expand Up @@ -32,4 +32,6 @@ function FaceDetector({
);
}

export default FaceDetector;
export { FaceDetectorFlash };

export default FaceDetectorFlash;
32 changes: 22 additions & 10 deletions __app/component/FaceDetector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ A minimal [Demo Link](https://6jpxdq.csb.app/?component=FaceDetector)

| Value | Used as a | Description|
|--------- | -------- |-----------------|
| <b>FaceDetector</b> | Component :white_check_mark: | Can be used as Component |
| <b>faceDetector<b> | Service :x: | Can't be used as Service |
| <b>FaceDetector</b> | :white_check_mark: Component | Can be used as Component |
| <b>faceDetector<b> | :x: Service | Can be used as Service |

##### 1. Here's an example of basic usage with Multiple Import: with Default Import:
```javascript
Expand Down Expand Up @@ -134,21 +134,33 @@ return (
}
</pre>
</td>
</tr>
<tr>
<td>
showForever
</td>
<td>Boolean</td>
<td>To hide/remove unsupported feature, make it <b>false</b>. Default value is <b>true</b></td>
<td> <pre>---</pre> </td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<th>
Props
</th>
<th>
Type
</th>
<th>
Description
</th>
<th>
Default Values
</th>
<tr>
<td>
showForever
</td>
<td>Boolean</td>
<td>To hide/remove unsupported feature, make it <b>false</b>.</td>
<td>Default value is <b>true.</b></td>
</tr>
</table>

### Child Component
Expand Down
22 changes: 5 additions & 17 deletions __app/component/FaceDetector/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import FaceDetector from './FaceDetector';
import FaceDetectorFlash from './FaceDetectorFlash';
import FaceDetectorClose from './FaceDetectorClose';
import FaceDetectorFacing from './FaceDetectorFacing';
export * from './FaceDetector';
export * from './FaceDetectorClose';
export * from './FaceDetectorFlash';
export * from './FaceDetectorFacing';

export {
FaceDetector,
FaceDetectorFlash,
FaceDetectorClose,
FaceDetectorFacing,
};

export default {
Init: FaceDetector,
Flash: FaceDetectorFlash,
Close: FaceDetectorClose,
Facing: FaceDetectorFacing,
};
export { default } from './FaceDetector';
73 changes: 29 additions & 44 deletions __app/component/LiveLocationTracking/LiveLocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import dependentJsService from '../services/dependentJsService';
import { handleError, handleSuccess, handleLoading } from '../services/handlerService';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
Expand All @@ -16,6 +16,8 @@ const failureMsgDefault = {
error: '',
};

const isBrowserSupport = () => navigator?.geolocation?.watchPosition;

const checkPermitByBrowser = async (failureMsg, failureCb) => {
try {
const permissions = await navigator.permissions.query({ name: 'geolocation' });
Expand Down Expand Up @@ -43,23 +45,23 @@ const checkScriptInBrowser = async (failureMsg, failureCb, isProdKey, googleKey)
};

function LiveLocationTracking({
successCb,
failureCb,
successMsg,
failureMsg: failureMsgProps,
loadingCb,
googleKey,
isProdKey,
destinationLatLng,
mapTypeControl,
panControl,
zoomControl,
scaleControl,
streetViewControl,
overviewMapControl,
rotateControl,
fullscreenControl,
}) {
successCb = () => {},
failureCb = () => {},
loadingCb = () => {},
successMsg = 'Successfully!!',
failureMsg: failureMsgProps = { ...failureMsgDefault },
googleKey = '',
isProdKey = true,
destinationLatLng = { lat: 12.9387901, lng: 77.6407703 },
mapTypeControl = true,
panControl = true,
zoomControl = true,
scaleControl = true,
streetViewControl = true,
overviewMapControl = true,
rotateControl = true,
fullscreenControl = true,
} = {}) {
const directionMapRef = useRef();
let directionsService;
let directionsRenderer;
Expand Down Expand Up @@ -167,8 +169,10 @@ function LiveLocationTracking({
};

const init = async () => {
if (LiveLocationTracking.isBrowserSupport()) {
if (isBrowserSupport()) {
handleLoading({ loadingCb });

// Your Code will start from here
const isPermitByBrowser = await checkPermitByBrowser(failureMsg, failureCb);
const isScriptInBrowser = await checkScriptInBrowser(
failureMsg,
Expand Down Expand Up @@ -203,6 +207,7 @@ function LiveLocationTracking({
// }, 200);
}
};
// Your Code will end here
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}
Expand All @@ -224,9 +229,9 @@ function LiveLocationTracking({
);
}

LiveLocationTracking.isBrowserSupport = () => navigator?.geolocation?.watchPosition;

LiveLocationTracking.propTypes = {
// eslint-disable-next-line react/no-unused-prop-types
showForever: PropTypes.bool,
successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
Expand All @@ -245,28 +250,8 @@ LiveLocationTracking.propTypes = {
fullscreenControl: PropTypes.bool,
};

LiveLocationTracking.defaultProps = {
successCb: () => {},
failureCb: () => {},
loadingCb: () => {},
successMsg: '',
failureMsg: { ...failureMsgDefault },

destinationLatLng: { lat: 12.9387901, lng: 77.6407703 },
isProdKey: true,
googleKey: '',
mapTypeControl: true,
panControl: true,
zoomControl: true,
scaleControl: true,
streetViewControl: true,
overviewMapControl: true,
rotateControl: true,
fullscreenControl: true,
};
const WLiveLocationTracking = Wrapper(LiveLocationTracking, isBrowserSupport);

export default Wrapper(LiveLocationTracking);
export { WLiveLocationTracking as LiveLocationTracking };

// WALKING - bike
// TWO_WHEELER - Walking
// DRIVING - Car
export default WLiveLocationTracking;
Loading

0 comments on commit 25b3745

Please sign in to comment.