-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Alok30/feature_wakelock
Feature wakelock
- Loading branch information
Showing
2 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,57 @@ | ||
import PropTypes from 'prop-types'; | ||
import { handleError, handleSuccess } from '../services/handlerService'; | ||
|
||
function WakeLock(props = {}) { | ||
const successCb = props.successCb || (() => {}); | ||
const failureCb = props.failureCb || (() => {}); | ||
const successCb = props.successCb || (() => { }); | ||
const failureCb = props.failureCb || (() => { }); | ||
const successMsg = props.successMsg || ''; | ||
const failureMsg = props.failureMsg || {}; | ||
|
||
if (WakeLock.isBrowserSupport()) { | ||
// const abort = new AbortController(); | ||
// abortAutoFill(abort, 3); | ||
// navigator.credentials.get({ | ||
// otp: { transport: ['sms'] }, | ||
// signal: abort.signal, | ||
// }).then((otp) => { | ||
// const { code } = otp; | ||
// handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: code }); | ||
// }).catch((error) => handleError({ msgType: 'ERROR', msg: error, failureCb })); | ||
let wakeLocker = null; | ||
wakeLocker = navigator.wakeLock.request('screen'); | ||
try { | ||
if (wakeLocker) { | ||
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb }); | ||
} else { | ||
return handleError({ | ||
msgType: 'CANCELLED', | ||
failureCb, | ||
}); | ||
} | ||
} catch (error) { | ||
return handleError({ | ||
msgType: 'ERROR', | ||
msg: failureMsg.error || JSON.stringify(error), | ||
failureCb, | ||
}); | ||
} | ||
} else { | ||
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported || 'WakeLock is not supporting in your device', failureCb }); | ||
return handleError({ | ||
msgType: 'UN_SUPPORTED_FEATURE', | ||
msg: | ||
failureMsg.unSupported || 'WakeLock is not supporting in your device', | ||
failureCb, | ||
}); | ||
} | ||
} | ||
|
||
WakeLock.isBrowserSupport = () => 'wakeLock' in navigator; | ||
|
||
WakeLock.propTypes = { | ||
successCb: PropTypes.func, | ||
failureCb: PropTypes.func, | ||
successMsg: PropTypes.string, | ||
failureMsg: PropTypes.object, | ||
}; | ||
|
||
WakeLock.defaultProps = { | ||
successCb: () => { }, | ||
failureCb: () => { }, | ||
successMsg: 'WakeLock successfully!!', | ||
failureMsg: { | ||
unSupported: 'Your browser does not support the WakeLock fetaure', | ||
error: 'Unable to apply WakeLock', | ||
}, | ||
}; | ||
export default WakeLock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters