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 • 13.5 kB
JavaScript
var _excluded=["children","successCb","failureCb","loadingCb","successMsg","failureMsg"];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 _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 _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}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 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";import textToSpeechService from"./textToSpeechService";import TextToSpeechStart from"./TextToSpeechStart";var failureMsgDefault={unSupported:"Text To Speech feature is not supporting in your device",badRequest:"Missing props/params",techError:"Technical error",interrupted:"Interrupted",error:""},isBrowserSupport=function(){var a,b;return(null===globalThis||void 0===globalThis?void 0:globalThis.speechSynthesis)&&(null===globalThis||void 0===globalThis||null===(a=globalThis.speechSynthesis)||void 0===a?void 0:a.cancel)&&(null===globalThis||void 0===globalThis||null===(b=globalThis.speechSynthesis)||void 0===b?void 0:b.speak)},textToSpeechStart=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.successCb,c=void 0===b?function(){}:b,d=a.failureCb,e=void 0===d?function(){}:d,f=a.loadingCb,g=void 0===f?function(){}:f,h=a.setIsAudioOn,i=void 0===h?function(){}:h,j=a.successMsg,k=void 0===j?"Converted text to voice Successfully!!":j,l=a.failureMsg,m=void 0===l?_objectSpread({},failureMsgDefault):l,n=a.text,o=_objectSpread(_objectSpread({},failureMsgDefault),m),p=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b;return _regeneratorRuntime().wrap(function d(a){for(;1;)switch(a.prev=a.next){case 0:if(!isBrowserSupport()){a.next=20;break}if(!n){a.next=17;break}return handleLoading({loadingCb:g}),i(!0),a.prev=4,a.next=7,textToSpeechService(n);case 7:b=a.sent,b.onend=function(){i(!1),handleSuccess({msgType:"SUCCESSFULFUL",msg:k,successCb:c,data:n})},b.onerror=function(a){return i(!1),"interrupted"===a.error?handleError({msgType:"INTERRUPTED",msg:o.interrupted,failureCb:e}):handleError({msgType:"ERROR",msg:o.error||a.error||"Unable to convert text to voice",failureCb:e})},a.next=15;break;case 12:return a.prev=12,a.t0=a["catch"](4),a.abrupt("return",handleError({msgType:"TECH_ERROR",msg:o.techError,failureCb:e}));case 15:a.next=18;break;case 17:return a.abrupt("return",handleError({msgType:"MISSING_PARAMS",msg:o.badRequest,failureCb:e}));case 18:a.next=21;break;case 20:return a.abrupt("return",handleError({msgType:"UN_SUPPORTED_FEATURE",msg:o.unSupported,failureCb:e}));case 21:return a.abrupt("return",!0);case 22:case"end":return a.stop()}},a,null,[[4,12]])}));return function b(){return a.apply(this,arguments)}}();p()},textToSpeechStop=function b(a){var c=a.setIsAudioOn;globalThis.speechSynthesis.cancel(),c(!1)};function TextToSpeech(a){var b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=_objectWithoutProperties(a,_excluded),i=useState(!1),j=_slicedToArray(i,2),k=j[0],l=j[1];return useEffect(function(){return globalThis.speechSynthesis.cancel(),function(){globalThis.speechSynthesis.cancel()}},[]),React.Children.map(b||React.createElement(TextToSpeechStart,{defaultShow:!0}),function(a){return React.cloneElement("string"==typeof a?React.createElement("span",null,a):a,_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g,textToSpeechStart:textToSpeechStart,textToSpeechStop:textToSpeechStop,setIsAudioOn:l,isAudioOn:k},h))})}var WTextToSpeech=Wrapper(TextToSpeech,isBrowserSupport);export{textToSpeechStart,textToSpeechStop,WTextToSpeech as TextToSpeech};export default WTextToSpeech;