@btsd/aitu-bridge 0.2.4 → 0.2.8
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.d.ts +13 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +77 -9
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ declare enum EInvokeRequest {
|
|
|
2
2
|
getMe = "GetMe",
|
|
3
3
|
getPhone = "GetPhone",
|
|
4
4
|
getContacts = "GetContacts",
|
|
5
|
+
getUserProfile = "GetUserProfile",
|
|
5
6
|
enableNotifications = "AllowNotifications",
|
|
6
7
|
disableNotifications = "DisableNotifications"
|
|
7
8
|
}
|
|
@@ -42,9 +43,17 @@ interface SelectContactResponse {
|
|
|
42
43
|
name: string;
|
|
43
44
|
lastname: string;
|
|
44
45
|
}
|
|
46
|
+
interface GetUserProfileResponse {
|
|
47
|
+
name: string;
|
|
48
|
+
lastname?: string;
|
|
49
|
+
phone?: string;
|
|
50
|
+
avatar?: string;
|
|
51
|
+
avatarThumb?: string;
|
|
52
|
+
}
|
|
45
53
|
declare type OpenSettingsResponse = 'success' | 'failed';
|
|
46
54
|
declare type ShareResponse = 'success' | 'failed';
|
|
47
55
|
declare type CopyToClipboardResponse = 'success' | 'failed';
|
|
56
|
+
declare type ResponseType = 'success' | 'failed';
|
|
48
57
|
declare type BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;
|
|
49
58
|
interface BridgeStorage {
|
|
50
59
|
setItem: SetItemType;
|
|
@@ -61,13 +70,16 @@ interface AituBridge {
|
|
|
61
70
|
selectContact: () => Promise<SelectContactResponse>;
|
|
62
71
|
getQr: () => Promise<string>;
|
|
63
72
|
getSMSCode: () => Promise<string>;
|
|
73
|
+
getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;
|
|
64
74
|
share: (text: string) => Promise<ShareResponse>;
|
|
75
|
+
setTitle: (text: string) => Promise<ResponseType>;
|
|
65
76
|
copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;
|
|
66
77
|
shareImage: (text: string, image: string) => Promise<ShareResponse>;
|
|
67
|
-
shareFile: (text: string,
|
|
78
|
+
shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;
|
|
68
79
|
enableNotifications: () => Promise<{}>;
|
|
69
80
|
disableNotifications: () => Promise<{}>;
|
|
70
81
|
openSettings: () => Promise<OpenSettingsResponse>;
|
|
82
|
+
closeApplication: () => Promise<ResponseType>;
|
|
71
83
|
setShakeHandler: (handler: any) => void;
|
|
72
84
|
vibrate: (pattern: number[]) => Promise<VibratePattern>;
|
|
73
85
|
isSupported: () => boolean;
|
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.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,
|
|
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.substring("data:image/".length,t.indexOf(";base64")),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;
|
|
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 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\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = '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 share: (text: string) => Promise<ShareResponse>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, file: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\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 shareMethod = 'share';\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 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\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 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\n const shareFile = (reqId, text, file) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, file);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, file });\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 sharePromise = promisifyMethod(share, 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 selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\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","sharePromise","text","copyToClipboardPromise","shareImagePromise","image","shareFilePromise","file","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","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,2CACAA,8CALF,CAAKA,IAAAA,OAyFL,IAAMC,EAAe,SACfC,EAAgB,UAahBC,EAA4B,oBAAXC,QAA2BA,OAAeC,cAC3DC,EAAwB,oBAAXF,QAA2BA,OAAeG,QAAWH,OAAeG,OAAOC,gBACxFC,EAAwB,oBAAXL,QAA2BA,OAAO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kBAAoBD,EACT,oBAAXnF,QAChBkC,QAAQC,IAAI,4BAuEdkD,QAAS3B,EACT4B,YA9CkB,WAClB,IAAMC,EAASrF,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOoD,QAAQzF,GAAWwF,GAAUlF,IA6CpCoF,SA1Ce,SAACnH,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IAwCnBoD,IAAAA,GAIWgE"}
|
|
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.substring('data:image/'.length, image.indexOf(';base64'));\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","substring","length","indexOf","base64Data","substr","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,QA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=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.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
|
|
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 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),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")},d),f=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")},d),p=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")},d),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")},d),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")},d),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")},d),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")},d),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")},d),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")},d),I=e((e,t,o)=>{const n=s&&s.shareFile,r=i&&i.shareFile,a="image."+o.substring("data:image/".length,o.indexOf(";base64")),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),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")},d),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")},d);return{copyToClipboard:v,invoke:l,storage:c,getMe:()=>l(t.getMe),getPhone:()=>l(t.getPhone),getContacts:()=>l(t.getContacts),getGeo:g,getQr:f,getSMSCode:p,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:d}})();export default a;
|
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
CHANGED
|
@@ -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 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\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = '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 share: (text: string) => Promise<ShareResponse>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, file: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\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 shareMethod = 'share';\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 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\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 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\n const shareFile = (reqId, text, file) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, file);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, file });\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 sharePromise = promisifyMethod(share, 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 selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\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","sharePromise","text","copyToClipboardPromise","shareImagePromise","image","shareFilePromise","file","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","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,EAA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J,EAAQO,OAAO,CAACC,EAAOJ,IAAWI,EAAQJ,GAAU,IAGpD,YADA7B,QAAQ/C,MAAM,gFAIhB,MACM6C,EAAQ/B,GAAOA,EAAG,QADNH,GAAWA,EAAO,QAIlCA,EAAO,QAAgBd,EAAO2B,KAAKC,UAAU+C,IACpC3B,EACT/B,EAAG,QAAgBS,YAAY,CAAE1B,MAAAA,EAAO2E,QAAAA,IACb,oBAAX5D,QAChBmC,QAAQC,IAAI,oBA6BgCV,GAEhD,MAAO,CACL2C,gBAAiBf,EACjBxB,OAAQD,EACRU,QAASD,EACTgC,MAAO,IAAMzC,EAAcjC,EAAe0E,OAC1CC,SAAU,IAAM1C,EAAcjC,EAAe2E,UAC7CC,YAAa,IAAM3C,EAAcjC,EAAe4E,aAChDC,OAAQ1B,EACR2B,MAAO1B,EACP2B,WAAY1B,EACZ2B,cAAe1B,EACf2B,oBA3E0B,IAAMhD,EAAcjC,EAAeiF,qBA4E7DC,qBA1E2B,IAAMjD,EAAcjC,EAAekF,sBA2E9DC,aAAc5B,EACd6B,MAAO5B,EACP6B,WAAY1B,EACZ2B,UAAWzB,EACX0B,gBA7EuBC,IACLrF,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAeqF,kBAAoBD,EACT,oBAAXpF,QAChBmC,QAAQC,IAAI,4BAuEdkD,QAAS3B,EACT4B,YA9CkB,KAClB,MAAMC,EAAStF,GAAQF,OAAeG,OAAOC,gBAAgB0B,OAC7D,OAAO2D,QAAQ1F,GAAWyF,GAAUnF,IA6CpCqF,SA1CgBtH,GACf2B,GAAsC,mBAApBA,EAAQ3B,IAC1B8B,GAAOA,EAAI9B,IAA8C,mBAA5B8B,EAAI9B,GAAQuC,aACzCN,GAA8B,mBAAhBA,EAAIjC,GAwCnBsD,IAAAA,IAIWiE"}
|
|
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.substring('data:image/'.length, image.indexOf(';base64'));\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","substring","length","indexOf","base64Data","substr","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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DC,OAAQlC,EACRmC,MAAOlC,EACPmC,WAAYlC,EACZmC,eAAiBC,GAAexD,EAAcjC,EAAewF,eAAgB,CAAEC,GAAAA,IAC/EC,cAAepC,EACfqC,oBA9E0B,IAAM1D,EAAcjC,EAAe2F,qBA+E7DC,qBA7E2B,IAAM3D,EAAcjC,EAAe4F,sBA8E9DC,aAActC,EACduC,iBAAkBtC,EAClBuC,SAAUpC,EACVqC,MAAOvC,EACPwC,WAAYpC,EACZqC,UAAW5B,EACX6B,gBAlFuBC,IACLjG,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAeiG,kBAAoBD,EACT,oBAAXhG,QAChBmC,QAAQC,IAAI,4BA4Ed8D,QAAS/B,EACTgC,YAnDkB,KAClB,MAAMC,EAASlG,GAAQF,OAAeG,OAAOC,gBAAgB0B,OAC7D,OAAOuE,QAAQtG,GAAWqG,GAAU/F,IAkDpCiG,SA/CgBlI,GACf2B,GAAsC,mBAApBA,EAAQ3B,IAC1B8B,GAAOA,EAAI9B,IAA8C,mBAA5B8B,EAAI9B,GAAQuC,aACzCN,GAA8B,mBAAhBA,EAAIjC,GA6CnBsD,IAAAA,IAIW6E"}
|
package/dist/index.module.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.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,
|
|
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.substring("data:image/".length,t.indexOf(";base64")),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}}();export default d;
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -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 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\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = '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 share: (text: string) => Promise<ShareResponse>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, file: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\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 shareMethod = 'share';\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 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\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 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\n const shareFile = (reqId, text, file) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, file);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, file });\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 sharePromise = promisifyMethod(share, 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 selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\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","sharePromise","text","copyToClipboardPromise","shareImagePromise","image","shareFilePromise","file","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","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,2CACAA,8CALF,CAAKA,IAAAA,OAyFL,IA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C,EAAeiF,uBA2E9DC,aAAc5B,EACd6B,MAAO5B,EACP6B,WAAY1B,EACZ2B,UAAWzB,EACX0B,gBA7EsB,SAACC,GACLpF,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAeoF,kBAAoBD,EACT,oBAAXnF,QAChBkC,QAAQC,IAAI,4BAuEdkD,QAAS3B,EACT4B,YA9CkB,WAClB,IAAMC,EAASrF,GAAQF,OAAeG,OAAOC,gBAAgBgC,OAC7D,OAAOoD,QAAQzF,GAAWwF,GAAUlF,IA6CpCoF,SA1Ce,SAACnH,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IAwCnBoD,IAAAA,GAIWgE"}
|
|
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.substring('data:image/'.length, image.indexOf(';base64'));\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","substring","length","indexOf","base64Data","substr","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,SAAK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8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA6CnBoD,IAAAA,GAIW4E"}
|
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.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,
|
|
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)})}),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),y=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),m=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),I=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),S=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.substring("data:image/".length,t.indexOf(";base64")),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:S,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:y,closeApplication:h,setTitle:I,share:m,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}}()});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -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 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\ntype OpenSettingsResponse = 'success' | 'failed';\ntype ShareResponse = 'success' | 'failed';\ntype CopyToClipboardResponse = 'success' | 'failed';\ntype VibrateResponse = '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 share: (text: string) => Promise<ShareResponse>;\n copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;\n shareImage: (text: string, image: string) => Promise<ShareResponse>;\n shareFile: (text: string, file: string) => Promise<ShareResponse>;\n enableNotifications: () => Promise<{}>;\n disableNotifications: () => Promise<{}>;\n openSettings: () => Promise<OpenSettingsResponse>;\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 shareMethod = 'share';\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 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\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 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\n const shareFile = (reqId, text, file) => {\n const isAndroid = android && android[shareFileMethod];\n const isIos = ios && ios[shareFileMethod];\n\n if (isAndroid) {\n android[shareFileMethod](reqId, text, file);\n } else if (isIos) {\n ios[shareFileMethod].postMessage({ reqId, text, file });\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 sharePromise = promisifyMethod(share, 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 selectContact: selectContactPromise,\n enableNotifications,\n disableNotifications,\n openSettings: openSettingsPromise,\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","sharePromise","text","copyToClipboardPromise","shareImagePromise","image","shareFilePromise","file","vibratePromise","pattern","Array","isArray","some","timing","Math","floor","reduce","total","copyToClipboard","getMe","getPhone","getContacts","getGeo","getQr","getSMSCode","selectContact","enableNotifications","disableNotifications","openSettings","share","shareImage","shareFile","setShakeHandler","handler","onAituBridgeShake","vibrate","isSupported","iosSup","Boolean","supports","buildBridge"],"mappings":"mLA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,IAwCnBmD,IAAAA,GAIWgE"}
|
|
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.substring('data:image/'.length, image.indexOf(';base64'));\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","substring","length","indexOf","base64Data","substr","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","isS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AAMjD,EAAchC,EAAeiF,WAC7CC,YAAa,kBAAMlD,EAAchC,EAAekF,cAChDC,OAAQlC,EACRmC,MAAOlC,EACPmC,WAAYlC,EACZmC,eAAgB,SAACC,UAAevD,EAAchC,EAAesF,eAAgB,CAAEC,GAAAA,KAC/EC,cAAepC,EACfqC,oBA9E0B,kBAAMzD,EAAchC,EAAeyF,sBA+E7DC,qBA7E2B,kBAAM1D,EAAchC,EAAe0F,uBA8E9DC,aAActC,EACduC,iBAAkBtC,EAClBuC,SAAUpC,EACVqC,MAAOvC,EACPwC,WAAYpC,EACZqC,UAAW5B,EACX6B,gBAlFsB,SAACC,GACL/F,GAAWA,EAAO,iBACtBG,GAAOA,EAAG,gBAGrBF,OAAe+F,kBAAoBD,EACT,oBAAX9F,QAChBiC,QAAQC,IAAI,4BA4Ed8D,QAAS/B,EACTgC,YAnDkB,WAClB,IAAMC,EAAShG,GAAQF,OAAeG,OAAOC,gBAAgB+B,OAC7D,OAAOgE,QAAQpG,GAAWmG,GAAU7F,IAkDpC+F,SA/Ce,SAAC9H,UACfyB,GAAsC,mBAApBA,EAAQzB,IAC1B4B,GAAOA,EAAI5B,IAA8C,mBAA5B4B,EAAI5B,GAAQqC,aACzCN,GAA8B,mBAAhBA,EAAI/B,IA6CnBmD,IAAAA,GAIW4E"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ enum EInvokeRequest {
|
|
|
6
6
|
getMe = 'GetMe',
|
|
7
7
|
getPhone = 'GetPhone',
|
|
8
8
|
getContacts = 'GetContacts',
|
|
9
|
+
getUserProfile = 'GetUserProfile',
|
|
9
10
|
enableNotifications = 'AllowNotifications',
|
|
10
11
|
disableNotifications = 'DisableNotifications'
|
|
11
12
|
}
|
|
@@ -54,10 +55,20 @@ interface SelectContactResponse {
|
|
|
54
55
|
lastname: string;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
interface GetUserProfileResponse {
|
|
59
|
+
name: string;
|
|
60
|
+
lastname?: string;
|
|
61
|
+
phone?: string;
|
|
62
|
+
avatar?: string;
|
|
63
|
+
avatarThumb?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
type OpenSettingsResponse = 'success' | 'failed';
|
|
58
67
|
type ShareResponse = 'success' | 'failed';
|
|
59
68
|
type CopyToClipboardResponse = 'success' | 'failed';
|
|
60
69
|
type VibrateResponse = 'success' | 'failed';
|
|
70
|
+
// todo: remove duplicates
|
|
71
|
+
type ResponseType = 'success' | 'failed';
|
|
61
72
|
|
|
62
73
|
type BridgeInvoke<T extends EInvokeRequest, R> = (method: T, data?: {}) => Promise<R>;
|
|
63
74
|
|
|
@@ -77,13 +88,16 @@ interface AituBridge {
|
|
|
77
88
|
selectContact: () => Promise<SelectContactResponse>;
|
|
78
89
|
getQr: () => Promise<string>;
|
|
79
90
|
getSMSCode: () => Promise<string>;
|
|
91
|
+
getUserProfile: (userId: string) => Promise<GetUserProfileResponse>;
|
|
80
92
|
share: (text: string) => Promise<ShareResponse>;
|
|
93
|
+
setTitle: (text: string) => Promise<ResponseType>;
|
|
81
94
|
copyToClipboard: (text: string) => Promise<CopyToClipboardResponse>;
|
|
82
95
|
shareImage: (text: string, image: string) => Promise<ShareResponse>;
|
|
83
|
-
shareFile: (text: string,
|
|
96
|
+
shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;
|
|
84
97
|
enableNotifications: () => Promise<{}>;
|
|
85
98
|
disableNotifications: () => Promise<{}>;
|
|
86
99
|
openSettings: () => Promise<OpenSettingsResponse>;
|
|
100
|
+
closeApplication: () => Promise<ResponseType>;
|
|
87
101
|
setShakeHandler: (handler: any) => void;
|
|
88
102
|
vibrate: (pattern: number[]) => Promise<VibratePattern>;
|
|
89
103
|
isSupported: () => boolean;
|
|
@@ -98,7 +112,9 @@ const getQrMethod = 'getQr';
|
|
|
98
112
|
const getSMSCodeMethod = 'getSMSCode';
|
|
99
113
|
const selectContactMethod = 'selectContact';
|
|
100
114
|
const openSettingsMethod = 'openSettings';
|
|
115
|
+
const closeApplicationMethod = 'closeApplication';
|
|
101
116
|
const shareMethod = 'share';
|
|
117
|
+
const setTitleMethod = 'setTitle';
|
|
102
118
|
const copyToClipboardMethod = 'copyToClipboard';
|
|
103
119
|
const shareImageMethod = 'shareImage';
|
|
104
120
|
const shareFileMethod = 'shareFile';
|
|
@@ -237,6 +253,19 @@ const buildBridge = (): AituBridge => {
|
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
|
|
256
|
+
const closeApplication = (reqId) => {
|
|
257
|
+
const isAndroid = android && android[closeApplicationMethod];
|
|
258
|
+
const isIos = ios && ios[closeApplicationMethod];
|
|
259
|
+
|
|
260
|
+
if (isAndroid) {
|
|
261
|
+
android[closeApplicationMethod](reqId);
|
|
262
|
+
} else if (isIos) {
|
|
263
|
+
ios[closeApplicationMethod].postMessage({ reqId });
|
|
264
|
+
} else if (typeof window !== 'undefined') {
|
|
265
|
+
console.log('--closeApplication-isWeb');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
240
269
|
const share = (reqId, text) => {
|
|
241
270
|
const isAndroid = android && android[shareMethod];
|
|
242
271
|
const isIos = ios && ios[shareMethod];
|
|
@@ -250,6 +279,18 @@ const buildBridge = (): AituBridge => {
|
|
|
250
279
|
}
|
|
251
280
|
}
|
|
252
281
|
|
|
282
|
+
const setTitle = (reqId, text) => {
|
|
283
|
+
const isAndroid = android && android[setTitleMethod];
|
|
284
|
+
const isIos = ios && ios[setTitleMethod];
|
|
285
|
+
|
|
286
|
+
if (isAndroid) {
|
|
287
|
+
android[setTitleMethod](reqId, text);
|
|
288
|
+
} else if (isIos) {
|
|
289
|
+
ios[setTitleMethod].postMessage({ reqId, text });
|
|
290
|
+
} else if (typeof window !== 'undefined') {
|
|
291
|
+
console.log('--setTitle-isWeb');
|
|
292
|
+
}
|
|
293
|
+
}
|
|
253
294
|
|
|
254
295
|
const copyToClipboard = (reqId, text) => {
|
|
255
296
|
const isAndroid = android && android[copyToClipboardMethod];
|
|
@@ -265,26 +306,48 @@ const buildBridge = (): AituBridge => {
|
|
|
265
306
|
}
|
|
266
307
|
|
|
267
308
|
const shareImage = (reqId, text, image) => {
|
|
268
|
-
|
|
269
|
-
|
|
309
|
+
// !!!======================!!!
|
|
310
|
+
// !!!===== Deprecated =====!!!
|
|
311
|
+
// !!!======================!!!
|
|
312
|
+
|
|
313
|
+
// const isAndroid = android && android[shareImageMethod];
|
|
314
|
+
// const isIos = ios && ios[shareImageMethod];
|
|
315
|
+
|
|
316
|
+
// if (isAndroid) {
|
|
317
|
+
// android[shareImageMethod](reqId, text, image);
|
|
318
|
+
// } else if (isIos) {
|
|
319
|
+
// ios[shareImageMethod].postMessage({ reqId, text, image });
|
|
320
|
+
// } else if (typeof window !== 'undefined') {
|
|
321
|
+
// console.log('--shareImage-isWeb');
|
|
322
|
+
// }
|
|
323
|
+
|
|
324
|
+
// new one - fallback to shareFile
|
|
325
|
+
const isAndroid = android && android[shareFileMethod];
|
|
326
|
+
const isIos = ios && ios[shareFileMethod];
|
|
327
|
+
|
|
328
|
+
// get extension from base64 mime type and merge with name
|
|
329
|
+
const ext = image.substring('data:image/'.length, image.indexOf(';base64'));
|
|
330
|
+
const filename = 'image.' + ext;
|
|
331
|
+
// remove mime type
|
|
332
|
+
const base64Data = image.substr(image.indexOf(',') + 1);
|
|
270
333
|
|
|
271
334
|
if (isAndroid) {
|
|
272
|
-
android[
|
|
335
|
+
android[shareFileMethod](reqId, text, filename, base64Data);
|
|
273
336
|
} else if (isIos) {
|
|
274
|
-
ios[
|
|
337
|
+
ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });
|
|
275
338
|
} else if (typeof window !== 'undefined') {
|
|
276
|
-
console.log('--
|
|
339
|
+
console.log('--shareFile-isWeb');
|
|
277
340
|
}
|
|
278
341
|
}
|
|
279
342
|
|
|
280
|
-
const shareFile = (reqId, text,
|
|
343
|
+
const shareFile = (reqId, text, filename, base64Data) => {
|
|
281
344
|
const isAndroid = android && android[shareFileMethod];
|
|
282
345
|
const isIos = ios && ios[shareFileMethod];
|
|
283
346
|
|
|
284
347
|
if (isAndroid) {
|
|
285
|
-
android[shareFileMethod](reqId, text,
|
|
348
|
+
android[shareFileMethod](reqId, text, filename, base64Data);
|
|
286
349
|
} else if (isIos) {
|
|
287
|
-
ios[shareFileMethod].postMessage({ reqId, text,
|
|
350
|
+
ios[shareFileMethod].postMessage({ reqId, text, filename, base64Data });
|
|
288
351
|
} else if (typeof window !== 'undefined') {
|
|
289
352
|
console.log('--shareFile-isWeb');
|
|
290
353
|
}
|
|
@@ -348,7 +411,9 @@ const buildBridge = (): AituBridge => {
|
|
|
348
411
|
const getSMSCodePromise = promisifyMethod(getSMSCode, sub);
|
|
349
412
|
const selectContactPromise = promisifyMethod(selectContact, sub);
|
|
350
413
|
const openSettingsPromise = promisifyMethod(openSettings, sub);
|
|
414
|
+
const closeApplicationPromise = promisifyMethod(closeApplication, sub);
|
|
351
415
|
const sharePromise = promisifyMethod(share, sub);
|
|
416
|
+
const setTitlePromise = promisifyMethod(setTitle, sub);
|
|
352
417
|
const copyToClipboardPromise = promisifyMethod(copyToClipboard, sub);
|
|
353
418
|
const shareImagePromise = promisifyMethod(shareImage, sub);
|
|
354
419
|
const shareFilePromise = promisifyMethod(shareFile, sub);
|
|
@@ -364,10 +429,13 @@ const buildBridge = (): AituBridge => {
|
|
|
364
429
|
getGeo: getGeoPromise,
|
|
365
430
|
getQr: getQrPromise,
|
|
366
431
|
getSMSCode: getSMSCodePromise,
|
|
432
|
+
getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),
|
|
367
433
|
selectContact: selectContactPromise,
|
|
368
434
|
enableNotifications,
|
|
369
435
|
disableNotifications,
|
|
370
436
|
openSettings: openSettingsPromise,
|
|
437
|
+
closeApplication: closeApplicationPromise,
|
|
438
|
+
setTitle: setTitlePromise,
|
|
371
439
|
share: sharePromise,
|
|
372
440
|
shareImage: shareImagePromise,
|
|
373
441
|
shareFile: shareFilePromise,
|