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.6 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 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)}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)})}}import React,{useEffect,useRef}from"react";import dependentJsService from"../services/dependentJsService";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";var failureMsgDefault={unSupported:"LiveLocationTracking is not supporting in your device",permissionDenied:"Permission Denied",unableToLocateDirection:"Unable To get Updated Location",browserPermissionAPIFailed:"Unable to check browser permission",unableToLoadGoogleAPI:"Unable to load google api script",locationNotFound:"Unable To get Updated Location",googleAPIKeyMissing:"Unable to check browser permission",error:""},isBrowserSupport=function(){var a;return null===(a=navigator)||void 0===a||null===(a=a.geolocation)||void 0===a?void 0:a.watchPosition},checkPermitByBrowser=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function c(a,b){var d;return _regeneratorRuntime().wrap(function e(c){for(;1;)switch(c.prev=c.next){case 0:return c.prev=0,c.next=3,navigator.permissions.query({name:"geolocation"});case 3:if(d=c.sent,"denied"!==d.state){c.next=6;break}return c.abrupt("return",handleError({msgType:"PERMISSION_DENIED",msg:a.permissionDenied,failureCb:b}));case 6:c.next=11;break;case 8:return c.prev=8,c.t0=c["catch"](0),c.abrupt("return",handleError({msgType:"BROWSER_PERMISION_API_FAILED",msg:a.browserPermissionAPIFailed,failureCb:b}));case 11:return c.abrupt("return",!0);case 12:case"end":return c.stop()}},c,null,[[0,8]])}));return function d(b,c){return a.apply(this,arguments)}}(),checkScriptInBrowser=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function e(a,b,c,d){var f;return _regeneratorRuntime().wrap(function g(e){for(;1;)switch(e.prev=e.next){case 0:if(d){e.next=2;break}return e.abrupt("return",handleError({msgType:"GOOGLE_API_KEY_MISSING",msg:a.googleAPIKeyMissing,failureCb:b}));case 2:return f="https://maps.googleapis.com/maps/api/js?".concat(c?"client":"key","=").concat(d,"&libraries=places&loading=async&callback=scriptCbLLT"),e.prev=3,e.next=6,dependentJsService(f,"googleMapLocationAPI",!0);case 6:return e.abrupt("return",!0);case 9:return e.prev=9,e.t0=e["catch"](3),e.abrupt("return",handleError({msgType:"UNABLE_TO_LOAD_GOOGLE_APIS",msg:a.unableToLoadGoogleAPI,failureCb:b}));case 12:case"end":return e.stop()}},e,null,[[3,9]])}));return function f(b,c,d,e){return a.apply(this,arguments)}}();function LiveLocationTracking(){function a(a,b){var c=document.createElement("button");return c.style.backgroundColor="#709bd5",c.style.border="2px solid #fff",c.style.borderRadius="50px",c.style.boxShadow="0 2px 6px rgba(0,0,0,.3)",c.style.color="#fff",c.style.cursor="pointer",c.style.fontFamily="Roboto,Arial,sans-serif",c.style.fontSize="16px",c.style.lineHeight="38px",c.style.margin="8px",c.style.padding="0 16px",c.style.textAlign="center",c.textContent="Start",c.title="Click to recenter the map",c.type="button",c.addEventListener("click",function(){a.setCenter(b),a.setZoom(19)}),c}var b,c,d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=d.successCb,f=void 0===e?function(){}:e,g=d.failureCb,h=void 0===g?function(){}:g,i=d.loadingCb,j=void 0===i?function(){}:i,k=d.successMsg,l=void 0===k?"Successfully!!":k,m=d.failureMsg,n=void 0===m?_objectSpread({},failureMsgDefault):m,o=d.googleKey,p=void 0===o?"":o,q=d.isProdKey,r=void 0===q||q,s=d.destinationLatLng,t=void 0===s?{lat:12.9387901,lng:77.6407703}:s,u=d.mapTypeControl,v=void 0===u||u,w=d.panControl,x=void 0===w||w,y=d.zoomControl,z=void 0===y||y,A=d.scaleControl,B=void 0===A||A,C=d.streetViewControl,D=void 0===C||C,E=d.overviewMapControl,F=void 0===E||E,G=d.rotateControl,H=void 0===G||G,I=d.fullscreenControl,J=void 0===I||I,K=useRef(),L=null,M=_objectSpread(_objectSpread({},failureMsgDefault),n),N=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function d(a,b,c){var e,f,g;return _regeneratorRuntime().wrap(function h(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,google.maps.importLibrary("marker");case 2:e=d.sent,f=e.AdvancedMarkerElement,g=document.createElement("img"),g.src=c,g.style.transform="scaleX(-1)",new f({map:a,position:{lat:parseFloat(b.lat)-1e-4,lng:b.lng},content:g,title:"A marker using a custom PNG Image"});case 8:case"end":return d.stop()}},d)}));return function e(b,c,d){return a.apply(this,arguments)}}(),O=function(){var b=_asyncToGenerator(_regeneratorRuntime().mark(function d(b){var e,f,g;return _regeneratorRuntime().wrap(function i(d){for(;1;)switch(d.prev=d.next){case 0:d.prev=0,e=new google.maps.Map(K.current,{mapId:"DEMO_MAP_ID",center:b,mapTypeControl:v,panControl:x,zoomControl:z,scaleControl:B,streetViewControl:D,overviewMapControl:F,rotateControl:H,fullscreenControl:J}),f=document.createElement("div"),g=a(e,b),f.appendChild(g),e.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(f),N(e,b,"https://maps.gstatic.com/mapfiles/ms2/micons/motorcycling.png"),N(e,t,"https://maps.gstatic.com/mapfiles/ms2/micons/red-dot.png"),c.setMap(e),d.next=14;break;case 11:return d.prev=11,d.t0=d["catch"](0),d.abrupt("return",handleError({msgType:"UNABLE_TO_CREATE_MAP",msg:M.unableToCreateMap,failureCb:h}));case 14:return d.abrupt("return",!0);case 15:case"end":return d.stop()}},d,null,[[0,11]])}));return function c(a){return b.apply(this,arguments)}}(),P=function d(a){b&&b.route&&b.route.length&&b.route({origin:a,destination:t,travelMode:google.maps.TravelMode.WALKING}).then(function(b){c.setDirections(b),handleSuccess({msgType:"SUCCESSFUL",msg:l,successCb:f,data:a})})["catch"](function(){return handleError({msgType:"UNABLE_TO_LOCATE_DIRECTION",msg:M.unableToLocateDirection,failureCb:h})})},Q=function b(a){a&&(1===a.code&&"User denied Geolocation"===a.message&&handleError({msgType:"PERMISSION_DENIED",msg:M.permissionDenied||"Permission Denied",failureCb:h}),handleError({msgType:"LOCATION_NOT_FOUND",msg:M.locationNotFound,failureCb:h}))},R=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var d,e;return _regeneratorRuntime().wrap(function f(a){for(;1;)switch(a.prev=a.next){case 0:if(!isBrowserSupport()){a.next=11;break}return handleLoading({loadingCb:j}),a.next=4,checkPermitByBrowser(M,h);case 4:return d=a.sent,a.next=7,checkScriptInBrowser(M,h,r,p);case 7:e=a.sent,window.scriptCbLLT=function(){d&&e&&(b=new google.maps.DirectionsService,c=new google.maps.DirectionsRenderer({suppressMarkers:!0,preserveViewport:!0}),navigator.geolocation.getCurrentPosition(function(a){var b=a.coords.latitude,c=a.coords.longitude;O({lat:b,lng:c})}),L=navigator.geolocation.watchPosition(function(a){var b=a.coords.latitude,c=a.coords.longitude;P({lat:b,lng:c})},Q(),{enableHighAccuracy:!0,timeout:3e4,maximumAge:2e3,distanceFilter:100}))},a.next=12;break;case 11:return a.abrupt("return",handleError({msgType:"UN_SUPPORTED_FEATURE",msg:M.unSupported,failureCb:h}));case 12:return a.abrupt("return",!0);case 13:case"end":return a.stop()}},a)}));return function b(){return a.apply(this,arguments)}}();return useEffect(function(){return R(),function(){L&&navigator.geolocation.clearWatch(L)}},[]),React.createElement("div",{ref:K,style:{height:"50vh"}})}var WLiveLocationTracking=Wrapper(LiveLocationTracking,isBrowserSupport);export{WLiveLocationTracking as LiveLocationTracking};export default WLiveLocationTracking;