@btsd/aitu-bridge 0.3.0 → 0.3.2

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
@@ -14,7 +14,9 @@ enum EInvokeRequest {
14
14
  getContacts = 'GetContacts',
15
15
  getUserProfile = 'GetUserProfile',
16
16
  enableNotifications = 'AllowNotifications',
17
- disableNotifications = 'DisableNotifications'
17
+ disableNotifications = 'DisableNotifications',
18
+ enablePrivateMessaging = 'EnablePrivateMessaging',
19
+ disablePrivateMessaging = 'DisablePrivateMessaging',
18
20
  }
19
21
 
20
22
  type SetItemType = (keyName: string, keyValue: string) => Promise<void>;
@@ -127,6 +129,8 @@ export interface AituBridge {
127
129
  shareFile: (text: string, filename: string, base64Data: string) => Promise<ShareResponse>;
128
130
  enableNotifications: () => Promise<{}>;
129
131
  disableNotifications: () => Promise<{}>;
132
+ enablePrivateMessaging: (appId: string) => Promise<string>;
133
+ disablePrivateMessaging: (appId: string) => Promise<string>;
130
134
  openSettings: () => Promise<OpenSettingsResponse>;
131
135
  closeApplication: () => Promise<ResponseType>;
132
136
  setShakeHandler: (handler: any) => void;
@@ -182,13 +186,13 @@ const buildBridge = (): AituBridge => {
182
186
  [...subs].map((fn) => fn.call(null, e));
183
187
  })
184
188
 
185
- window.addEventListener('message', (e)=>{
189
+ window.addEventListener('message', (e) => {
186
190
  const message = JSON.parse(e.data)
187
191
 
188
- if(message && message['method']){
189
- if(message.method === 'setCustomBackArrowOnClickHandler'){
192
+ if (message && message['method']) {
193
+ if (message.method === 'setCustomBackArrowOnClickHandler') {
190
194
  (window as any).onAituBridgeBackArrowClick()
191
- }else if(message.method === 'setHeaderMenuItemClickHandler'){
195
+ } else if (message.method === 'setHeaderMenuItemClickHandler') {
192
196
  (window as any).onAituBridgeHeaderMenuItemClick(message.param)
193
197
  }
194
198
  }
@@ -485,7 +489,7 @@ const buildBridge = (): AituBridge => {
485
489
  android[vibrateMethod](reqId, JSON.stringify(pattern));
486
490
  } else if (isIos) {
487
491
  ios[vibrateMethod].postMessage({ reqId, pattern });
488
- } else if (web) {
492
+ } else if (web) {
489
493
  web.execute(vibrateMethod, reqId, pattern);
490
494
  } else if (typeof window !== 'undefined') {
491
495
  console.log('--vibrate-isUnknown');
@@ -591,7 +595,7 @@ const buildBridge = (): AituBridge => {
591
595
 
592
596
  if (isAndroid || isIos || web) {
593
597
  (window as any).onAituBridgeBackArrowClick = handler;
594
- }else if (typeof window !== 'undefined') {
598
+ } else if (typeof window !== 'undefined') {
595
599
  console.log('--setCustomBackArrowOnClickHandler-isUnknown');
596
600
  }
597
601
  }
@@ -616,7 +620,7 @@ const buildBridge = (): AituBridge => {
616
620
  const setHeaderMenuItemsPromise = promisifyMethod(setHeaderMenuItems, setHeaderMenuItemsMethod, sub);
617
621
  const setCustomBackArrowModePromise = promisifyMethod(setCustomBackArrowMode, setCustomBackArrowModeMethod, sub);
618
622
  const getCustomBackArrowModePromise = promisifyMethod(getCustomBackArrowMode, getCustomBackArrowModeMethod, sub);
619
- const setCustomBackArrowVisiblePromise = promisifyMethod(setCustomBackArrowVisible,setCustomBackArrowVisibleMethod, sub);
623
+ const setCustomBackArrowVisiblePromise = promisifyMethod(setCustomBackArrowVisible, setCustomBackArrowVisibleMethod, sub);
620
624
 
621
625
  return {
622
626
  version: String(LIB_VERSION),
@@ -633,6 +637,8 @@ const buildBridge = (): AituBridge => {
633
637
  selectContact: selectContactPromise,
634
638
  enableNotifications,
635
639
  disableNotifications,
640
+ enablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.enablePrivateMessaging, { appId }),
641
+ disablePrivateMessaging: (appId: string) => invokePromise(EInvokeRequest.disablePrivateMessaging, { appId }),
636
642
  openSettings: openSettingsPromise,
637
643
  closeApplication: closeApplicationPromise,
638
644
  setTitle: setTitlePromise,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.3.0";
1
+ export const LIB_VERSION = "0.3.2";
package/src/webBridge.ts CHANGED
@@ -4,8 +4,13 @@ const AITU_DOMAIN_PARAM = '__aitu-domain'
4
4
 
5
5
  const searchParams = new URLSearchParams(window.location.search)
6
6
 
7
- const aituOrigin = searchParams.get(AITU_DOMAIN_PARAM)
7
+ let aituOrigin = searchParams.get(AITU_DOMAIN_PARAM)
8
8
 
9
+ if(aituOrigin){
10
+ localStorage.setItem('mini-app-domain', aituOrigin)
11
+ }else{
12
+ aituOrigin = localStorage.getItem('mini-app-domain')
13
+ }
9
14
  interface WebBridge {
10
15
  execute(method: keyof AituBridge, reqId: string, ...payload: any[] ): void
11
16
  origin: string
@@ -28,7 +33,6 @@ if (aituOrigin) {
28
33
  }
29
34
 
30
35
  }
31
-
32
36
  window.addEventListener('message', event => {
33
37
  if (event.origin === aituOrigin && event.data) {
34
38
  window.dispatchEvent(new CustomEvent('aituEvents', { detail: event.data }));