@btsd/aitu-bridge 0.3.43 → 0.3.45

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/src/index.ts CHANGED
@@ -151,6 +151,7 @@ export interface AituBridge {
151
151
  openPayment: (transactionId: string) => Promise<ResponseType>;
152
152
  setCustomBackArrowOnClickHandler: (handler: BackArrowClickHandlerType) => void;
153
153
  checkBiometry: () => Promise<ResponseType>;
154
+ openExternalUrl: (url: string) => Promise<ResponseType>;
154
155
  }
155
156
 
156
157
  const invokeMethod = 'invoke';
@@ -179,6 +180,7 @@ const setCustomBackArrowVisibleMethod = 'setCustomBackArrowVisible';
179
180
  const openPaymentMethod = 'openPayment'
180
181
  const setCustomBackArrowOnClickHandlerMethod = 'setCustomBackArrowOnClickHandler';
181
182
  const checkBiometryMethod = 'checkBiometry';
183
+ const openExternalUrlMethod = 'openExternalUrl';
182
184
 
183
185
  const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
184
186
  const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
@@ -191,22 +193,6 @@ const buildBridge = (): AituBridge => {
191
193
  window.addEventListener('aituEvents', (e: any) => {
192
194
  [...subs].map((fn) => fn.call(null, e));
193
195
  })
194
-
195
- window.addEventListener('message', (e) => {
196
- if (typeof e.data !== 'string') {
197
- return;
198
- }
199
-
200
- const message = JSON.parse(e.data)
201
-
202
- if (message && message['method']) {
203
- if (message.method === 'setCustomBackArrowOnClickHandler') {
204
- (window as any).onAituBridgeBackArrowClick()
205
- } else if (message.method === 'setHeaderMenuItemClickHandler') {
206
- (window as any).onAituBridgeHeaderMenuItemClick(message.param)
207
- }
208
- }
209
- })
210
196
  }
211
197
 
212
198
  const invoke = (reqId, method, data = {}) => {
@@ -638,6 +624,19 @@ const buildBridge = (): AituBridge => {
638
624
  }
639
625
  }
640
626
 
627
+ const openExternalUrl = (reqId, url: string) => {
628
+ const isAndroid = android && android[openExternalUrlMethod];
629
+ const isIos = ios && ios[openExternalUrlMethod];
630
+
631
+ if (isAndroid) {
632
+ android[openExternalUrlMethod](reqId, url);
633
+ } else if (isIos) {
634
+ ios[openExternalUrlMethod].postMessage({ reqId, url });
635
+ } else {
636
+ console.log("--openExternalUrlMethod-isUnknown");
637
+ }
638
+ };
639
+
641
640
 
642
641
  const invokePromise = promisifyInvoke(invoke, sub);
643
642
  const storagePromise = promisifyStorage(storage, sub);
@@ -661,6 +660,7 @@ const buildBridge = (): AituBridge => {
661
660
  const setCustomBackArrowVisiblePromise = promisifyMethod(setCustomBackArrowVisible, setCustomBackArrowVisibleMethod, sub);
662
661
  const openPaymentPromise = promisifyMethod(openPayment, openPaymentMethod, sub);
663
662
  const checkBiometryPromise = promisifyMethod(checkBiometry, checkBiometryMethod, sub);
663
+ const openExternalUrlPromise = promisifyMethod(openExternalUrl, openExternalUrlMethod, sub);
664
664
 
665
665
  return {
666
666
  version: String(LIB_VERSION),
@@ -673,12 +673,15 @@ const buildBridge = (): AituBridge => {
673
673
  getGeo: getGeoPromise,
674
674
  getQr: getQrPromise,
675
675
  getSMSCode: getSMSCodePromise,
676
- getUserProfile: (id: string) => invokePromise(EInvokeRequest.getUserProfile, { id }),
676
+ getUserProfile: (id: string) =>
677
+ invokePromise(EInvokeRequest.getUserProfile, { id }),
677
678
  selectContact: selectContactPromise,
678
679
  enableNotifications,
679
680
  disableNotifications,
680
- enablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
681
- disablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
681
+ enablePrivateMessaging: (appId: string) =>
682
+ invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
683
+ disablePrivateMessaging: (appId: string) =>
684
+ invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
682
685
  openSettings: openSettingsPromise,
683
686
  closeApplication: closeApplicationPromise,
684
687
  setTitle: setTitlePromise,
@@ -701,7 +704,8 @@ const buildBridge = (): AituBridge => {
701
704
  openPayment: openPaymentPromise,
702
705
  setCustomBackArrowOnClickHandler,
703
706
  checkBiometry: checkBiometryPromise,
704
- }
707
+ openExternalUrl: openExternalUrlPromise,
708
+ };
705
709
  }
706
710
 
707
711
  const bridge = buildBridge();
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.3.43";
1
+ export const LIB_VERSION = "0.3.45";
package/src/webBridge.ts CHANGED
@@ -35,7 +35,28 @@ if (aituOrigin) {
35
35
  }
36
36
  window.addEventListener('message', event => {
37
37
  if (event.origin === aituOrigin && event.data) {
38
+
39
+ // dispatch aitu events
38
40
  window.dispatchEvent(new CustomEvent('aituEvents', { detail: event.data }));
41
+
42
+ // try to detect handler call
43
+ if (typeof event.data !== 'string' || event.data === '') {
44
+ return;
45
+ }
46
+
47
+ try {
48
+ const message = JSON.parse(event.data)
49
+
50
+ if (message && message['method']) {
51
+ if (message.method === 'setCustomBackArrowOnClickHandler') {
52
+ (window as any).onAituBridgeBackArrowClick()
53
+ } else if (message.method === 'setHeaderMenuItemClickHandler') {
54
+ (window as any).onAituBridgeHeaderMenuItemClick(message.param)
55
+ }
56
+ }
57
+ } catch (e) {
58
+ console.log('Error parsing message data: ' + e);
59
+ }
39
60
  }
40
61
  })
41
62
  }