@kbapp/js-bridge 1.0.2-alpha.0 → 1.0.3-alpha.0
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/README.MD +49 -49
- package/dist/index.es.js +50 -50
- package/dist/index.umd.js +1 -1
- package/dist/lib/trigger-login.d.ts +4 -5
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -87,7 +87,7 @@ async function saveImageHandle() {
|
|
|
87
87
|
| 62 | `saveImageToLocal` | 保存图片到本地 |
|
|
88
88
|
| 63 | `saveVideoToLocal` | 保存视频到本地 |
|
|
89
89
|
| 69 | `reportDAEvent` | 上报数据埋点 |
|
|
90
|
-
| - | `
|
|
90
|
+
| - | `onLoopCheckAppLogin` | 监听登录成功回调 |
|
|
91
91
|
| 31 | `getAppLoginInfo` | 获取 app 登录信息 |
|
|
92
92
|
| 31 | `triggerAppLogin` | 触发 app 登录 |
|
|
93
93
|
| 71 | `setScreenOrientation` | 设置屏幕方向 |
|
|
@@ -598,9 +598,53 @@ const stopHandle = onAppSharePanelShow(() => {
|
|
|
598
598
|
|
|
599
599
|
---
|
|
600
600
|
|
|
601
|
-
###
|
|
601
|
+
### triggerAppLogin
|
|
602
|
+
|
|
603
|
+
> 触发 app 登录
|
|
604
|
+
|
|
605
|
+
#### 请求参数
|
|
606
|
+
|
|
607
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
608
|
+
| ---------- | ----------------------------- | ---- | -------- |
|
|
609
|
+
| `success` | `() => void` | 否 | 成功回调 |
|
|
610
|
+
| `fail` | `(error: BridgeCode) => void` | 否 | 失败回调 |
|
|
611
|
+
| `complete` | `() => void` | 否 | 完成回调 |
|
|
612
|
+
|
|
613
|
+
#### 返回值
|
|
614
|
+
|
|
615
|
+
```js
|
|
616
|
+
Promise<void>
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
#### 示例代码
|
|
620
|
+
|
|
621
|
+
```js
|
|
622
|
+
import { triggerAppLogin, onLoopCheckAppLogin } from '@kbapp/js-bridge'
|
|
623
|
+
|
|
624
|
+
// 监听登录成功
|
|
625
|
+
const handle = onLoopCheckAppLogin((loginInfo) => {
|
|
626
|
+
console.log('登录成功', loginInfo)
|
|
627
|
+
handle() // 停止监听
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
// 触发登录
|
|
631
|
+
triggerAppLogin({
|
|
632
|
+
success() {
|
|
633
|
+
console.log('触发登录成功')
|
|
634
|
+
},
|
|
635
|
+
fail(error) {
|
|
636
|
+
console.log('触发登录失败', error)
|
|
637
|
+
},
|
|
638
|
+
})
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
> 支持 Promise 风格调用
|
|
642
|
+
|
|
643
|
+
---
|
|
644
|
+
|
|
645
|
+
### onLoopCheckAppLogin
|
|
602
646
|
|
|
603
|
-
>
|
|
647
|
+
> 启动轮询检查 APP 登录状态,查询到已登录后立即触发回调并自动回收回调函数(支持主动取消监听)
|
|
604
648
|
|
|
605
649
|
#### 请求参数
|
|
606
650
|
|
|
@@ -618,9 +662,9 @@ const stopHandle = onAppSharePanelShow(() => {
|
|
|
618
662
|
#### 示例代码
|
|
619
663
|
|
|
620
664
|
```js
|
|
621
|
-
import {
|
|
665
|
+
import { onLoopCheckAppLogin } from '@kbapp/js-bridge'
|
|
622
666
|
|
|
623
|
-
const handle =
|
|
667
|
+
const handle = onLoopCheckAppLogin((loginInfo) => {
|
|
624
668
|
console.log('登录成功', loginInfo)
|
|
625
669
|
})
|
|
626
670
|
|
|
@@ -1023,50 +1067,6 @@ subscribeNotify({
|
|
|
1023
1067
|
|
|
1024
1068
|
---
|
|
1025
1069
|
|
|
1026
|
-
### triggerAppLogin
|
|
1027
|
-
|
|
1028
|
-
> 触发 app 登录
|
|
1029
|
-
|
|
1030
|
-
#### 请求参数
|
|
1031
|
-
|
|
1032
|
-
| 参数 | 类型 | 必填 | 说明 |
|
|
1033
|
-
| ---------- | ----------------------------- | ---- | -------- |
|
|
1034
|
-
| `success` | `() => void` | 否 | 成功回调 |
|
|
1035
|
-
| `fail` | `(error: BridgeCode) => void` | 否 | 失败回调 |
|
|
1036
|
-
| `complete` | `() => void` | 否 | 完成回调 |
|
|
1037
|
-
|
|
1038
|
-
#### 返回值
|
|
1039
|
-
|
|
1040
|
-
```js
|
|
1041
|
-
Promise<void>
|
|
1042
|
-
```
|
|
1043
|
-
|
|
1044
|
-
#### 示例代码
|
|
1045
|
-
|
|
1046
|
-
```js
|
|
1047
|
-
import { triggerAppLogin, onAppLoginSuccess } from '@kbapp/js-bridge'
|
|
1048
|
-
|
|
1049
|
-
// 监听登录成功
|
|
1050
|
-
const handle = onAppLoginSuccess((loginInfo) => {
|
|
1051
|
-
console.log('登录成功', loginInfo)
|
|
1052
|
-
handle() // 停止监听
|
|
1053
|
-
})
|
|
1054
|
-
|
|
1055
|
-
// 触发登录
|
|
1056
|
-
triggerAppLogin({
|
|
1057
|
-
success() {
|
|
1058
|
-
console.log('触发登录成功')
|
|
1059
|
-
},
|
|
1060
|
-
fail(error) {
|
|
1061
|
-
console.log('触发登录失败', error)
|
|
1062
|
-
},
|
|
1063
|
-
})
|
|
1064
|
-
```
|
|
1065
|
-
|
|
1066
|
-
> 支持 Promise 风格调用
|
|
1067
|
-
|
|
1068
|
-
---
|
|
1069
|
-
|
|
1070
1070
|
### isAppVersionSupport
|
|
1071
1071
|
|
|
1072
1072
|
> 判断当前版本号是否支持
|
package/dist/index.es.js
CHANGED
|
@@ -27,15 +27,15 @@ l.UNKNOWN = new l({
|
|
|
27
27
|
});
|
|
28
28
|
let p = l;
|
|
29
29
|
const C = () => {
|
|
30
|
-
const e = (
|
|
30
|
+
const e = (s, o, n) => {
|
|
31
31
|
var a = "";
|
|
32
|
-
typeof
|
|
33
|
-
var d = { data:
|
|
32
|
+
typeof o == "function" && (n = o, o = {});
|
|
33
|
+
var d = { data: o === void 0 ? null : o };
|
|
34
34
|
if (typeof n == "function") {
|
|
35
35
|
var f = "dscb" + window.dscb++;
|
|
36
36
|
window[f] = n, d._dscbstub = f;
|
|
37
37
|
}
|
|
38
|
-
if (d = JSON.stringify(d), window.flutter_inappwebview ? window.flutter_inappwebview.callHandler && (a = window.flutter_inappwebview.callHandler("" +
|
|
38
|
+
if (d = JSON.stringify(d), window.flutter_inappwebview ? window.flutter_inappwebview.callHandler && (a = window.flutter_inappwebview.callHandler("" + s, d)) : (window._dswk || navigator.userAgent.indexOf("_dsbridge") != -1) && (a = prompt("_flutterDsbridge=" + s, d)), a instanceof Promise)
|
|
39
39
|
return a;
|
|
40
40
|
try {
|
|
41
41
|
return JSON.parse(a || "{}").data;
|
|
@@ -43,34 +43,34 @@ const C = () => {
|
|
|
43
43
|
console.error("callHandle异常,JSON.parse错误");
|
|
44
44
|
}
|
|
45
45
|
}, t = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, r = (() => {
|
|
46
|
-
const
|
|
47
|
-
t() && (clearInterval(
|
|
46
|
+
const s = [], o = setInterval(() => {
|
|
47
|
+
t() && (clearInterval(o), s.forEach((n) => {
|
|
48
48
|
e.apply(window, n);
|
|
49
|
-
}),
|
|
49
|
+
}), s.length = 0);
|
|
50
50
|
}, 500);
|
|
51
51
|
return (...n) => {
|
|
52
|
-
|
|
52
|
+
s.push(n);
|
|
53
53
|
};
|
|
54
54
|
})();
|
|
55
55
|
var i = {
|
|
56
56
|
default: void 0,
|
|
57
57
|
// for typescript
|
|
58
|
-
callHandler: function(
|
|
59
|
-
return t() ? e(
|
|
58
|
+
callHandler: function(s, o, n) {
|
|
59
|
+
return t() ? e(s, o, n) : r(s, o, n);
|
|
60
60
|
},
|
|
61
|
-
register: function(
|
|
61
|
+
register: function(s, o, n) {
|
|
62
62
|
var a = n ? window._dsaf : window._dsf;
|
|
63
63
|
window._dsInit || (window._dsInit = !0, setTimeout(function() {
|
|
64
64
|
i.callHandler("_dsb.dsinit");
|
|
65
|
-
}, 0)), typeof
|
|
65
|
+
}, 0)), typeof o == "object" ? a._obs[s] = o : a[s] = o;
|
|
66
66
|
},
|
|
67
|
-
registerHandler: function(
|
|
68
|
-
this.register(
|
|
67
|
+
registerHandler: function(s, o) {
|
|
68
|
+
this.register(s, o, !0);
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
return function() {
|
|
72
72
|
if (!window._dsf) {
|
|
73
|
-
var
|
|
73
|
+
var s = {
|
|
74
74
|
//保存JS同步方法
|
|
75
75
|
_dsf: {
|
|
76
76
|
_obs: {}
|
|
@@ -85,12 +85,12 @@ const C = () => {
|
|
|
85
85
|
var a = JSON.parse(n.data), d = {
|
|
86
86
|
id: n.callbackId,
|
|
87
87
|
complete: !0
|
|
88
|
-
}, f = this._dsf[n.method], A = this._dsaf[n.method], R = function(b,
|
|
89
|
-
d.data = b.apply(
|
|
90
|
-
}, T = function(b,
|
|
88
|
+
}, f = this._dsf[n.method], A = this._dsaf[n.method], R = function(b, O) {
|
|
89
|
+
d.data = b.apply(O, a), i.callHandler("_dsb.returnValue", d);
|
|
90
|
+
}, T = function(b, O) {
|
|
91
91
|
a.push(function(V, U) {
|
|
92
92
|
d.data = V, d.complete = U !== !1, i.callHandler("_dsb.returnValue", d);
|
|
93
|
-
}), b.apply(
|
|
93
|
+
}), b.apply(O, a);
|
|
94
94
|
};
|
|
95
95
|
if (f)
|
|
96
96
|
R(f, this._dsf);
|
|
@@ -111,13 +111,13 @@ const C = () => {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
|
-
for (var
|
|
115
|
-
window[
|
|
114
|
+
for (var o in s)
|
|
115
|
+
window[o] = s[o];
|
|
116
116
|
}
|
|
117
117
|
}(), i;
|
|
118
118
|
};
|
|
119
119
|
var I;
|
|
120
|
-
const
|
|
120
|
+
const S = ((e) => /(kb)/i.test(e) ? C() : {
|
|
121
121
|
registerHandler(t, r) {
|
|
122
122
|
throw p.UNSUPPORTED_BRIDGE_ENV;
|
|
123
123
|
},
|
|
@@ -125,40 +125,40 @@ const O = ((e) => /(kb)/i.test(e) ? C() : {
|
|
|
125
125
|
throw p.UNSUPPORTED_BRIDGE_ENV;
|
|
126
126
|
}
|
|
127
127
|
})((I = window == null ? void 0 : window.navigator) == null ? void 0 : I.userAgent), N = (e) => new Promise((t, r) => {
|
|
128
|
-
var i,
|
|
128
|
+
var i, s, o;
|
|
129
129
|
try {
|
|
130
|
-
|
|
130
|
+
S.registerHandler(e.name, e.handler), (i = e.success) == null || i.call(e), t();
|
|
131
131
|
} catch (n) {
|
|
132
|
-
(
|
|
132
|
+
(s = e.fail) == null || s.call(e, n), r(n);
|
|
133
133
|
} finally {
|
|
134
|
-
(
|
|
134
|
+
(o = e.complete) == null || o.call(e);
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
function w(e) {
|
|
138
138
|
const t = (r) => {
|
|
139
139
|
let i;
|
|
140
|
-
const
|
|
140
|
+
const s = (n) => {
|
|
141
141
|
var a;
|
|
142
142
|
(!i || i === "success") && (i = "success", (a = r.success) == null || a.call(r, n));
|
|
143
|
-
},
|
|
143
|
+
}, o = (n) => {
|
|
144
144
|
var a;
|
|
145
145
|
(!i || i === "error") && (i = "error", (a = r.fail) == null || a.call(r, n));
|
|
146
146
|
};
|
|
147
147
|
r.timeout && setTimeout(() => {
|
|
148
|
-
|
|
148
|
+
o(p.TIMEOUT);
|
|
149
149
|
}, r.timeout);
|
|
150
150
|
try {
|
|
151
|
-
|
|
151
|
+
S.callHandler(r.name, r.params, (n) => {
|
|
152
152
|
let a;
|
|
153
153
|
try {
|
|
154
154
|
typeof n == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(n) ? a = JSON.parse(n.replace(/\n/g, "\\n").replace(/\r/g, "\\r")) : a = n;
|
|
155
155
|
} catch {
|
|
156
156
|
a = n;
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
s(a);
|
|
159
159
|
});
|
|
160
160
|
} catch (n) {
|
|
161
|
-
|
|
161
|
+
o(n);
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
164
|
return new Promise((r, i) => {
|
|
@@ -166,33 +166,33 @@ function w(e) {
|
|
|
166
166
|
name: e.name,
|
|
167
167
|
params: q(e.params),
|
|
168
168
|
timeout: e.timeout,
|
|
169
|
-
success: (
|
|
170
|
-
var
|
|
171
|
-
(
|
|
169
|
+
success: (s) => {
|
|
170
|
+
var o, n;
|
|
171
|
+
(o = e.success) == null || o.call(e, s), (n = e.complete) == null || n.call(e), r(s);
|
|
172
172
|
},
|
|
173
|
-
fail: (
|
|
174
|
-
var
|
|
175
|
-
(
|
|
173
|
+
fail: (s) => {
|
|
174
|
+
var o, n;
|
|
175
|
+
(o = e.fail) == null || o.call(e, s), (n = e.complete) == null || n.call(e), i(s);
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
function u(e) {
|
|
181
|
-
|
|
181
|
+
S.callHandler(e.name, e.params, (t) => {
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
function c(e) {
|
|
185
185
|
return async function(...r) {
|
|
186
|
-
const i = r[0] || {}, { success:
|
|
186
|
+
const i = r[0] || {}, { success: s, fail: o, complete: n, ...a } = i;
|
|
187
187
|
try {
|
|
188
188
|
const d = await Promise.resolve(e(a));
|
|
189
|
-
return
|
|
189
|
+
return s == null || s(d), d;
|
|
190
190
|
} catch (d) {
|
|
191
191
|
const f = d != null && d.errorCode ? d : new p({
|
|
192
192
|
errorCode: p.UNKNOWN.errorCode,
|
|
193
193
|
errorMsg: String(d)
|
|
194
194
|
});
|
|
195
|
-
throw
|
|
195
|
+
throw o == null || o(f), f;
|
|
196
196
|
} finally {
|
|
197
197
|
n == null || n();
|
|
198
198
|
}
|
|
@@ -382,12 +382,12 @@ const z = c(
|
|
|
382
382
|
), _ = "SHARE_EVENT_NAME";
|
|
383
383
|
class ie {
|
|
384
384
|
}
|
|
385
|
-
const
|
|
385
|
+
const oe = c((e) => N({
|
|
386
386
|
name: "CommonShare",
|
|
387
387
|
handler(t, r) {
|
|
388
388
|
window.dispatchEvent(new Event(_)), "onShareApp" in e && e.onShareApp ? r({ type: 12, data: e.onShareApp() }) : r({ type: 12, data: e });
|
|
389
389
|
}
|
|
390
|
-
})),
|
|
390
|
+
})), se = c(async (e) => {
|
|
391
391
|
window.dispatchEvent(new Event(_)), u({
|
|
392
392
|
name: "OpenActRequest",
|
|
393
393
|
params: {
|
|
@@ -435,13 +435,13 @@ const x = c(async () => (await w({
|
|
|
435
435
|
})).data || null), y = /* @__PURE__ */ (() => {
|
|
436
436
|
const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ (() => {
|
|
437
437
|
let r;
|
|
438
|
-
const i = (
|
|
438
|
+
const i = (s) => {
|
|
439
439
|
r = setTimeout(async () => {
|
|
440
440
|
const n = await x();
|
|
441
441
|
if (!n)
|
|
442
|
-
return i(++
|
|
442
|
+
return i(++s);
|
|
443
443
|
e.forEach((a) => a(n)), e.clear();
|
|
444
|
-
}, ((n) => n === 0 ? 0 : n < 50 ? 600 : n < 80 ? 1e3 : 5e3)(
|
|
444
|
+
}, ((n) => n === 0 ? 0 : n < 50 ? 600 : n < 80 ? 1e3 : 5e3)(s));
|
|
445
445
|
};
|
|
446
446
|
return {
|
|
447
447
|
start() {
|
|
@@ -489,7 +489,7 @@ export {
|
|
|
489
489
|
K as closeWebView,
|
|
490
490
|
$ as createPostEditorParams,
|
|
491
491
|
B as decorateAppVersionSupport,
|
|
492
|
-
|
|
492
|
+
oe as defineAppShareModel,
|
|
493
493
|
ce as defineAppSharePanelState,
|
|
494
494
|
N as defineBridgeCallback,
|
|
495
495
|
F as definePermissionUsage,
|
|
@@ -498,9 +498,9 @@ export {
|
|
|
498
498
|
x as getAppLoginInfo,
|
|
499
499
|
de as getAppSubscribeNotifyStatus,
|
|
500
500
|
L as isAppVersionSupport,
|
|
501
|
-
fe as onAppLoginSuccess,
|
|
502
501
|
ae as onAppSharePanelShow,
|
|
503
|
-
|
|
502
|
+
fe as onLoopCheckAppLogin,
|
|
503
|
+
se as openAppSharePanel,
|
|
504
504
|
ue as openAppSubscribeNotifySettings,
|
|
505
505
|
z as openPostEditor,
|
|
506
506
|
Q as reportDAEvent,
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var q;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const o=e[i];o!=null&&(t[i]=Object.prototype.toString.call(o)==="[object Object]"?A(o):o)}),t}const f=class f{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};f.UNKNOWN=new f({errorCode:1e3,errorMsg:"未知错误"}),f.UNSUPPORTED_VERSION=new f({errorCode:1001,errorMsg:"当前开吧版本不支持"}),f.TIMEOUT=new f({errorCode:1002,errorMsg:"执行超时"}),f.UNSUPPORTED_BRIDGE_ENV=new f({errorCode:1003,errorMsg:"请在开吧app内执行"});let p=f;const H=()=>{const e=(a,s,n)=>{var c="";typeof s=="function"&&(n=s,s={});var u={data:s===void 0?null:s};if(typeof n=="function"){var h="dscb"+window.dscb++;window[h]=n,u._dscbstub=h}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+a,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+a,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const a=[],s=setInterval(()=>{t()&&(clearInterval(s),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var o={default:void 0,callHandler:function(a,s,n){return t()?e(a,s,n):i(a,s,n)},register:function(a,s,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof s=="object"?c._obs[a]=s:c[a]=s},registerHandler:function(a,s){this.register(a,s,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],b=this._dsaf[n.method],U=function(P,E){u.data=P.apply(E,c),o.callHandler("_dsb.returnValue",u)},C=function(P,E){c.push(function(fe,ge){u.data=fe,u.complete=ge!==!1,o.callHandler("_dsb.returnValue",u)}),P.apply(E,c)};if(h)U(h,this._dsf);else if(b)C(b,this._dsaf);else{var T=n.method.split(".");if(T.length<2)return;var
|
|
1
|
+
(function(r,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(r=typeof globalThis<"u"?globalThis:r||self,A(r.kbBridge={}))})(this,function(r){"use strict";var q;function A(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const t={};return Object.keys(e).forEach(i=>{const o=e[i];o!=null&&(t[i]=Object.prototype.toString.call(o)==="[object Object]"?A(o):o)}),t}const f=class f{constructor(t){this.errorCode=t.errorCode,this.errorMsg=t.errorMsg}};f.UNKNOWN=new f({errorCode:1e3,errorMsg:"未知错误"}),f.UNSUPPORTED_VERSION=new f({errorCode:1001,errorMsg:"当前开吧版本不支持"}),f.TIMEOUT=new f({errorCode:1002,errorMsg:"执行超时"}),f.UNSUPPORTED_BRIDGE_ENV=new f({errorCode:1003,errorMsg:"请在开吧app内执行"});let p=f;const H=()=>{const e=(a,s,n)=>{var c="";typeof s=="function"&&(n=s,s={});var u={data:s===void 0?null:s};if(typeof n=="function"){var h="dscb"+window.dscb++;window[h]=n,u._dscbstub=h}if(u=JSON.stringify(u),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(c=window.flutter_inappwebview.callHandler(""+a,u)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(c=prompt("_flutterDsbridge="+a,u)),c instanceof Promise)return c;try{return JSON.parse(c||"{}").data}catch{console.error("callHandle异常,JSON.parse错误")}},t=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,i=(()=>{const a=[],s=setInterval(()=>{t()&&(clearInterval(s),a.forEach(n=>{e.apply(window,n)}),a.length=0)},500);return(...n)=>{a.push(n)}})();var o={default:void 0,callHandler:function(a,s,n){return t()?e(a,s,n):i(a,s,n)},register:function(a,s,n){var c=n?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){o.callHandler("_dsb.dsinit")},0)),typeof s=="object"?c._obs[a]=s:c[a]=s},registerHandler:function(a,s){this.register(a,s,!0)}};return function(){if(!window._dsf){var a={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:o,_handleMessageFromNative:function(n){var c=JSON.parse(n.data),u={id:n.callbackId,complete:!0},h=this._dsf[n.method],b=this._dsaf[n.method],U=function(P,E){u.data=P.apply(E,c),o.callHandler("_dsb.returnValue",u)},C=function(P,E){c.push(function(fe,ge){u.data=fe,u.complete=ge!==!1,o.callHandler("_dsb.returnValue",u)}),P.apply(E,c)};if(h)U(h,this._dsf);else if(b)C(b,this._dsaf);else{var T=n.method.split(".");if(T.length<2)return;var L=T.pop(),M=T.join("."),O=this._dsf._obs,_=O[M]||{},w=_[L];if(w&&typeof w=="function"){U(w,_);return}if(O=this._dsaf._obs,_=O[M]||{},w=_[L],w&&typeof w=="function"){C(w,_);return}}}};for(var s in a)window[s]=a[s]}}(),o},v=(e=>/(kb)/i.test(e)?H():{registerHandler(t,i){throw p.UNSUPPORTED_BRIDGE_ENV},callHandler(t,i,o){throw p.UNSUPPORTED_BRIDGE_ENV}})((q=window==null?void 0:window.navigator)==null?void 0:q.userAgent),S=e=>new Promise((t,i)=>{var o,a,s;try{v.registerHandler(e.name,e.handler),(o=e.success)==null||o.call(e),t()}catch(n){(a=e.fail)==null||a.call(e,n),i(n)}finally{(s=e.complete)==null||s.call(e)}});function g(e){const t=i=>{let o;const a=n=>{var c;(!o||o==="success")&&(o="success",(c=i.success)==null||c.call(i,n))},s=n=>{var c;(!o||o==="error")&&(o="error",(c=i.fail)==null||c.call(i,n))};i.timeout&&setTimeout(()=>{s(p.TIMEOUT)},i.timeout);try{v.callHandler(i.name,i.params,n=>{let c;try{typeof n=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(n)?c=JSON.parse(n.replace(/\n/g,"\\n").replace(/\r/g,"\\r")):c=n}catch{c=n}a(c)})}catch(n){s(n)}};return new Promise((i,o)=>{t({name:e.name,params:A(e.params),timeout:e.timeout,success:a=>{var s,n;(s=e.success)==null||s.call(e,a),(n=e.complete)==null||n.call(e),i(a)},fail:a=>{var s,n;(s=e.fail)==null||s.call(e,a),(n=e.complete)==null||n.call(e),o(a)}})})}function l(e){v.callHandler(e.name,e.params,t=>{})}function d(e){return async function(...i){const o=i[0]||{},{success:a,fail:s,complete:n,...c}=o;try{const u=await Promise.resolve(e(c));return a==null||a(u),u}catch(u){const h=u!=null&&u.errorCode?u:new p({errorCode:p.UNKNOWN.errorCode,errorMsg:String(u)});throw s==null||s(h),h}finally{n==null||n()}}}function B(e){let t;return function(...i){return t||(t=e(...i),Promise.resolve(t).catch(()=>{t=void 0}),t)}}class D{}const R=d(B(()=>g({name:"OpenActRequest",params:{type:35,data:{}}}))),k=d(async e=>(await R()).vcode>=e.minVersion);function j(e,t){return(...i)=>k({minVersion:e.minVersion}).then(o=>o?t(...i):Promise.reject(new p({errorCode:p.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const K=d(()=>{l({name:"OpenActRequest",params:{type:56,data:null}})}),W=d(()=>{l({name:"OpenActRequest",params:{type:-1,data:{}}})}),I={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},F=d(e=>(Object.assign(I,e),S({name:"getPermissionUsage",handler(t,i){i(I[t.permission])}}))),J=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),G=d(async e=>{const{kbKey:t,...i}=e,{data:o}=await g({name:"OpenActRequest",params:{type:51,data:i}});return o});class V{constructor(){this.enableImageUpload=!0,this.enableAudioUpload=!0,this.enableVideoUpload=!0,this.enableAddress=!0,this.enableMediaVideoUpload=!1,this.minTextLength=0,this.maxTextLength=1e3,this.minImageCount=0,this.maxImageCount=9,this.isAudioRequired=!1,this.isVideoRequired=!1,this.isMediaVideoRequired=!1}}function $(e){const t=new V;return e&&Object.keys(e).forEach(o=>{t[o]=e[o]}),{hint:t.placeholder,initialText:t.initialText,audio:t.enableAudioUpload,image:t.enableImageUpload,video:t.enableVideoUpload,address:t.enableAddress,asset_video:t.enableMediaVideoUpload,text_must:t.minTextLength>0,content_min_length:t.minTextLength,content_max_length:t.maxTextLength,image_must:t.minImageCount>0,min_image_count:t.minImageCount,max_image_count:t.maxImageCount,audio_must:t.isAudioRequired,video_must:t.isVideoRequired,asset_video_must:t.isMediaVideoRequired}}const z=d(async(e={})=>g({name:"OpenActRequest",params:{type:13,data:e}}).then(({data:t})=>{const{pic:i,...o}=t;return{images:i,...o}})),Q=d(e=>{l({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),X=d(e=>{l({name:"OpenActRequest",params:{type:1001,data:e}})}),Y=d(e=>{l({name:"OpenActRequest",params:{type:62,data:e}})}),Z=d(e=>{l({name:"OpenActRequest",params:{type:63,data:e}})}),x=d(()=>g({name:"OpenActRequest",params:{type:26,data:{}}})),ee=d(e=>{l({name:"OpenActRequest",params:{type:71,data:e}})}),te=d(e=>{l({name:"OpenActRequest",params:{type:64,data:e}})}),ne=d(e=>{l({name:"OpenActRequest",params:{type:58,data:e}})}),m="SHARE_EVENT_NAME";class ie{}const re=d(e=>S({name:"CommonShare",handler(t,i){window.dispatchEvent(new Event(m)),"onShareApp"in e&&e.onShareApp?i({type:12,data:e.onShareApp()}):i({type:12,data:e})}})),oe=d(async e=>{window.dispatchEvent(new Event(m)),l({name:"OpenActRequest",params:{type:58,data:e}})});function se(e){return window.addEventListener(m,e),()=>{window.removeEventListener(m,e)}}const ae=d(e=>{l({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),ce=d(()=>g({name:"OpenActRequest",params:{type:72}})),de=d(async()=>{l({name:"OpenActRequest",params:{type:73}})});class ue{}const N=d(async()=>(await g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!1}}})).data||null),y=(()=>{const e=new Set,t=(()=>{let i;const o=a=>{i=setTimeout(async()=>{const n=await N();if(!n)return o(++a);e.forEach(c=>c(n)),e.clear()},(n=>n===0?0:n<50?600:n<80?1e3:5e3)(a))};return{start(){i&&clearTimeout(i),e.size>0&&o(0)},stop(){i&&clearTimeout(i)}}})();return{addTask(i){e.add(i)},removeTask(i){e.delete(i),e.size===0&&t.stop()},triggerCheckTask(){t.start()}}})(),le=d(async()=>{y.triggerCheckTask(),g({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}},success(e){var t;(t=e.data)!=null&&t.userId&&y.triggerCheckTask()}})}),pe=e=>(y.addTask(e),y.triggerCheckTask(),()=>{y.removeTask(e)});r.AppBaseInfo=D,r.AppLoginInfo=ue,r.AppShareModel=ie,r.BridgeCode=p,r.IS_KB_APP_ENV=J,r.PostEditorParams=V,r.checkForNewVersion=K,r.closeWebView=W,r.createPostEditorParams=$,r.decorateAppVersionSupport=j,r.defineAppShareModel=re,r.defineAppSharePanelState=ae,r.defineBridgeCallback=S,r.definePermissionUsage=F,r.generateKBSign=G,r.getAppBaseInfo=R,r.getAppLoginInfo=N,r.getAppSubscribeNotifyStatus=ce,r.isAppVersionSupport=k,r.onAppSharePanelShow=se,r.onLoopCheckAppLogin=pe,r.openAppSharePanel=oe,r.openAppSubscribeNotifySettings=de,r.openPostEditor=z,r.reportDAEvent=Q,r.runAction=X,r.runBridgeApi=l,r.runBridgeApiResponse=g,r.saveImageToLocal=Y,r.saveVideoToLocal=Z,r.scanQRCode=x,r.setScreenOrientation=ee,r.setWebViewTitle=te,r.shareImage=ne,r.triggerAppLogin=le,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -45,17 +45,16 @@ export declare const triggerAppLogin: (params?: {
|
|
|
45
45
|
} | undefined) => Promise<void>;
|
|
46
46
|
/**
|
|
47
47
|
*
|
|
48
|
-
* @description
|
|
49
|
-
* 如果已登录, 立刻触发一次回调
|
|
48
|
+
* @description 启动轮询检查 APP 登录状态,查询到已登录后立即触发回调并自动回收回调函数(支持主动取消监听)
|
|
50
49
|
* @example **示例代码**
|
|
51
50
|
```js
|
|
52
|
-
import {
|
|
51
|
+
import { onLoopCheckAppLogin } from '@kbapp/js-bridge';
|
|
53
52
|
|
|
54
|
-
const handle =
|
|
53
|
+
const handle = onLoopCheckAppLogin(() => {
|
|
55
54
|
console.log('登录成功')
|
|
56
55
|
})
|
|
57
56
|
|
|
58
57
|
// handle() 停止监听
|
|
59
58
|
```
|
|
60
59
|
*/
|
|
61
|
-
export declare const
|
|
60
|
+
export declare const onLoopCheckAppLogin: (callback: (loginInfo: AppLoginInfo) => void) => () => void;
|