UNPKG

fe-pilot

Version:

scanner in web, phonebook in web, autofill otp in web, share web, TextToSpeech in web, Voice Recognition in web, live location tracking in web, detect my location web, wakelock in web, color picker, WhatsappShare, SnapScanner, NetworkMonitor, View360

1 lines 15 kB
function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _regeneratorRuntime(){"use strict";function b(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function f(b,d,e,f){var g=d&&d.prototype instanceof k?d:k,h=Object.create(g.prototype),a=new B(f||[]);return E(h,"_invoke",{value:w(b,e,a)}),h}function j(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function k(){}function l(){}function m(){}function q(a){["next","throw","return"].forEach(function(c){b(a,c,function(a){return this._invoke(c,a)})})}function s(b,d){function c(e,f,g,i){var a=j(b[e],b,f);if("throw"!==a.type){var k=a.arg,l=k.value;return l&&"object"==_typeof(l)&&t.call(l,"__await")?d.resolve(l.__await).then(function(a){c("next",a,g,i)},function(a){c("throw",a,g,i)}):d.resolve(l).then(function(a){k.value=a,g(k)},function(a){return c("throw",a,g,i)})}i(a.arg)}var e;E(this,"_invoke",{value:function(a,b){function f(){return new d(function(d,e){c(a,b,d,e)})}return e=e?e.then(f,f):f()}})}function w(a,b,d){var e="suspendedStart";return function(f,g){if(e==="executing")throw Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return{value:D,done:!0}}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=x(h,d);if(i){if(i===G)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"===e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=j(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===G)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function x(b,c){var d=c.method,e=b.iterator[d];if(e===D)return c.delegate=null,"throw"===d&&b.iterator["return"]&&(c.method="return",c.arg=D,x(b,c),"throw"===c.method)||"return"!==d&&(c.method="throw",c.arg=new TypeError("The iterator does not provide a '"+d+"' method")),G;var f=j(e,b.iterator,c.arg);if("throw"===f.type)return c.method="throw",c.arg=f.arg,c.delegate=null,G;var g=f.arg;return g?g.done?(c[b.resultName]=g.value,c.next=b.nextLoc,"return"!==c.method&&(c.method="next",c.arg=D),c.delegate=null,G):g:(c.method="throw",c.arg=new TypeError("iterator result is not an object"),c.delegate=null,G)}function z(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function A(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function B(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(z,this),this.reset(!0)}function C(a){if(a||""===a){var b=a[F];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(t.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=D,b.done=!0,b};return d.next=d}}throw new TypeError(_typeof(a)+" is not iterable")}_regeneratorRuntime=function(){return h};var D,h={},e=Object.prototype,t=e.hasOwnProperty,E=Object.defineProperty||function(a,b,c){a[b]=c.value},n="function"==typeof Symbol?Symbol:{},F=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";try{b({},"")}catch(a){b=function(a,b,c){return a[b]=c}}h.wrap=f;var G={},i={};b(i,F,function(){return this});var o=Object.getPrototypeOf,d=o&&o(o(C([])));d&&d!==e&&t.call(d,F)&&(i=d);var r=m.prototype=k.prototype=Object.create(i);return l.prototype=m,E(r,"constructor",{value:m,configurable:!0}),E(m,"constructor",{value:l,configurable:!0}),l.displayName=b(m,c,"GeneratorFunction"),h.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===l||"GeneratorFunction"===(b.displayName||b.name))},h.mark=function(a){return Object.setPrototypeOf?Object.setPrototypeOf(a,m):(a.__proto__=m,b(a,c,"GeneratorFunction")),a.prototype=Object.create(r),a},h.awrap=function(a){return{__await:a}},q(s.prototype),b(s.prototype,a,function(){return this}),h.AsyncIterator=s,h.async=function(b,c,d,e,g){void 0===g&&(g=Promise);var j=new s(f(b,c,d,e),g);return h.isGeneratorFunction(c)?j:j.next().then(function(a){return a.done?a.value:j.next()})},q(r),b(r,c,"Generator"),b(r,F,function(){return this}),b(r,"toString",function(){return"[object Generator]"}),h.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},h.values=C,B.prototype={constructor:B,reset:function(a){if(this.prev=0,this.next=0,this.sent=this._sent=D,this.done=!1,this.delegate=null,this.method="next",this.arg=D,this.tryEntries.forEach(A),!a)for(var b in this)"t"===b.charAt(0)&&t.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=D)},stop:function(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function(b){function d(a,c){return h.type="throw",h.arg=b,e.next=a,c&&(e.method="next",e.arg=D),!!c}if(this.done)throw b;for(var e=this,f=this.tryEntries.length-1;0<=f;--f){var g=this.tryEntries[f],h=g.completion;if("root"===g.tryLoc)return d("end");if(g.tryLoc<=this.prev){var j=t.call(g,"catchLoc"),k=t.call(g,"finallyLoc");if(j&&k){if(this.prev<g.catchLoc)return d(g.catchLoc,!0);if(this.prev<g.finallyLoc)return d(g.finallyLoc)}else if(!j){if(!k)throw Error("try statement without catch or finally");if(this.prev<g.finallyLoc)return d(g.finallyLoc)}else if(this.prev<g.catchLoc)return d(g.catchLoc,!0)}}},abrupt:function(b,c){for(var d,e=this.tryEntries.length-1;0<=e;--e)if(d=this.tryEntries[e],d.tryLoc<=this.prev&&t.call(d,"finallyLoc")&&this.prev<d.finallyLoc){var f=d;break}f&&("break"===b||"continue"===b)&&f.tryLoc<=c&&c<=f.finallyLoc&&(f=null);var g=f?f.completion:{};return g.type=b,g.arg=c,f?(this.method="next",this.next=f.finallyLoc,G):this.complete(g)},complete:function(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),G},finish:function(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),A(b),G},catch:function(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var f=d.arg;A(b)}return f}throw Error("illegal catch attempt")},delegateYield:function(a,b,c){return this.delegate={iterator:C(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=D),G}},h}function asyncGeneratorStep(b,d,f,e,g,h,a){try{var c=b[h](a),i=c.value}catch(a){return void f(a)}c.done?d(i):Promise.resolve(i).then(e,g)}function _asyncToGenerator(b){return function(){var c=this,d=arguments;return new Promise(function(e,f){function g(a){asyncGeneratorStep(i,e,f,g,h,"next",a)}function h(a){asyncGeneratorStep(i,e,f,g,h,"throw",a)}var i=b.apply(c,d);g(void 0)})}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React,{useEffect,useState}from"react";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";var mediaStream=null,videoUnmount=null,unmoutRenderLoop=null,failureMsgDefault={unSupported:"QR-Code/Bar-Code/UPI Scanner is not supporting in your device",flashUnsupported:"Flash is not supporting in your device",error:""},isBrowserSupport=function(){var a;return(null===(a=globalThis.navigator)||void 0===a?void 0:a.mediaDevices)&&globalThis.BarcodeDetector};function Scanner(){var a,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=b.successCb,d=void 0===c?function(){}:c,e=b.failureCb,f=void 0===e?function(){}:e,g=b.loadingCb,h=void 0===g?function(){}:g,i=b.successMsg,j=void 0===i?"Scanned successfully":i,k=b.failureMsg,l=void 0===k?_objectSpread({},failureMsgDefault):k,m=b.cameraType,n=void 0===m?"back":m,o=b.zIndex,p=void 0===o?9:o,q=b.children,r=null,s=null,t=_objectSpread(_objectSpread({},failureMsgDefault),l),u=useState(!1),v=_slicedToArray(u,2),w=v[0],x=v[1],y=function a(){mediaStream&&mediaStream.getTracks().forEach(function(a){a.stop()})},z=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b,c,e,f,g;return _regeneratorRuntime().wrap(function h(a){for(;1;)switch(a.prev=a.next){case 0:g=function a(){return g=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b;return _regeneratorRuntime().wrap(function f(a){for(;1;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,c.detect(s);case 3:b=a.sent,b.forEach(function(a){e.includes(a.rawValue)||(e.push(a.rawValue),handleSuccess({msgType:"SUCCESSFUL",msg:j,successCb:d,data:{barCodeValue:a.rawValue,barCodeType:a.format}}))}),a.next=9;break;case 7:a.prev=7,a.t0=a["catch"](0);case 9:case"end":return a.stop()}},a,null,[[0,7]])})),g.apply(this,arguments)},f=function a(){return g.apply(this,arguments)},b=globalThis.BarcodeDetector,c=new b,e=[],unmoutRenderLoop=setTimeout(function(){(function a(){videoUnmount=requestAnimationFrame(a),f()})()},1e3);case 6:case"end":return a.stop()}},a)}));return function b(){return a.apply(this,arguments)}}(),A=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function b(a){var c;return _regeneratorRuntime().wrap(function d(b){for(;1;)switch(b.prev=b.next){case 0:null===(c=document.getElementById("streaming-video"))||void 0===c||c.remove(),s=document.createElement("video"),s.id="streaming-video",s.srcObject=mediaStream,s.autoplay=!0,s.play(),s.style.width="100%",s.style.height="100%",s.style.position="absolute",s.style.overflow="hidden",s.style.display="block",s.style.zIndex=p,s.style.top="0",s.style.left="0",s.style.objectFit="fill",s.style.transform="rotateY(180deg)",r=document.getElementById(a),r.before(s);case 18:case"end":return b.stop()}},b)}));return function c(b){return a.apply(this,arguments)}}(),B=function(){var b=_asyncToGenerator(_regeneratorRuntime().mark(function b(){return _regeneratorRuntime().wrap(function c(b){for(;1;)switch(b.prev=b.next){case 0:return b.prev=0,b.next=3,navigator.mediaDevices.getUserMedia({video:{facingMode:a,zoom:!0,resizeMode:!0,focusDistance:!0,focusMode:!0}});case 3:mediaStream=b.sent,b.next=9;break;case 6:return b.prev=6,b.t0=b["catch"](0),b.abrupt("return",handleError({msgType:"ERROR",msg:t.error||(null===b.t0||void 0===b.t0?void 0:b.t0.message)||"Camera streaming failed",failureCb:f}));case 9:return b.abrupt("return",mediaStream);case 10:case"end":return b.stop()}},b,null,[[0,6]])}));return function a(){return b.apply(this,arguments)}}(),C=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b,c=arguments;return _regeneratorRuntime().wrap(function d(a){for(;1;)switch(a.prev=a.next){case 0:return b=0<c.length&&void 0!==c[0]?c[0]:"camera",a.next=3,B();case 3:mediaStream=a.sent,A(b),z();case 6:case"end":return a.stop()}},a)}));return function b(){return a.apply(this,arguments)}}(),D=function a(){cancelAnimationFrame(videoUnmount),y(),clearTimeout(unmoutRenderLoop)},E=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b;return _regeneratorRuntime().wrap(function c(a){for(;1;)switch(a.prev=a.next){case 0:return b=mediaStream.getVideoTracks()[0],a.prev=1,a.next=4,b.applyConstraints({advanced:[{torch:!w}]});case 4:x(function(a){return!a}),a.next=10;break;case 7:return a.prev=7,a.t0=a["catch"](1),a.abrupt("return",handleError({msgType:"FLASH_UPSUPPORTED",msg:t.flashUnsupported,failureCb:f}));case 10:return a.abrupt("return",!0);case 11:case"end":return a.stop()}},a,null,[[1,7]])}));return function b(){return a.apply(this,arguments)}}(),F=function b(){a="user"===a?"environment":"user",y(),cancelAnimationFrame(videoUnmount),clearTimeout(unmoutRenderLoop),C()},G=function b(){if(isBrowserSupport())handleLoading({loadingCb:h}),a="back"===n?"environment":"user",C();else return handleError({msgType:"UN_SUPPORTED_FEATURE",msg:t.unSupported,failureCb:f});return!0};return useEffect(function(){return G(),function(){w&&E(),D()}},[]),isBrowserSupport()&&React.createElement("div",{id:"scanner",style:{background:"#000000b3"}},React.createElement("div",{id:"camera"}),React.Children.map(q,function(a){return React.cloneElement(a,{zIndex:p,allClear:D,toggleCamera:F,toggleFlash:E,successCb:d,successMsg:j,failureCb:f,failureMsg:t})}))}var WScanner=Wrapper(Scanner,isBrowserSupport);export{WScanner as Scanner};export default WScanner;