@btsd/aitu-bridge 0.2.9 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,s="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(s){var a=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){s[e]||(s[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),a)})}),window.addEventListener("message",function(e){if(e.origin===a&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var a=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(a).map(function(n){return n.call(null,e)})});var d,l,c,u=function(e){a.push(e)},f=(d={current:0,next:function(){return++this.current}},l={},c={add:function(e,n){var t=null!=n?n:d.next();return l[t]=e,t},resolve:function(e,n,t,o){var i=l[e];i&&(t(o)?i.resolve(n):i.reject(o),l[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&c.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,a){!function(e,n,o){void 0===o&&(o={});var a=r&&r[t],d=s&&s[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):a?r[t].postMessage({reqId:e,method:n,data:o}):d?s[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(c.add({resolve:o,reject:a},n.reqId),e,n)})}),g=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var s=i.add({resolve:o,reject:r});e(s,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var a=r&&r[o],d=s&&s[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):a?r[o].postMessage({reqId:e,method:n,data:t}):d?s[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),p=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),I=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),S=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),M=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),m=e(function(e,n,t){var o=i&&i.shareFile,s=r&&r.shareFile,a="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,a,d):s?r.shareFile.postMessage({reqId:e,text:n,filename:a,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),C=e(function(e,n,t,o){var s=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):s?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u);return{copyToClipboard:M,invoke:f,storage:g,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:p,getQr:w,getSMSCode:v,getUserProfile:function(e){return f(n.getUserProfile,{id:e})},selectContact:b,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:h,closeApplication:y,setTitle:S,share:I,shareImage:m,shareFile:C,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||s)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||s&&"function"==typeof s[e]},sub:u}}();module.exports=d;
1
+ var e;function n(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(e||(e={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,l,c,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},l={},c={add:function(e,n){var t=null!=n?n:d.next();return l[t]=e,t},resolve:function(e,n,t,o){var i=l[e];i&&(t(o)?i.resolve(n):i.reject(o),l[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&c.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(c.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=n(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=n(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=n(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=n(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),y=n(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),S=n(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),h=n(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),C=n(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),I=n(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),M=n(function(e,n,t){var o=i&&i.shareFile,a=r&&r.shareFile,s="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,s,d):a?r.shareFile.postMessage({reqId:e,text:n,filename:s,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),m=n(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=n(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u),A=n(function(e){var n=r&&r.enableScreenCapture;i&&i.enableScreenCapture?i.enableScreenCapture(e):n?r.enableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},u),T=n(function(e){var n=r&&r.disableScreenCapture;i&&i.disableScreenCapture?i.disableScreenCapture(e):n?r.disableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},u);return{version:String("0.2.13"),copyToClipboard:I,invoke:f,storage:p,getMe:function(){return f(e.getMe)},getPhone:function(){return f(e.getPhone)},getContacts:function(){return f(e.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(n){return f(e.getUserProfile,{id:n})},selectContact:b,enableNotifications:function(){return f(e.enableNotifications)},disableNotifications:function(){return f(e.disableNotifications)},openSettings:y,closeApplication:S,setTitle:C,share:h,shareImage:M,shareFile:m,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:function(e){i&&i.setTabActiveHandler||r&&r.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u,enableScreenCapture:A,disableScreenCapture:T}}();module.exports=d;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qCASvB,WAAWK,QAAQ,SAACT,EAASM,GAC3B,IAAML,EAAQT,EAAgBI,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,gBAAOa,gCC3Db,IAAKS,GAAL,SAAKA,GACHA,gBACAA,sBACAA,4BACAA,kCACAA,2CACAA,8CANF,CAAKA,IAAAA,OAuGL,IAAMC,EAAe,SACfC,EAAgB,UAehBC,EAA4B,oBAAXC,QAA2BA,OAAeC,cAC3DC,EAAwB,oBAAXF,QAA2BA,OAAeG,QAAWH,OAAeG,OAAOC,gBACxFC,EAAwB,oBAAXL,QAA2BA,OAAOM,MAAQN,SAAaA,OAAeO,UAAaP,OAAeO,WAAa,IAElI,GAAIF,EAAK,CACP,IAAMG,EAAc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MAAAA,EAAO+E,QAAAA,IACb,oBAAXlE,QAChBkC,QAAQC,IAAI,qBA+BgCT,GAEhD,MAAO,CACLiD,gBAAiBpB,EACjBnB,OAAQP,EACRS,QAASD,EACTuC,MAAO,kBAAM/C,EAAcjC,EAAegF,QAC1CC,SAAU,kBAAMhD,EAAcjC,EAAeiF,WAC7CC,YAAa,kBAAMjD,EAAcjC,EAAekF,cAChDC,OAAQjC,EACRkC,MAAOjC,EACPkC,WAAYjC,EACZkC,eAAgB,SAACC,UAAetD,EAAcjC,EAAesF,eAAgB,CAAEC,GAAAA,KAC/EC,cAAenC,EACfoC,oBA9E0B,kBAAMxD,EAAcjC,EAAeyF,sBA+E7DC,qBA7E2B,kBAAMzD,EAAcjC,EAAe0F,uBA8E9DC,aAAcrC,EACdsC,iBAAkBrC,EAClBsC,SAAUnC,EACVoC,MAAOtC,EACPuC,WAAYnC,EACZoC,UAAW5B,EACX6B,gBAlFsB,SAACC,GACL/F,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAe+F,kBAAoBD,EACT,oBAAX9F,QAChBkC,QAAQC,IAAI,4BA4Ed6D,QAAS/B,EACTgC,YAnDkB,WAClB,IAAMC,EAAShG,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAO+D,QAAQpG,GAAWmG,GAAU7F,IAkDpC+F,SA/Ce,SAAC9H,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA6CnBoD,IAAAA,GAIW2E"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts","../src/promisifyMethod.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["import { version } from '../package.json';\n\nimport promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n version: string;\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCapture';\nconst disableScreenCaptureMethod = 'disableScreenCapture';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = (reqId) => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = (reqId) => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n version: String(version),\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["EInvokeRequest","promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","version","String","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"IAMKA,ECoCL,SAASC,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,E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EACRS,QAASD,EACT2C,MAAO,kBAAMnD,EAAcxD,EAAe2G,QAC1CC,SAAU,kBAAMpD,EAAcxD,EAAe4G,WAC7CC,YAAa,kBAAMrD,EAAcxD,EAAe6G,cAChDC,OAAQrC,EACRsC,MAAOrC,EACPsC,WAAYrC,EACZsC,eAAgB,SAACC,UAAe1D,EAAcxD,EAAeiH,eAAgB,CAAEC,GAAAA,KAC/EC,cAAevC,EACfwC,oBA5F0B,kBAAM5D,EAAcxD,EAAeoH,sBA6F7DC,qBA3F2B,kBAAM7D,EAAcxD,EAAeqH,uBA4F9DC,aAAczC,EACd0C,iBAAkBzC,EAClB0C,SAAUvC,EACVwC,MAAO1C,EACP2C,WAAYvC,EACZwC,UAAWhC,EACXiC,gBAhGsB,SAACC,GACLnG,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAemG,kBAAoBD,EACT,oBAAXlG,QAChBkC,QAAQC,IAAI,4BA0FdiE,oBAtF0B,SAACF,GACTnG,GAAWA,EAAO,qBACtBG,GAAOA,EAAG,oBAGrBF,OAAeqG,sBAAwBH,EACb,oBAAXlG,QAChBkC,QAAQC,IAAI,gCAgFdmE,QAASrC,EACTsC,YAvDkB,WAClB,IAAMC,EAAStG,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOqE,QAAQ1G,GAAWyG,GAAUnG,IAsDpCqG,SAnDe,SAACnI,UACfwB,GAAsC,mBAApBA,EAAQxB,IAC1B2B,GAAOA,EAAI3B,IAA8C,mBAA5B2B,EAAI3B,GAAQoC,aACzCN,GAA8B,mBAAhBA,EAAI9B,IAiDnBmD,IAAAA,EACAiF,oBAAqBhC,EACrBiC,qBAAsBhC,GAIXiC"}
@@ -1,2 +1,2 @@
1
- function e(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),function(...t){return new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,...t)})}}var t;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(t||(t={}));const o="invoke",n="storage",s="undefined"!=typeof window&&window.AndroidBridge,i="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,r="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(r){const e=window.AITU_ORIGIN||"https://aitu.io";[o,n].forEach(t=>{r[t]||(r[t]=(...o)=>window.top.postMessage(JSON.stringify({method:t,payload:o}),e))}),window.addEventListener("message",t=>{if(t.origin===e&&t.data)try{const e=JSON.parse(t.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:e}))}catch(e){}})}const d=(()=>{const d=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",e=>{[...d].map(t=>t.call(null,e))});const a=e=>{d.push(e)},l=function(e,t){const n=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:o,error:s}=e.detail;t&&n.resolve(t,o,e=>!e,s)}}),function(e,t={}){return new Promise((d,a)=>{((e,t,n={})=>{const d=i&&i[o],a=r&&r[o];s&&s[o]?s[o](e,t,JSON.stringify(n)):d?i[o].postMessage({reqId:e,method:t,data:n}):a?r[o](e,t,n):"undefined"!=typeof window&&console.log("--invoke-isUnknown")})(n.add({resolve:d,reject:a},t.reqId),e,t)})}}(0,a),c=function(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s="s"+(null!=n?n:e.next());return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),{setItem:(t,n)=>new Promise((s,i)=>{const r=o.add({resolve:s,reject:i});e(r,"setItem",{keyName:t,keyValue:n})}),getItem:t=>new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,"getItem",{keyName:t})}),clear:()=>new Promise((t,n)=>{const s=o.add({resolve:t,reject:n});e(s,"clear",{})})}}((e,t,o={})=>{const d=i&&i[n],a=r&&r[n];s&&s[n]?s[n](e,t,JSON.stringify(o)):d?i[n].postMessage({reqId:e,method:t,data:o}):a?r[n](e,t,o):"undefined"!=typeof window&&console.log("--storage-isUnknown")},a),g=e(e=>{const t=i&&i.getGeo;s&&s.getGeo?s.getGeo(e):t?i.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},a),p=e(e=>{const t=i&&i.getQr;s&&s.getQr?s.getQr(e):t?i.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},a),f=e(e=>{const t=i&&i.getSMSCode;s&&s.getSMSCode?s.getSMSCode(e):t?i.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},a),w=e(e=>{const t=i&&i.selectContact;s&&s.selectContact?s.selectContact(e):t?i.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},a),u=e(e=>{const t=i&&i.openSettings;s&&s.openSettings?s.openSettings(e):t?i.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},a),b=e(e=>{const t=i&&i.closeApplication;s&&s.closeApplication?s.closeApplication(e):t?i.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},a),h=e((e,t)=>{const o=i&&i.share;s&&s.share?s.share(e,t):o?i.share.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--share-isWeb")},a),y=e((e,t)=>{const o=i&&i.setTitle;s&&s.setTitle?s.setTitle(e,t):o?i.setTitle.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},a),v=e((e,t)=>{const o=i&&i.copyToClipboard;s&&s.copyToClipboard?s.copyToClipboard(e,t):o?i.copyToClipboard.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},a),I=e((e,t,o)=>{const n=s&&s.shareFile,r=i&&i.shareFile,d="image."+o.split(";")[0].split("/")[1],a=o.substr(o.indexOf(",")+1);n?s.shareFile(e,t,d,a):r?i.shareFile.postMessage({reqId:e,text:t,filename:d,base64Data:a}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},a),S=e((e,t,o,n)=>{const r=i&&i.shareFile;s&&s.shareFile?s.shareFile(e,t,o,n):r?i.shareFile.postMessage({reqId:e,text:t,filename:o,base64Data:n}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},a),M=e((e,t)=>{if(!Array.isArray(t)||t.some(e=>e<1||e!==Math.floor(e))||t.reduce((e,t)=>e+t)>1e4)return void console.error("Pattern should be an array of positive integers no longer than 10000ms total");const o=i&&i.vibrate;s&&s.vibrate?s.vibrate(e,JSON.stringify(t)):o?i.vibrate.postMessage({reqId:e,pattern:t}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")},a);return{copyToClipboard:v,invoke:l,storage:c,getMe:()=>l(t.getMe),getPhone:()=>l(t.getPhone),getContacts:()=>l(t.getContacts),getGeo:g,getQr:p,getSMSCode:f,getUserProfile:e=>l(t.getUserProfile,{id:e}),selectContact:w,enableNotifications:()=>l(t.enableNotifications),disableNotifications:()=>l(t.disableNotifications),openSettings:u,closeApplication:b,setTitle:y,share:h,shareImage:I,shareFile:S,setShakeHandler:e=>{s&&s.setShakeHandler||i&&i.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:M,isSupported:()=>{const e=i&&window.webkit.messageHandlers.invoke;return Boolean(s||e||r)},supports:e=>s&&"function"==typeof s[e]||i&&i[e]&&"function"==typeof i[e].postMessage||r&&"function"==typeof r[e],sub:a}})();export default d;
1
+ var e;function t(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),function(...t){return new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,...t)})}}!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(e||(e={}));const o="invoke",n="storage",s="undefined"!=typeof window&&window.AndroidBridge,i="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,r="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(r){const e=window.AITU_ORIGIN||"https://aitu.io";[o,n].forEach(t=>{r[t]||(r[t]=(...o)=>window.top.postMessage(JSON.stringify({method:t,payload:o}),e))}),window.addEventListener("message",t=>{if(t.origin===e&&t.data)try{const e=JSON.parse(t.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:e}))}catch(e){}})}const a=(()=>{const a=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",e=>{[...a].map(t=>t.call(null,e))});const d=e=>{a.push(e)},l=function(e,t){const n=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s=null!=n?n:e.next();return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:o,error:s}=e.detail;t&&n.resolve(t,o,e=>!e,s)}}),function(e,t={}){return new Promise((a,d)=>{((e,t,n={})=>{const a=i&&i[o],d=r&&r[o];s&&s[o]?s[o](e,t,JSON.stringify(n)):a?i[o].postMessage({reqId:e,method:t,data:n}):d?r[o](e,t,n):"undefined"!=typeof window&&console.log("--invoke-isUnknown")})(n.add({resolve:a,reject:d},t.reqId),e,t)})}}(0,d),c=function(e,t){const o=function(){const e={current:0,next(){return++this.current}},t={};return{add(o,n){const s="s"+(null!=n?n:e.next());return t[s]=o,s},resolve(e,o,n,s){const i=t[e];i&&(n(s)?i.resolve(o):i.reject(s),t[e]=null)}}}();return t(e=>{if(e.detail&&"reqId"in e.detail){const{reqId:t,data:n,error:s}=e.detail;t&&o.resolve(t,n,e=>!e,s)}}),{setItem:(t,n)=>new Promise((s,i)=>{const r=o.add({resolve:s,reject:i});e(r,"setItem",{keyName:t,keyValue:n})}),getItem:t=>new Promise((n,s)=>{const i=o.add({resolve:n,reject:s});e(i,"getItem",{keyName:t})}),clear:()=>new Promise((t,n)=>{const s=o.add({resolve:t,reject:n});e(s,"clear",{})})}}((e,t,o={})=>{const a=i&&i[n],d=r&&r[n];s&&s[n]?s[n](e,t,JSON.stringify(o)):a?i[n].postMessage({reqId:e,method:t,data:o}):d?r[n](e,t,o):"undefined"!=typeof window&&console.log("--storage-isUnknown")},d),p=t(e=>{const t=i&&i.getGeo;s&&s.getGeo?s.getGeo(e):t?i.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},d),g=t(e=>{const t=i&&i.getQr;s&&s.getQr?s.getQr(e):t?i.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},d),u=t(e=>{const t=i&&i.getSMSCode;s&&s.getSMSCode?s.getSMSCode(e):t?i.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},d),f=t(e=>{const t=i&&i.selectContact;s&&s.selectContact?s.selectContact(e):t?i.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},d),w=t(e=>{const t=i&&i.openSettings;s&&s.openSettings?s.openSettings(e):t?i.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},d),b=t(e=>{const t=i&&i.closeApplication;s&&s.closeApplication?s.closeApplication(e):t?i.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},d),y=t((e,t)=>{const o=i&&i.share;s&&s.share?s.share(e,t):o?i.share.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--share-isWeb")},d),S=t((e,t)=>{const o=i&&i.setTitle;s&&s.setTitle?s.setTitle(e,t):o?i.setTitle.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},d),h=t((e,t)=>{const o=i&&i.copyToClipboard;s&&s.copyToClipboard?s.copyToClipboard(e,t):o?i.copyToClipboard.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},d),v=t((e,t,o)=>{const n=s&&s.shareFile,r=i&&i.shareFile,a="image."+o.split(";")[0].split("/")[1],d=o.substr(o.indexOf(",")+1);n?s.shareFile(e,t,a,d):r?i.shareFile.postMessage({reqId:e,text:t,filename:a,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},d),C=t((e,t,o,n)=>{const r=i&&i.shareFile;s&&s.shareFile?s.shareFile(e,t,o,n):r?i.shareFile.postMessage({reqId:e,text:t,filename:o,base64Data:n}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},d),I=t((e,t)=>{if(!Array.isArray(t)||t.some(e=>e<1||e!==Math.floor(e))||t.reduce((e,t)=>e+t)>1e4)return void console.error("Pattern should be an array of positive integers no longer than 10000ms total");const o=i&&i.vibrate;s&&s.vibrate?s.vibrate(e,JSON.stringify(t)):o?i.vibrate.postMessage({reqId:e,pattern:t}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")},d),M=t(e=>{const t=i&&i.enableScreenCapture;s&&s.enableScreenCapture?s.enableScreenCapture(e):t?i.enableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},d),m=t(e=>{const t=i&&i.disableScreenCapture;s&&s.disableScreenCapture?s.disableScreenCapture(e):t?i.disableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},d);return{version:String("0.2.13"),copyToClipboard:h,invoke:l,storage:c,getMe:()=>l(e.getMe),getPhone:()=>l(e.getPhone),getContacts:()=>l(e.getContacts),getGeo:p,getQr:g,getSMSCode:u,getUserProfile:t=>l(e.getUserProfile,{id:t}),selectContact:f,enableNotifications:()=>l(e.enableNotifications),disableNotifications:()=>l(e.disableNotifications),openSettings:w,closeApplication:b,setTitle:S,share:y,shareImage:v,shareFile:C,setShakeHandler:e=>{s&&s.setShakeHandler||i&&i.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:e=>{s&&s.setTabActiveHandler||i&&i.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:I,isSupported:()=>{const e=i&&window.webkit.messageHandlers.invoke;return Boolean(s||e||r)},supports:e=>s&&"function"==typeof s[e]||i&&i[e]&&"function"==typeof i[e].postMessage||r&&"function"==typeof r[e],sub:d,enableScreenCapture:M,disableScreenCapture:m}})();export default a;
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","requestResolver","counter","current","next","this","promiseControllers","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","createRequestResolver","event","detail","args","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invoke","invokeId","props","isIos","isWeb","console","log","promisifyInvoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,MAAMC,EAlCR,WAME,MAAMC,EAdC,CACLC,QAAS,EACTC,OACE,QAASC,KAAKF,UAYZG,EAA+D,GAErE,MAAO,CACLC,IAAIC,EAA+BC,GACjC,MACMC,EADiB,MAAZD,EAAmBA,EAAWP,EAAQE,OAGjD,OADAE,EAAmBI,GAAYF,EACxBE,GAGTC,QAAWC,EAAwBC,EAASC,EAAiCC,GA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BA8E9DC,aAAcrC,EACdsC,iBAAkBrC,EAClBsC,SAAUnC,EACVoC,MAAOtC,EACPuC,WAAYnC,EACZoC,UAAW5B,EACX6B,gBAlFuBC,IACLhG,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAegG,kBAAoBD,EACT,oBAAX/F,QAChBmC,QAAQC,IAAI,4BA4Ed6D,QAAS/B,EACTgC,YAnDkB,KAClB,MAAMC,EAASjG,GAAQF,OAAeG,OAAOC,gBAAgB0B,OAC7D,OAAOsE,QAAQrG,GAAWoG,GAAU9F,IAkDpCgG,SA/CgBjI,GACf2B,GAAsC,mBAApBA,EAAQ3B,IAC1B8B,GAAOA,EAAI9B,IAA8C,mBAA5B8B,EAAI9B,GAAQuC,aACzCN,GAA8B,mBAAhBA,EAAIjC,GA6CnBsD,IAAAA,IAIW4E"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/index.ts","../src/promisifyMethod.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["import { version } from '../package.json';\n\nimport promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n version: string;\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCapture';\nconst disableScreenCaptureMethod = 'disableScreenCapture';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = (reqId) => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = (reqId) => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n version: String(version),\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["EInvokeRequest","promisifyMethod","method","subscribe","requestResolver","counter","current","next","this","promiseControllers","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","createRequestResolver","event","detail","args","Promise","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invoke","invokeId","props","isIos","isWeb","console","log","promisifyInvoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","version","String","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"IAMKA,ECoCL,SAASC,EAAgBC,EAAQC,GAC/B,MAAMC,EAlCR,WAME,MAAMC,EAdC,CACLC,QAAS,EACTC,OACE,QAASC,KAAKF,UAYZG,EAA+D,GAErE,MAAO,CACLC,IAAIC,EAA+BC,GACjC,MACMC,EADiB,MAAZD,EAAmBA,EAAWP,EAAQE,OAGjD,OADAE,EAAmBI,GAAYF,EACxBE,GAGTC,QAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,MAAMC,EAAiBV,EAAmBM,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBT,EAAmBM,GAAS,QAOVM,GAgBxB,OAdAlB,EAAWmB,IACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,CAC3B,MAAMR,MAAEA,EAAFC,KAASA,EAATE,MAAeA,GAAUI,EAAMC,OAEjCR,GACFX,EAAgBU,QAAQC,EAAOC,EAAOE,IAAYA,EAAQA,kBAK7BM,GACjC,WAAWC,QAAQ,CAACX,EAASM,KAC3B,MAAML,EAAQX,EAAgBM,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,EAAOa,KAAUS,ODzDvB,SAAKxB,GACHA,gBACAA,sBACAA,4BACAA,kCACAA,2CACAA,8CANF,C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,EACZwC,UAAWhC,EACXiC,gBAhGuBC,IACLpG,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAeoG,kBAAoBD,EACT,oBAAXnG,QAChBmC,QAAQC,IAAI,4BA0FdiE,oBAtF2BF,IACTpG,GAAWA,EAAO,qBACtBG,GAAOA,EAAG,oBAGrBF,OAAesG,sBAAwBH,EACb,oBAAXnG,QAChBmC,QAAQC,IAAI,gCAgFdmE,QAASrC,EACTsC,YAvDkB,KAClB,MAAMC,EAASvG,GAAQF,OAAeG,OAAOC,gBAAgB0B,OAC7D,OAAO4E,QAAQ3G,GAAW0G,GAAUpG,IAsDpCsG,SAnDgBtI,GACf0B,GAAsC,mBAApBA,EAAQ1B,IAC1B6B,GAAOA,EAAI7B,IAA8C,mBAA5B6B,EAAI7B,GAAQsC,aACzCN,GAA8B,mBAAhBA,EAAIhC,GAiDnBqD,IAAAA,EACAkF,oBAAqBhC,EACrBiC,qBAAsBhC,IAIXiC"}
@@ -1,2 +1,2 @@
1
- function e(e,t){var n,o,i=(n={current:0,next:function(){return++this.current}},o={},{add:function(e,t){var i=null!=t?t:n.next();return o[i]=e,i},resolve:function(e,t,n,i){var r=o[e];r&&(n(i)?r.resolve(t):r.reject(i),o[e]=null)}});return t(function(e){if(e.detail&&"reqId"in e.detail){var t=e.detail,n=t.reqId;n&&i.resolve(n,t.data,function(e){return!e},t.error)}}),function(){var t=arguments;return new Promise(function(n,o){var r=i.add({resolve:n,reject:o});e.apply(void 0,[r].concat([].slice.call(t)))})}}var t;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(t||(t={}));var n="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,s="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(s){var a=window.AITU_ORIGIN||"https://aitu.io";[n,o].forEach(function(e){s[e]||(s[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),a)})}),window.addEventListener("message",function(e){if(e.origin===a&&e.data)try{var t=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:t}))}catch(e){}})}var d=function(){var a=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(a).map(function(t){return t.call(null,e)})});var d,l,c,u=function(e){a.push(e)},f=(d={current:0,next:function(){return++this.current}},l={},c={add:function(e,t){var n=null!=t?t:d.next();return l[n]=e,n},resolve:function(e,t,n,o){var i=l[e];i&&(n(o)?i.resolve(t):i.reject(o),l[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var t=e.detail,n=t.reqId;n&&c.resolve(n,t.data,function(e){return!e},t.error)}}),function(e,t){return void 0===t&&(t={}),new Promise(function(o,a){!function(e,t,o){void 0===o&&(o={});var a=r&&r[n],d=s&&s[n];i&&i[n]?i[n](e,t,JSON.stringify(o)):a?r[n].postMessage({reqId:e,method:t,data:o}):d?s[n](e,t,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(c.add({resolve:o,reject:a},t.reqId),e,t)})}),g=function(e,t){var n,o,i=(n={current:0,next:function(){return++this.current}},o={},{add:function(e,t){var i="s"+(null!=t?t:n.next());return o[i]=e,i},resolve:function(e,t,n,i){var r=o[e];r&&(n(i)?r.resolve(t):r.reject(i),o[e]=null)}});return t(function(e){if(e.detail&&"reqId"in e.detail){var t=e.detail,n=t.reqId;n&&i.resolve(n,t.data,function(e){return!e},t.error)}}),{setItem:function(t,n){return new Promise(function(o,r){var s=i.add({resolve:o,reject:r});e(s,"setItem",{keyName:t,keyValue:n})})},getItem:function(t){return new Promise(function(n,o){var r=i.add({resolve:n,reject:o});e(r,"getItem",{keyName:t})})},clear:function(){return new Promise(function(t,n){var o=i.add({resolve:t,reject:n});e(o,"clear",{})})}}}(function(e,t,n){void 0===n&&(n={});var a=r&&r[o],d=s&&s[o];i&&i[o]?i[o](e,t,JSON.stringify(n)):a?r[o].postMessage({reqId:e,method:t,data:n}):d?s[o](e,t,n):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),p=e(function(e){var t=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):t?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var t=r&&r.getQr;i&&i.getQr?i.getQr(e):t?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var t=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):t?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=e(function(e){var t=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):t?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),h=e(function(e){var t=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):t?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),y=e(function(e){var t=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):t?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),I=e(function(e,t){var n=r&&r.share;i&&i.share?i.share(e,t):n?r.share.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),S=e(function(e,t){var n=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,t):n?r.setTitle.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),M=e(function(e,t){var n=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,t):n?r.copyToClipboard.postMessage({reqId:e,text:t}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),m=e(function(e,t,n){var o=i&&i.shareFile,s=r&&r.shareFile,a="image."+n.split(";")[0].split("/")[1],d=n.substr(n.indexOf(",")+1);o?i.shareFile(e,t,a,d):s?r.shareFile.postMessage({reqId:e,text:t,filename:a,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),C=e(function(e,t,n,o){var s=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,t,n,o):s?r.shareFile.postMessage({reqId:e,text:t,filename:n,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,t){if(!Array.isArray(t)||t.some(function(e){return e<1||e!==Math.floor(e)})||t.reduce(function(e,t){return e+t})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var n=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(t)):n?r.vibrate.postMessage({reqId:e,pattern:t}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u);return{copyToClipboard:M,invoke:f,storage:g,getMe:function(){return f(t.getMe)},getPhone:function(){return f(t.getPhone)},getContacts:function(){return f(t.getContacts)},getGeo:p,getQr:w,getSMSCode:v,getUserProfile:function(e){return f(t.getUserProfile,{id:e})},selectContact:b,enableNotifications:function(){return f(t.enableNotifications)},disableNotifications:function(){return f(t.disableNotifications)},openSettings:h,closeApplication:y,setTitle:S,share:I,shareImage:m,shareFile:C,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||s)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||s&&"function"==typeof s[e]},sub:u}}();export default d;
1
+ var e;function n(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(e||(e={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}var d=function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,l,c,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},l={},c={add:function(e,n){var t=null!=n?n:d.next();return l[t]=e,t},resolve:function(e,n,t,o){var i=l[e];i&&(t(o)?i.resolve(n):i.reject(o),l[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&c.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(c.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=n(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=n(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=n(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=n(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),y=n(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),S=n(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),h=n(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),C=n(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),I=n(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),M=n(function(e,n,t){var o=i&&i.shareFile,a=r&&r.shareFile,s="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,s,d):a?r.shareFile.postMessage({reqId:e,text:n,filename:s,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),m=n(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=n(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u),A=n(function(e){var n=r&&r.enableScreenCapture;i&&i.enableScreenCapture?i.enableScreenCapture(e):n?r.enableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},u),T=n(function(e){var n=r&&r.disableScreenCapture;i&&i.disableScreenCapture?i.disableScreenCapture(e):n?r.disableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},u);return{version:String("0.2.13"),copyToClipboard:I,invoke:f,storage:p,getMe:function(){return f(e.getMe)},getPhone:function(){return f(e.getPhone)},getContacts:function(){return f(e.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(n){return f(e.getUserProfile,{id:n})},selectContact:b,enableNotifications:function(){return f(e.enableNotifications)},disableNotifications:function(){return f(e.disableNotifications)},openSettings:y,closeApplication:S,setTitle:C,share:h,shareImage:M,shareFile:m,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:function(e){i&&i.setTabActiveHandler||r&&r.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u,enableScreenCapture:A,disableScreenCapture:T}}();export default d;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.module.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"AA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qC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AgBgC,OAC7D,OAAO+D,QAAQpG,GAAWmG,GAAU7F,IAkDpC+F,SA/Ce,SAAC9H,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA6CnBoD,IAAAA,GAIW2E"}
1
+ {"version":3,"file":"index.module.js","sources":["../src/index.ts","../src/promisifyMethod.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["import { version } from '../package.json';\n\nimport promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n version: string;\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCapture';\nconst disableScreenCaptureMethod = 'disableScreenCapture';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = (reqId) => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = (reqId) => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n version: String(version),\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["EInvokeRequest","promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","bridge","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","version","String","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"IAMKA,ECoCL,SAASC,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qCASvB,WAAWK,QAAQ,SAACT,EAASM,GAC3B,IAAML,EAAQT,EAAgBI,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,gBAAOa,iCDzDb,SAAKf,GACHA,gBACAA,sBACAA,4BACAA,kCACAA,2CACAA,8CANF,CAAKA,IAAAA,OA2GL,IAAMwB,EAAe,SACfC,EAAgB,UAkBhBC,EAA4B,oBAAXC,QAA2BA,OAAeC,cAC3DC,EAAwB,oBAAXF,QAA2BA,OAAeG,QAAWH,OAAeG,OAAOC,gBACxFC,EAAwB,oBAAXL,QAA2BA,OAAOM,MAAQN,SAAaA,OAAeO,UAAaP,OAAeO,WAAa,IAElI,GAAIF,EAAK,CACP,IAAMG,EAAcR,OAAeS,aAAe,kBAElD,CAACZ,EAAcC,GAAeY,QAAQ,SAACnC,GAChC8B,EAAI9B,KACP8B,EAAI9B,GAAU,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OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOqE,QAAQ1G,GAAWyG,GAAUnG,IAsDpCqG,SAnDe,SAACnI,UACfwB,GAAsC,mBAApBA,EAAQxB,IAC1B2B,GAAOA,EAAI3B,IAA8C,mBAA5B2B,EAAI3B,GAAQoC,aACzCN,GAA8B,mBAAhBA,EAAI9B,IAiDnBmD,IAAAA,EACAiF,oBAAqBhC,EACrBiC,qBAAsBhC,GAIXiC"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).aituBridge=n()}(this,function(){function e(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}var n;!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(n||(n={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,s="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(s){var a=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){s[e]||(s[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),a)})}),window.addEventListener("message",function(e){if(e.origin===a&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}return function(){var a=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(a).map(function(n){return n.call(null,e)})});var d,c,l,u=function(e){a.push(e)},f=(d={current:0,next:function(){return++this.current}},c={},l={add:function(e,n){var t=null!=n?n:d.next();return c[t]=e,t},resolve:function(e,n,t,o){var i=c[e];i&&(t(o)?i.resolve(n):i.reject(o),c[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&l.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,a){!function(e,n,o){void 0===o&&(o={});var a=r&&r[t],d=s&&s[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):a?r[t].postMessage({reqId:e,method:n,data:o}):d?s[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(l.add({resolve:o,reject:a},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var s=i.add({resolve:o,reject:r});e(s,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var a=r&&r[o],d=s&&s[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):a?r[o].postMessage({reqId:e,method:n,data:t}):d?s[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=e(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=e(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=e(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),y=e(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),b=e(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),h=e(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),I=e(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),S=e(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),m=e(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),M=e(function(e,n,t){var o=i&&i.shareFile,s=r&&r.shareFile,a="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,a,d):s?r.shareFile.postMessage({reqId:e,text:n,filename:a,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),C=e(function(e,n,t,o){var s=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):s?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=e(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u);return{copyToClipboard:m,invoke:f,storage:p,getMe:function(){return f(n.getMe)},getPhone:function(){return f(n.getPhone)},getContacts:function(){return f(n.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(e){return f(n.getUserProfile,{id:e})},selectContact:y,enableNotifications:function(){return f(n.enableNotifications)},disableNotifications:function(){return f(n.disableNotifications)},openSettings:b,closeApplication:h,setTitle:S,share:I,shareImage:M,shareFile:C,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||s)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||s&&"function"==typeof s[e]},sub:u}}()});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).aituBridge=n()}(this,function(){var e;function n(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i=null!=n?n:t.next();return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),function(){var n=arguments;return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e.apply(void 0,[r].concat([].slice.call(n)))})}}!function(e){e.getMe="GetMe",e.getPhone="GetPhone",e.getContacts="GetContacts",e.getUserProfile="GetUserProfile",e.enableNotifications="AllowNotifications",e.disableNotifications="DisableNotifications"}(e||(e={}));var t="invoke",o="storage",i="undefined"!=typeof window&&window.AndroidBridge,r="undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers,a="undefined"!=typeof window&&window.top!==window&&(window.WebBridge=window.WebBridge||{});if(a){var s=window.AITU_ORIGIN||"https://aitu.io";[t,o].forEach(function(e){a[e]||(a[e]=function(){return window.top.postMessage(JSON.stringify({method:e,payload:[].slice.call(arguments)}),s)})}),window.addEventListener("message",function(e){if(e.origin===s&&e.data)try{var n=JSON.parse(e.data);window.dispatchEvent(new CustomEvent("aituEvents",{detail:n}))}catch(e){}})}return function(){var s=[];"undefined"!=typeof window&&window.addEventListener("aituEvents",function(e){[].concat(s).map(function(n){return n.call(null,e)})});var d,c,l,u=function(e){s.push(e)},f=(d={current:0,next:function(){return++this.current}},c={},l={add:function(e,n){var t=null!=n?n:d.next();return c[t]=e,t},resolve:function(e,n,t,o){var i=c[e];i&&(t(o)?i.resolve(n):i.reject(o),c[e]=null)}},u(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&l.resolve(t,n.data,function(e){return!e},n.error)}}),function(e,n){return void 0===n&&(n={}),new Promise(function(o,s){!function(e,n,o){void 0===o&&(o={});var s=r&&r[t],d=a&&a[t];i&&i[t]?i[t](e,n,JSON.stringify(o)):s?r[t].postMessage({reqId:e,method:n,data:o}):d?a[t](e,n,o):"undefined"!=typeof window&&console.log("--invoke-isUnknown")}(l.add({resolve:o,reject:s},n.reqId),e,n)})}),p=function(e,n){var t,o,i=(t={current:0,next:function(){return++this.current}},o={},{add:function(e,n){var i="s"+(null!=n?n:t.next());return o[i]=e,i},resolve:function(e,n,t,i){var r=o[e];r&&(t(i)?r.resolve(n):r.reject(i),o[e]=null)}});return n(function(e){if(e.detail&&"reqId"in e.detail){var n=e.detail,t=n.reqId;t&&i.resolve(t,n.data,function(e){return!e},n.error)}}),{setItem:function(n,t){return new Promise(function(o,r){var a=i.add({resolve:o,reject:r});e(a,"setItem",{keyName:n,keyValue:t})})},getItem:function(n){return new Promise(function(t,o){var r=i.add({resolve:t,reject:o});e(r,"getItem",{keyName:n})})},clear:function(){return new Promise(function(n,t){var o=i.add({resolve:n,reject:t});e(o,"clear",{})})}}}(function(e,n,t){void 0===t&&(t={});var s=r&&r[o],d=a&&a[o];i&&i[o]?i[o](e,n,JSON.stringify(t)):s?r[o].postMessage({reqId:e,method:n,data:t}):d?a[o](e,n,t):"undefined"!=typeof window&&console.log("--storage-isUnknown")},u),g=n(function(e){var n=r&&r.getGeo;i&&i.getGeo?i.getGeo(e):n?r.getGeo.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getGeo-isWeb")},u),w=n(function(e){var n=r&&r.getQr;i&&i.getQr?i.getQr(e):n?r.getQr.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getQr-isWeb")},u),v=n(function(e){var n=r&&r.getSMSCode;i&&i.getSMSCode?i.getSMSCode(e):n?r.getSMSCode.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--getSMSCode-isWeb")},u),b=n(function(e){var n=r&&r.selectContact;i&&i.selectContact?i.selectContact(e):n?r.selectContact.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--selectContact-isWeb")},u),y=n(function(e){var n=r&&r.openSettings;i&&i.openSettings?i.openSettings(e):n?r.openSettings.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--openSettings-isWeb")},u),h=n(function(e){var n=r&&r.closeApplication;i&&i.closeApplication?i.closeApplication(e):n?r.closeApplication.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--closeApplication-isWeb")},u),S=n(function(e,n){var t=r&&r.share;i&&i.share?i.share(e,n):t?r.share.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--share-isWeb")},u),C=n(function(e,n){var t=r&&r.setTitle;i&&i.setTitle?i.setTitle(e,n):t?r.setTitle.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--setTitle-isWeb")},u),I=n(function(e,n){var t=r&&r.copyToClipboard;i&&i.copyToClipboard?i.copyToClipboard(e,n):t?r.copyToClipboard.postMessage({reqId:e,text:n}):"undefined"!=typeof window&&console.log("--copyToClipboard-isWeb")},u),M=n(function(e,n,t){var o=i&&i.shareFile,a=r&&r.shareFile,s="image."+t.split(";")[0].split("/")[1],d=t.substr(t.indexOf(",")+1);o?i.shareFile(e,n,s,d):a?r.shareFile.postMessage({reqId:e,text:n,filename:s,base64Data:d}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),m=n(function(e,n,t,o){var a=r&&r.shareFile;i&&i.shareFile?i.shareFile(e,n,t,o):a?r.shareFile.postMessage({reqId:e,text:n,filename:t,base64Data:o}):"undefined"!=typeof window&&console.log("--shareFile-isWeb")},u),q=n(function(e,n){if(!Array.isArray(n)||n.some(function(e){return e<1||e!==Math.floor(e)})||n.reduce(function(e,n){return e+n})>1e4)console.error("Pattern should be an array of positive integers no longer than 10000ms total");else{var t=r&&r.vibrate;i&&i.vibrate?i.vibrate(e,JSON.stringify(n)):t?r.vibrate.postMessage({reqId:e,pattern:n}):"undefined"!=typeof window&&console.log("--vibrate-isWeb")}},u),A=n(function(e){var n=r&&r.enableScreenCapture;i&&i.enableScreenCapture?i.enableScreenCapture(e):n?r.enableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--enableScreenCapture-isWeb")},u),T=n(function(e){var n=r&&r.disableScreenCapture;i&&i.disableScreenCapture?i.disableScreenCapture(e):n?r.disableScreenCapture.postMessage({reqId:e}):"undefined"!=typeof window&&console.log("--disableScreenCapture-isWeb")},u);return{version:String("0.2.13"),copyToClipboard:I,invoke:f,storage:p,getMe:function(){return f(e.getMe)},getPhone:function(){return f(e.getPhone)},getContacts:function(){return f(e.getContacts)},getGeo:g,getQr:w,getSMSCode:v,getUserProfile:function(n){return f(e.getUserProfile,{id:n})},selectContact:b,enableNotifications:function(){return f(e.enableNotifications)},disableNotifications:function(){return f(e.disableNotifications)},openSettings:y,closeApplication:h,setTitle:C,share:S,shareImage:M,shareFile:m,setShakeHandler:function(e){i&&i.setShakeHandler||r&&r.setShakeHandler?window.onAituBridgeShake=e:"undefined"!=typeof window&&console.log("--setShakeHandler-isWeb")},setTabActiveHandler:function(e){i&&i.setTabActiveHandler||r&&r.setTabActiveHandler?window.onAituBridgeTabActive=e:"undefined"!=typeof window&&console.log("--setTabActiveHandler-isWeb")},vibrate:q,isSupported:function(){var e=r&&window.webkit.messageHandlers.invoke;return Boolean(i||e||a)},supports:function(e){return i&&"function"==typeof i[e]||r&&r[e]&&"function"==typeof r[e].postMessage||a&&"function"==typeof a[e]},sub:u,enableScreenCapture:A,disableScreenCapture:T}}()});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/promisifyMethod.ts","../src/index.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","import promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch(e) {}\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n\n return {\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","EInvokeRequest","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"mLA0CA,SAASA,EAAgBC,EAAQC,GAC/B,IA5BMC,EACAC,EA2BAC,GA5BAF,EAdC,CACLG,QAAS,EACTC,gBACE,QAASC,KAAKF,UAYZF,EAA+D,GAE9D,CACLK,aAAIC,EAA+BC,GACjC,IACMC,EADiB,MAAZD,EAAmBA,EAAWR,EAAQI,OAGjD,OADAH,EAAmBQ,GAAYF,EACxBE,GAGTC,iBAAWC,EAAwBC,EAASC,EAAiCC,GAC3E,IAAMC,EAAiBd,EAAmBU,GAEtCI,IACEF,EAAUC,GACZC,EAAeL,QAAQE,GAEvBG,EAAeC,OAAOF,GAGxBb,EAAmBU,GAAS,SAuBlC,OAdAZ,EAAU,SAACkB,GACT,GAAKA,EAAMC,QAIP,UAAWD,EAAMC,OAAQ,OACID,EAAMC,OAA7BP,IAAAA,MAEJA,GACFT,EAAgBQ,QAAQC,IAHXC,KAGwB,SAACE,UAAYA,KAH/BA,qCASvB,WAAWK,QAAQ,SAACT,EAASM,GAC3B,IAAML,EAAQT,EAAgBI,IAAI,CAAEI,QAAAA,EAASM,OAAAA,IAE7ClB,gBAAOa,gCC3Db,IAAKS,GAA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I5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA6CnBmD,IAAAA,GAIW2E"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/index.ts","../src/promisifyMethod.ts","../src/promisifyInvoke.ts","../src/promisifyStorage.ts"],"sourcesContent":["import { version } from '../package.json';\n\nimport promisifyInvoke from './promisifyInvoke';\nimport promisifyStorage from './promisifyStorage';\nimport promisifyMethod from './promisifyMethod';\n\nenum EInvokeRequest {\n getMe = 'GetMe',\n getPhone = 'GetPhone',\n getContacts = 'GetContacts',\n getUserProfile = 'GetUserProfile',\n enableNotifications = 'AllowNotifications',\n disableNotifications = 'DisableNotifications'\n}\n\ntype SetItemType = (keyName: string, keyValue: string) => Promise<void>;\ntype GetItemType = (keyName: string) => Promise<string | null>;\ntype ClearType = () => Promise<void>;\n\ninterface GetPhoneResponse {\n phone: string;\n sign: string;\n}\n\ninterface GetMeResponse {\n name: string;\n lastname: string;\n id: string;\n avatar?: string;\n avatarThumb?: string;\n sign: string;\n}\n\ninterface ResponseObject {\n phone?: string;\n name?: string;\n lastname?: string;\n}\n\ninterface GetGeoResponse {\n latitude: number;\n longitude: number;\n}\n\ninterface GetContactsResponse {\n contacts: Array<{\n first_name: string;\n last_name: string;\n phone: string;\n }>;\n sign: string;\n}\n\ninterface SelectContactResponse {\n phone: string;\n name: string;\n lastname: string;\n}\n\ninterface GetUserProfileResponse {\n name: string;\n lastname?: string;\n phone?: string;\n avatar?: string;\n avatarThumb?: string;\n}\n\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = 'success' | 'failed';\n// todo: remove duplicates\ntype ResponseType = 'success' | 'failed';\n\ntype BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;\n\ninterface BridgeStorage {\n setItem: SetItemType,\n getItem: GetItemType,\n clear: ClearType\n}\n\ninterface AituBridge {\n version: string;\n invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;\n storage: BridgeStorage;\n getMe: () => Promise<GetMeResponse>;\n getPhone: () => Promise<GetPhoneResponse>;\n getContacts: () => Promise<GetContactsResponse>;\n getGeo: () => Promise<GetGeoResponse>;\n selectContact: () => Promise<SelectContactResponse>;\n getQr: () => Promise<string>;\n getSMSCode: () => Promise<string>;\n getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;\n share: (text: string) => Promise<ShareResponse>;\n setTitle: (text: string) => Promise<ResponseType>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\n closeApplication: () => Promise<ResponseType>;\n setShakeHandler: (handler: any) => void;\n setTabActiveHandler: (handler: (tabname: string) => void) => void;\n vibrate: (pattern: number[]) => Promise<VibratePattern>;\n isSupported: () => boolean;\n supports: (method: string) => boolean;\n sub: any;\n enableScreenCapture: () => Promise<{}>;\n disableScreenCapture: () => Promise<{}>;\n}\n\nconst invokeMethod = 'invoke';\nconst storageMethod = 'storage';\nconst getGeoMethod = 'getGeo';\nconst getQrMethod = 'getQr';\nconst getSMSCodeMethod = 'getSMSCode';\nconst selectContactMethod = 'selectContact';\nconst openSettingsMethod = 'openSettings';\nconst closeApplicationMethod = 'closeApplication';\nconst shareMethod = 'share';\nconst setTitleMethod = 'setTitle';\nconst copyToClipboardMethod = 'copyToClipboard';\nconst shareImageMethod = 'shareImage';\nconst shareFileMethod = 'shareFile';\nconst setShakeHandlerMethod = 'setShakeHandler';\nconst vibrateMethod = 'vibrate';\nconst enableScreenCaptureMethod = 'enableScreenCapture';\nconst disableScreenCaptureMethod = 'disableScreenCapture';\nconst setTabActiveHandlerMethod = 'setTabActiveHandler';\n\nconst android = typeof window !== 'undefined' && (window as any).AndroidBridge;\nconst ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;\nconst web = typeof window !== 'undefined' && (window.top !== window) && ((window as any).WebBridge = (window as any).WebBridge || {});\n\nif (web) {\n const aituOrigin = (window as any).AITU_ORIGIN || 'https://aitu.io';\n\n [invokeMethod, storageMethod].forEach((method) => {\n if (!web[method]) {\n web[method] = (...args) => window.top.postMessage(JSON.stringify({\n method,\n payload: args,\n }), aituOrigin);\n }\n });\n\n window.addEventListener('message', (event) => {\n if (event.origin === aituOrigin && event.data) {\n try {\n const detail = JSON.parse(event.data);\n window.dispatchEvent(new CustomEvent('aituEvents', { detail }));\n } catch (e) { }\n }\n });\n}\n\nconst buildBridge = (): AituBridge => {\n const subs = [];\n\n if (typeof window !== 'undefined') {\n window.addEventListener('aituEvents', (e: any) => {\n [...subs].map((fn) => fn.call(null, e));\n })\n }\n\n const invoke = (reqId, method, data = {}) => {\n const isAndroid = android && android[invokeMethod];\n const isIos = ios && ios[invokeMethod];\n const isWeb = web && web[invokeMethod];\n\n if (isAndroid) {\n android[invokeMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[invokeMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[invokeMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--invoke-isUnknown');\n }\n };\n\n const storage = (reqId, method, data = {}) => {\n const isAndroid = android && android[storageMethod];\n const isIos = ios && ios[storageMethod];\n const isWeb = web && web[storageMethod];\n\n if (isAndroid) {\n android[storageMethod](reqId, method, JSON.stringify(data));\n } else if (isIos) {\n ios[storageMethod].postMessage({ reqId, method, data });\n } else if (isWeb) {\n web[storageMethod](reqId, method, data);\n } else if (typeof window !== 'undefined') {\n console.log('--storage-isUnknown');\n }\n }\n\n const getGeo = (reqId) => {\n const isAndroid = android && android[getGeoMethod];\n const isIos = ios && ios[getGeoMethod];\n\n if (isAndroid) {\n android[getGeoMethod](reqId);\n } else if (isIos) {\n ios[getGeoMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getGeo-isWeb');\n }\n }\n\n const getQr = (reqId) => {\n const isAndroid = android && android[getQrMethod];\n const isIos = ios && ios[getQrMethod];\n\n if (isAndroid) {\n android[getQrMethod](reqId);\n } else if (isIos) {\n ios[getQrMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getQr-isWeb');\n }\n }\n\n const getSMSCode = (reqId) => {\n const isAndroid = android && android[getSMSCodeMethod];\n const isIos = ios && ios[getSMSCodeMethod];\n\n if (isAndroid) {\n android[getSMSCodeMethod](reqId);\n } else if (isIos) {\n ios[getSMSCodeMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--getSMSCode-isWeb');\n }\n }\n\n const selectContact = (reqId) => {\n const isAndroid = android && android[selectContactMethod];\n const isIos = ios && ios[selectContactMethod];\n\n if (isAndroid) {\n android[selectContactMethod](reqId);\n } else if (isIos) {\n ios[selectContactMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--selectContact-isWeb');\n }\n }\n\n const openSettings = (reqId) => {\n const isAndroid = android && android[openSettingsMethod];\n const isIos = ios && ios[openSettingsMethod];\n\n if (isAndroid) {\n android[openSettingsMethod](reqId);\n } else if (isIos) {\n ios[openSettingsMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--openSettings-isWeb');\n }\n }\n\n const closeApplication = (reqId) => {\n const isAndroid = android && android[closeApplicationMethod];\n const isIos = ios && ios[closeApplicationMethod];\n\n if (isAndroid) {\n android[closeApplicationMethod](reqId);\n } else if (isIos) {\n ios[closeApplicationMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--closeApplication-isWeb');\n }\n }\n\n const share = (reqId, text) => {\n const isAndroid = android && android[shareMethod];\n const isIos = ios && ios[shareMethod];\n\n if (isAndroid) {\n android[shareMethod](reqId, text);\n } else if (isIos) {\n ios[shareMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--share-isWeb');\n }\n }\n\n const setTitle = (reqId, text) => {\n const isAndroid = android && android[setTitleMethod];\n const isIos = ios && ios[setTitleMethod];\n\n if (isAndroid) {\n android[setTitleMethod](reqId, text);\n } else if (isIos) {\n ios[setTitleMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--setTitle-isWeb');\n }\n }\n\n const copyToClipboard = (reqId, text) => {\n const isAndroid = android && android[copyToClipboardMethod];\n const isIos = ios && ios[copyToClipboardMethod];\n\n if (isAndroid) {\n android[copyToClipboardMethod](reqId, text);\n } else if (isIos) {\n ios[copyToClipboardMethod].postMessage({ reqId, text });\n } else if (typeof window !== 'undefined') {\n console.log('--copyToClipboard-isWeb');\n }\n }\n\n const enableScreenCapture = (reqId) => {\n const isAndroid = android && android[enableScreenCaptureMethod];\n const isIos = ios && ios[enableScreenCaptureMethod];\n\n if (isAndroid) {\n android[enableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[enableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--enableScreenCapture-isWeb');\n }\n }\n\n const disableScreenCapture = (reqId) => {\n const isAndroid = android && android[disableScreenCaptureMethod];\n const isIos = ios && ios[disableScreenCaptureMethod];\n\n if (isAndroid) {\n android[disableScreenCaptureMethod](reqId);\n } else if (isIos) {\n ios[disableScreenCaptureMethod].postMessage({ reqId });\n } else if (typeof window !== 'undefined') {\n console.log('--disableScreenCapture-isWeb');\n }\n }\n\n const shareImage = (reqId, text, image) => {\n // !!!======================!!!\n // !!!===== Deprecated =====!!!\n // !!!======================!!!\n\n // const isAndroid = android && android[shareImageMethod];\n // const isIos = ios && ios[shareImageMethod];\n\n // if (isAndroid) {\n // android[shareImageMethod](reqId, text, image);\n // } else if (isIos) {\n // ios[shareImageMethod].postMessage({ reqId, text, image });\n // } else if (typeof window !== 'undefined') {\n // console.log('--shareImage-isWeb');\n // }\n\n // new one - fallback to shareFile\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n // get extension from base64 mime type and merge with name\n const ext = image.split(';')[0].split('/')[1];\n const filename = 'image.' + ext;\n // remove mime type\n const base64Data = image.substr(image.indexOf(',') + 1);\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const shareFile = (reqId, text, filename, base64Data) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, filename, base64Data);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });\n } else if (typeof window !== 'undefined') {\n console.log('--shareFile-isWeb');\n }\n }\n\n const enableNotifications = () => invokePromise(EInvokeRequest.enableNotifications);\n\n const disableNotifications = () => invokePromise(EInvokeRequest.disableNotifications);\n\n const setShakeHandler = (handler) => {\n const isAndroid = android && android[setShakeHandlerMethod];\n const isIos = ios && ios[setShakeHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeShake = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setShakeHandler-isWeb');\n }\n };\n\n const setTabActiveHandler = (handler: (tabname: string) => void) => {\n const isAndroid = android && android[setTabActiveHandlerMethod];\n const isIos = ios && ios[setTabActiveHandlerMethod];\n\n if (isAndroid || isIos) {\n (window as any).onAituBridgeTabActive = handler;\n } else if (typeof window !== 'undefined') {\n console.log('--setTabActiveHandler-isWeb');\n }\n };\n\n const vibrate = (reqId, pattern) => {\n if (\n !Array.isArray(pattern) ||\n pattern.some((timing) => timing < 1 || timing !== Math.floor(timing)) ||\n pattern.reduce((total, timing) => total + timing) > 10000\n ) {\n console.error('Pattern should be an array of positive integers no longer than 10000ms total');\n return;\n }\n\n const isAndroid = android && android[vibrateMethod];\n const isIos = ios && ios[vibrateMethod];\n\n if (isAndroid) {\n android[vibrateMethod](reqId, JSON.stringify(pattern));\n } else if (isIos) {\n ios[vibrateMethod].postMessage({ reqId, pattern });\n } else if (typeof window !== 'undefined') {\n console.log('--vibrate-isWeb');\n }\n }\n\n const isSupported = () => {\n const iosSup = ios && (window as any).webkit.messageHandlers.invoke;\n return Boolean(android || iosSup || web);\n }\n\n const supports = (method) =>\n (android && typeof android[method] === 'function') ||\n (ios && ios[method] && typeof ios[method].postMessage === 'function') ||\n (web && typeof web[method] === 'function');\n\n const sub = (listener: any) => {\n subs.push(listener);\n }\n\n const invokePromise = promisifyInvoke(invoke, sub);\n const storagePromise = promisifyStorage(storage, sub);\n const getGeoPromise = promisifyMethod(getGeo, sub);\n const getQrPromise = promisifyMethod(getQr, sub);\n const getSMSCodePromise = promisifyMethod(getSMSCode, sub);\n const selectContactPromise = promisifyMethod(selectContact, sub);\n const openSettingsPromise = promisifyMethod(openSettings, sub);\n const closeApplicationPromise = promisifyMethod(closeApplication, sub);\n const sharePromise = promisifyMethod(share, sub);\n const setTitlePromise = promisifyMethod(setTitle, sub);\n const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);\n const shareImagePromise = promisifyMethod(shareImage, sub);\n const shareFilePromise = promisifyMethod(shareFile, sub);\n const vibratePromise = promisifyMethod(vibrate, sub);\n const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);\n const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);\n\n return {\n version: String(version),\n copyToClipboard: copyToClipboardPromise,\n invoke: invokePromise,\n storage: storagePromise,\n getMe: () => invokePromise(EInvokeRequest.getMe),\n getPhone: () => invokePromise(EInvokeRequest.getPhone),\n getContacts: () => invokePromise(EInvokeRequest.getContacts),\n getGeo: getGeoPromise,\n getQr: getQrPromise,\n getSMSCode: getSMSCodePromise,\n getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),\n selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\n closeApplication: closeApplicationPromise,\n setTitle: setTitlePromise,\n share: sharePromise,\n shareImage: shareImagePromise,\n shareFile: shareFilePromise,\n setShakeHandler,\n setTabActiveHandler,\n vibrate: vibratePromise,\n isSupported,\n supports,\n sub,\n enableScreenCapture: enableScreenCapturePromise,\n disableScreenCapture: disableScreenCapturePromise\n }\n}\n\nconst bridge = buildBridge();\n\nexport default bridge;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const methodId = id;\n promiseControllers[methodId] = controller;\n return methodId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyMethod(method, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(...args: any[]): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n\n method(reqId, ...args);\n });\n };\n}\n\nexport default promisifyMethod;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n}\n\nfunction createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n\n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n\n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const invokeId = id;\n promiseControllers[invokeId] = controller;\n return invokeId;\n },\n\n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n\n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n\n promiseControllers[reqId] = null;\n }\n },\n };\n}\n\nfunction promisifyInvoke(invoke, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n\n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n\n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n\n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return function promisifiedFunc(method: any, props: any = {}): Promise<any | void> {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject }, props.reqId);\n\n invoke(reqId, method, props);\n });\n };\n}\n\nexport default promisifyInvoke;\n","function createCounter() {\n return {\n current: 0,\n next() {\n return ++this.current;\n },\n };\n }\n \n function createRequestResolver() {\n type PromiseController = {\n resolve: (value: any) => any;\n reject: (reason: any) => any;\n };\n \n const counter = createCounter();\n const promiseControllers: Record<string, PromiseController | null> = {};\n \n return {\n add(controller: PromiseController, customId?: number | string): number | string {\n const id = customId != null ? customId : counter.next();\n const storageId = `s${id}`;\n promiseControllers[storageId] = controller;\n return storageId;\n },\n \n resolve<T>(reqId: number | string, data: T, isSuccess: (data: T) => boolean, error: any) {\n const requestPromise = promiseControllers[reqId];\n \n if (requestPromise) {\n if (isSuccess(error)) {\n requestPromise.resolve(data);\n } else {\n requestPromise.reject(error);\n }\n \n promiseControllers[reqId] = null;\n }\n },\n };\n }\n \n function promisifyStorage(storage, subscribe: (fn: any) => void) {\n const requestResolver = createRequestResolver();\n \n subscribe((event) => {\n if (!event.detail) {\n return;\n }\n \n if ('reqId' in event.detail) {\n const { reqId, data, error } = event.detail;\n \n if (reqId) {\n requestResolver.resolve(reqId, data, (error) => !(error), error);\n }\n }\n });\n\n return {\n setItem: (keyName: string, keyValue: string): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'setItem', { keyName, keyValue });\n });\n },\n getItem: (keyName: string): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'getItem', { keyName });\n });\n },\n clear: (): Promise<void> => {\n return new Promise((resolve, reject) => {\n const reqId = requestResolver.add({ resolve, reject });\n storage(reqId, 'clear', {});\n });\n },\n }\n }\n \n export default promisifyStorage;\n "],"names":["EInvokeRequest","promisifyMethod","method","subscribe","counter","promiseControllers","requestResolver","current","next","this","add","controller","customId","methodId","resolve","reqId","data","isSuccess","error","requestPromise","reject","event","detail","Promise","invokeMethod","storageMethod","android","window","AndroidBridge","ios","webkit","messageHandlers","web","top","WebBridge","aituOrigin","AITU_ORIGIN","forEach","postMessage","JSON","stringify","payload","addEventListener","origin","parse","dispatchEvent","CustomEvent","e","subs","map","fn","call","sub","listener","push","invokePromise","invokeId","props","isIos","isWeb","console","log","invoke","storagePromise","storage","storageId","setItem","keyName","keyValue","getItem","clear","promisifyStorage","getGeoPromise","getQrPromise","getSMSCodePromise","selectContactPromise","openSettingsPromise","closeApplicationPromise","sharePromise","text","setTitlePromise","copyToClipboardPromise","shareImagePromise","image","isAndroid","filename","split","base64Data","substr","indexOf","shareFilePromise","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","enableScreenCapturePromise","disableScreenCapturePromise","version","String","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","getUserProfile","id","selectContact","enableNotifications","disableNotifications","openSettings","closeApplication","setTitle","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","setTabActiveHandler","onAituBridgeTabActive","vibrate","isSupported","iosSup","Boolean","supports","enableScreenCapture","disableScreenCapture","buildBridge"],"mappings":"uLAMKA,ECoCL,SAASC,EAAgBC,EAAQC,GAC/B,I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AAI3B,GAAQoC,aACzCN,GAA8B,mBAAhBA,EAAI9B,IAiDnBkD,IAAAA,EACAiF,oBAAqBhC,EACrBiC,qBAAsBhC,GAIXiC"}
@@ -61,6 +61,7 @@ interface BridgeStorage {
61
61
  clear: ClearType;
62
62
  }
63
63
  interface AituBridge {
64
+ version: string;
64
65
  invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;
65
66
  storage: BridgeStorage;
66
67
  getMe: () => Promise<GetMeResponse>;
@@ -81,10 +82,13 @@ interface AituBridge {
81
82
  openSettings: () => Promise<OpenSettingsResponse>;
82
83
  closeApplication: () => Promise<ResponseType>;
83
84
  setShakeHandler: (handler: any) => void;
85
+ setTabActiveHandler: (handler: (tabname: string) => void) => void;
84
86
  vibrate: (pattern: number[]) => Promise<VibratePattern>;
85
87
  isSupported: () => boolean;
86
88
  supports: (method: string) => boolean;
87
89
  sub: any;
90
+ enableScreenCapture: () => Promise<{}>;
91
+ disableScreenCapture: () => Promise<{}>;
88
92
  }
89
93
  declare const bridge: AituBridge;
90
94
  export default bridge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btsd/aitu-bridge",
3
- "version": "0.2.9",
3
+ "version": "0.2.13",
4
4
  "description": "",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { version } from '../package.json';
2
+
1
3
  import promisifyInvoke from './promisifyInvoke';
2
4
  import promisifyStorage from './promisifyStorage';
3
5
  import promisifyMethod from './promisifyMethod';
@@ -79,6 +81,7 @@ interface BridgeStorage {
79
81
  }
80
82
 
81
83
  interface AituBridge {
84
+ version: string;
82
85
  invoke: BridgeInvoke<EInvokeRequest, ResponseObject>;
83
86
  storage: BridgeStorage;
84
87
  getMe: () => Promise<GetMeResponse>;
@@ -99,10 +102,13 @@ interface AituBridge {
99
102
  openSettings: () => Promise<OpenSettingsResponse>;
100
103
  closeApplication: () => Promise<ResponseType>;
101
104
  setShakeHandler: (handler: any) => void;
105
+ setTabActiveHandler: (handler: (tabname: string) => void) => void;
102
106
  vibrate: (pattern: number[]) => Promise<VibratePattern>;
103
107
  isSupported: () => boolean;
104
108
  supports: (method: string) => boolean;
105
109
  sub: any;
110
+ enableScreenCapture: () => Promise<{}>;
111
+ disableScreenCapture: () => Promise<{}>;
106
112
  }
107
113
 
108
114
  const invokeMethod = 'invoke';
@@ -120,6 +126,9 @@ const shareImageMethod = 'shareImage';
120
126
  const shareFileMethod = 'shareFile';
121
127
  const setShakeHandlerMethod = 'setShakeHandler';
122
128
  const vibrateMethod = 'vibrate';
129
+ const enableScreenCaptureMethod = 'enableScreenCapture';
130
+ const disableScreenCaptureMethod = 'disableScreenCapture';
131
+ const setTabActiveHandlerMethod = 'setTabActiveHandler';
123
132
 
124
133
  const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
125
134
  const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
@@ -142,7 +151,7 @@ if (web) {
142
151
  try {
143
152
  const detail = JSON.parse(event.data);
144
153
  window.dispatchEvent(new CustomEvent('aituEvents', { detail }));
145
- } catch(e) {}
154
+ } catch (e) { }
146
155
  }
147
156
  });
148
157
  }
@@ -292,7 +301,7 @@ const buildBridge = (): AituBridge => {
292
301
  }
293
302
  }
294
303
 
295
- const copyToClipboard = (reqId, text) => {
304
+ const copyToClipboard = (reqId, text) => {
296
305
  const isAndroid = android && android[copyToClipboardMethod];
297
306
  const isIos = ios && ios[copyToClipboardMethod];
298
307
 
@@ -305,6 +314,32 @@ const buildBridge = (): AituBridge => {
305
314
  }
306
315
  }
307
316
 
317
+ const enableScreenCapture = (reqId) => {
318
+ const isAndroid = android && android[enableScreenCaptureMethod];
319
+ const isIos = ios && ios[enableScreenCaptureMethod];
320
+
321
+ if (isAndroid) {
322
+ android[enableScreenCaptureMethod](reqId);
323
+ } else if (isIos) {
324
+ ios[enableScreenCaptureMethod].postMessage({ reqId });
325
+ } else if (typeof window !== 'undefined') {
326
+ console.log('--enableScreenCapture-isWeb');
327
+ }
328
+ }
329
+
330
+ const disableScreenCapture = (reqId) => {
331
+ const isAndroid = android && android[disableScreenCaptureMethod];
332
+ const isIos = ios && ios[disableScreenCaptureMethod];
333
+
334
+ if (isAndroid) {
335
+ android[disableScreenCaptureMethod](reqId);
336
+ } else if (isIos) {
337
+ ios[disableScreenCaptureMethod].postMessage({ reqId });
338
+ } else if (typeof window !== 'undefined') {
339
+ console.log('--disableScreenCapture-isWeb');
340
+ }
341
+ }
342
+
308
343
  const shareImage = (reqId, text, image) => {
309
344
  // !!!======================!!!
310
345
  // !!!===== Deprecated =====!!!
@@ -368,6 +403,17 @@ const buildBridge = (): AituBridge => {
368
403
  }
369
404
  };
370
405
 
406
+ const setTabActiveHandler = (handler: (tabname: string) => void) => {
407
+ const isAndroid = android && android[setTabActiveHandlerMethod];
408
+ const isIos = ios && ios[setTabActiveHandlerMethod];
409
+
410
+ if (isAndroid || isIos) {
411
+ (window as any).onAituBridgeTabActive = handler;
412
+ } else if (typeof window !== 'undefined') {
413
+ console.log('--setTabActiveHandler-isWeb');
414
+ }
415
+ };
416
+
371
417
  const vibrate = (reqId, pattern) => {
372
418
  if (
373
419
  !Array.isArray(pattern) ||
@@ -418,8 +464,11 @@ const buildBridge = (): AituBridge => {
418
464
  const shareImagePromise = promisifyMethod(shareImage, sub);
419
465
  const shareFilePromise = promisifyMethod(shareFile, sub);
420
466
  const vibratePromise = promisifyMethod(vibrate, sub);
467
+ const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);
468
+ const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);
421
469
 
422
470
  return {
471
+ version: String(version),
423
472
  copyToClipboard: copyToClipboardPromise,
424
473
  invoke: invokePromise,
425
474
  storage: storagePromise,
@@ -440,10 +489,13 @@ const buildBridge = (): AituBridge => {
440
489
  shareImage: shareImagePromise,
441
490
  shareFile: shareFilePromise,
442
491
  setShakeHandler,
492
+ setTabActiveHandler,
443
493
  vibrate: vibratePromise,
444
494
  isSupported,
445
495
  supports,
446
- sub
496
+ sub,
497
+ enableScreenCapture: enableScreenCapturePromise,
498
+ disableScreenCapture: disableScreenCapturePromise
447
499
  }
448
500
  }
449
501
 
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "compilerOptions": {
3
+ "resolveJsonModule": true
4
+ }
5
+ }