@btsd/aitu-bridge 0.3.3 → 0.3.5
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 +4 -0
- 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/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/index.ts +38 -16
- package/src/version.ts +1 -1
- package/src/webBridge.ts +21 -0
package/src/index.ts
CHANGED
|
@@ -37,6 +37,8 @@ interface GetMeResponse {
|
|
|
37
37
|
id: string;
|
|
38
38
|
avatar?: string;
|
|
39
39
|
avatarThumb?: string;
|
|
40
|
+
notifications_allowed: boolean;
|
|
41
|
+
private_messaging_enabled: boolean;
|
|
40
42
|
sign: string;
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -146,7 +148,9 @@ export interface AituBridge {
|
|
|
146
148
|
setCustomBackArrowMode: (enabled: boolean) => Promise<ResponseType>;
|
|
147
149
|
getCustomBackArrowMode: () => Promise<boolean>;
|
|
148
150
|
setCustomBackArrowVisible: (visible: boolean) => Promise<ResponseType>;
|
|
151
|
+
openPayment: (transactionId: string) => Promise<ResponseType>;
|
|
149
152
|
setCustomBackArrowOnClickHandler: (handler: BackArrowClickHandlerType) => void;
|
|
153
|
+
checkBiometry: () => Promise<ResponseType>;
|
|
150
154
|
}
|
|
151
155
|
|
|
152
156
|
const invokeMethod = 'invoke';
|
|
@@ -172,7 +176,9 @@ const setHeaderMenuItemClickHandlerMethod = 'setHeaderMenuItemClickHandler';
|
|
|
172
176
|
const setCustomBackArrowModeMethod = 'setCustomBackArrowMode';
|
|
173
177
|
const getCustomBackArrowModeMethod = 'getCustomBackArrowMode';
|
|
174
178
|
const setCustomBackArrowVisibleMethod = 'setCustomBackArrowVisible';
|
|
179
|
+
const openPaymentMethod = 'openPayment'
|
|
175
180
|
const setCustomBackArrowOnClickHandlerMethod = 'setCustomBackArrowOnClickHandler';
|
|
181
|
+
const checkBiometryMethod = 'checkBiometry';
|
|
176
182
|
|
|
177
183
|
const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
|
|
178
184
|
const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
|
|
@@ -185,22 +191,6 @@ const buildBridge = (): AituBridge => {
|
|
|
185
191
|
window.addEventListener('aituEvents', (e: any) => {
|
|
186
192
|
[...subs].map((fn) => fn.call(null, e));
|
|
187
193
|
})
|
|
188
|
-
|
|
189
|
-
window.addEventListener('message', (e) => {
|
|
190
|
-
if(typeof e.data !== 'string') {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const message = JSON.parse(e.data)
|
|
195
|
-
|
|
196
|
-
if (message && message['method']) {
|
|
197
|
-
if (message.method === 'setCustomBackArrowOnClickHandler') {
|
|
198
|
-
(window as any).onAituBridgeBackArrowClick()
|
|
199
|
-
} else if (message.method === 'setHeaderMenuItemClickHandler') {
|
|
200
|
-
(window as any).onAituBridgeHeaderMenuItemClick(message.param)
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
194
|
}
|
|
205
195
|
|
|
206
196
|
const invoke = (reqId, method, data = {}) => {
|
|
@@ -604,6 +594,34 @@ const buildBridge = (): AituBridge => {
|
|
|
604
594
|
}
|
|
605
595
|
}
|
|
606
596
|
|
|
597
|
+
const openPayment = (reqId, transactionId: string) => {
|
|
598
|
+
const isAndroid = android && android[openPaymentMethod];
|
|
599
|
+
const isIos = ios && ios[openPaymentMethod];
|
|
600
|
+
|
|
601
|
+
if (isAndroid) {
|
|
602
|
+
android[openPaymentMethod](reqId, transactionId);
|
|
603
|
+
} else if (isIos) {
|
|
604
|
+
ios[openPaymentMethod].postMessage({ reqId, transactionId });
|
|
605
|
+
} else {
|
|
606
|
+
console.log('--openPayment-isUnknown');
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const checkBiometry = (reqId) => {
|
|
611
|
+
const isAndroid = android && android[checkBiometryMethod];
|
|
612
|
+
const isIos = ios && ios[checkBiometryMethod];
|
|
613
|
+
|
|
614
|
+
if (isAndroid) {
|
|
615
|
+
android[checkBiometryMethod](reqId);
|
|
616
|
+
} else if (isIos) {
|
|
617
|
+
ios[checkBiometryMethod].postMessage({ reqId });
|
|
618
|
+
} else if (web) {
|
|
619
|
+
web.execute(checkBiometryMethod, reqId);
|
|
620
|
+
} else if (typeof window !== 'undefined') {
|
|
621
|
+
console.log('--checkBiometry-isUnknown');
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
607
625
|
|
|
608
626
|
const invokePromise = promisifyInvoke(invoke, sub);
|
|
609
627
|
const storagePromise = promisifyStorage(storage, sub);
|
|
@@ -625,6 +643,8 @@ const buildBridge = (): AituBridge => {
|
|
|
625
643
|
const setCustomBackArrowModePromise = promisifyMethod(setCustomBackArrowMode, setCustomBackArrowModeMethod, sub);
|
|
626
644
|
const getCustomBackArrowModePromise = promisifyMethod(getCustomBackArrowMode, getCustomBackArrowModeMethod, sub);
|
|
627
645
|
const setCustomBackArrowVisiblePromise = promisifyMethod(setCustomBackArrowVisible, setCustomBackArrowVisibleMethod, sub);
|
|
646
|
+
const openPaymentPromise = promisifyMethod(openPayment, openPaymentMethod, sub);
|
|
647
|
+
const checkBiometryPromise = promisifyMethod(checkBiometry, checkBiometryMethod, sub);
|
|
628
648
|
|
|
629
649
|
return {
|
|
630
650
|
version: String(LIB_VERSION),
|
|
@@ -662,7 +682,9 @@ const buildBridge = (): AituBridge => {
|
|
|
662
682
|
setCustomBackArrowMode: setCustomBackArrowModePromise,
|
|
663
683
|
getCustomBackArrowMode: getCustomBackArrowModePromise,
|
|
664
684
|
setCustomBackArrowVisible: setCustomBackArrowVisiblePromise,
|
|
685
|
+
openPayment: openPaymentPromise,
|
|
665
686
|
setCustomBackArrowOnClickHandler,
|
|
687
|
+
checkBiometry: checkBiometryPromise,
|
|
666
688
|
}
|
|
667
689
|
}
|
|
668
690
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "0.3.
|
|
1
|
+
export const LIB_VERSION = "0.3.5";
|
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
|
}
|