@r2d2cn/rk-bridge 1.0.0 → 1.1.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/base.d.ts +9 -0
- package/index.cjs.js +1 -1
- package/index.esm.js +305 -266
- package/index.umd.js +1 -1
- package/lock-screen.d.ts +4 -0
- package/package.json +1 -1
- package/rokid/index.d.ts +3 -0
- package/zjt/index.d.ts +3 -0
package/base.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ export interface IRKBridge {
|
|
|
54
54
|
* success 表示眼镜端已确认生效;Native 未合入时 reject(-999)。
|
|
55
55
|
*/
|
|
56
56
|
setBootApp(packageName: string): Promise<void>;
|
|
57
|
+
/** 显示手机假锁屏。无悬浮窗权限时 reject `overlay_permission_denied`;Native 未注入时 reject -999。 */
|
|
58
|
+
showLockScreen(): Promise<void>;
|
|
59
|
+
/** 关闭手机假锁屏。 */
|
|
60
|
+
dismissLockScreen(): Promise<void>;
|
|
61
|
+
/** 假锁屏是否正在显示。 */
|
|
62
|
+
isLockScreenShowing(): Promise<boolean>;
|
|
57
63
|
on<T>(event: BridgeEventType, callback: (data: T) => void): void;
|
|
58
64
|
off(event: BridgeEventType, callback: (data: any) => void): void;
|
|
59
65
|
}
|
|
@@ -112,6 +118,9 @@ export declare abstract class BaseBridge {
|
|
|
112
118
|
abstract subscribeAppProgress(): Promise<void>;
|
|
113
119
|
abstract unsubscribeAppProgress(): Promise<void>;
|
|
114
120
|
abstract setBootApp(packageName: string): Promise<void>;
|
|
121
|
+
abstract showLockScreen(): Promise<void>;
|
|
122
|
+
abstract dismissLockScreen(): Promise<void>;
|
|
123
|
+
abstract isLockScreenShowing(): Promise<boolean>;
|
|
115
124
|
on<T>(event: BridgeEventType, callback: (data: T) => void): void;
|
|
116
125
|
off(event: BridgeEventType, callback: (data: any) => void): void;
|
|
117
126
|
}
|
package/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var S=Object.defineProperty;var y=(r,n,t)=>n in r?S(r,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[n]=t;var e=(r,n,t)=>y(r,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("uuid"),v=require("eventemitter3"),A="1048576-10772480",L="66D9EF553887B5054FFC4AC1CB2CB590",m=window.lx;function I(){return new Promise((r,n)=>{console.log("获取 authCode 参数 appId: ",A),m.biz.getAuthCode({appId:A,success:function(t){console.log("获取 authCode 成功",t),r(t)},fail:function(t){console.log("获取 authCode 失败",t),n(t)}})})}class _{constructor(n){e(this,"baseURL");e(this,"baseRequest");this.baseURL=(n==null?void 0:n.baseURL)||"",this.baseRequest=(n==null?void 0:n.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(n){try{const{statusCode:t,body:s}=await this.baseRequest(JSON.stringify(n));console.log("native http response:",t,s);const i=JSON.parse(s);if(i.errCode===0)return i.data;throw new Error(i.errMsg||"未知错误")}catch(t){throw console.warn("native http request error:",t),t}}get(n,t){return this.httpRequest({method:"GET",url:this.baseURL+n,queryParams:t==null?void 0:t.params,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}})}post(n,t){return this.httpRequest({method:"POST",url:this.baseURL+n,body:t==null?void 0:t.data,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}})}}var P,T;const R=new _({baseURL:"http://20.65.2.12:10443/open/apigw",baseRequest:typeof window<"u"&&((T=(P=window==null?void 0:window.RKBridge)==null?void 0:P.Http)==null?void 0:T.request)||void 0});class N{constructor(n){e(this,"baseURL");e(this,"baseRequest");this.baseURL=(n==null?void 0:n.baseURL)||"",this.baseRequest=(n==null?void 0:n.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(n){try{const{statusCode:t,body:s}=await this.baseRequest(JSON.stringify(n));console.log("native http response:",t,s);const i=JSON.parse(s);if(i.resultCode===0)return i;throw new Error(i.message||"未知错误")}catch(t){throw console.warn("native http request error:",t),t}}get(n,t){return this.httpRequest({method:"GET",url:this.baseURL+n,queryParams:t==null?void 0:t.params,headers:{...(t==null?void 0:t.headers)??{}}})}post(n,t){return this.httpRequest({method:"POST",url:this.baseURL+n,body:t==null?void 0:t.data,headers:{...(t==null?void 0:t.headers)??{}}})}}var b,k;new N({baseURL:"http://20.65.1.157",baseRequest:typeof window<"u"&&((k=(b=window==null?void 0:window.RKBridge)==null?void 0:b.Http)==null?void 0:k.request)||void 0});function D(){return R.get("/v1/apptoken/create",{params:{grant_type:"client_credential",appid:A,secret:L}})}function q(r,n){return R.get("/v1/usertoken/create",{params:{grant_type:"authorization_code",app_token:n,code:r}})}function M(r,n){return R.get("/v1/users/fetch",{params:{user_token:n,app_token:r}})}class f{constructor(){e(this,"emitter",new v);e(this,"hasBackground",!1);this.initCallback(),this.initNativeEventListener()}on(n,t){this.emitter.on(n,t)}off(n,t){this.emitter.off(n,t)}}function E(r){window[r]&&(window.RKBridge=window[r],window.RKBridge_GlassBluetooth=window[r+"_GlassBluetooth"],window.RKBridge_GlassWifiP2P=window[r+"_GlassWifiP2P"],window.RKBridge_GlassAiChat=window[r+"_GlassAiChat"],window.RKBridge_GlassTranslation=window[r+"_GlassTranslation"],window.RKBridge_GlassAlbum=window[r+"_GlassAlbum"],window.RKBridge_GlassFileSystem=window[r+"_GlassFileSystem"],window.RKBridge_GlassMessage=window[r+"_GlassMessage"],window.RKBridge_GlassAppInstall=window[r+"_GlassAppInstall"],window.RKBridge_Http=window[r+"_Http"])}let O=class extends f{constructor(){super();e(this,"emitter",new v);e(this,"appToken","");e(this,"userToken","");e(this,"hasBackground",!1);e(this,"initSDK",this.generateBridgeFunc("initSDK"));e(this,"registerClientId",this.generateBridgeFunc("registerClientId"));e(this,"navigate",t=>(t+=(t.includes("?")?"&":"?")+"adjust_fullscreen_inset=true",t+="&rkbridge=true",console.log("跳转页面: ",t),window.lx.ui.openView({mode:"webview",navigationBarBackgroundColor:"#FFFFFF",navigationBarFrontStyle:"#0C120D",url:t,useSplitScreen:!1}),Promise.resolve()));e(this,"goBack",()=>(window.lx.ui.closeWindow(),Promise.resolve()));e(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));e(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));e(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));e(this,"getCredentials",()=>{try{const t=localStorage.getItem("appCredential")||"",s=localStorage.getItem("userCredential")||"",i={appCredential:t,userCredential:s};return Promise.resolve(i)}catch(t){return console.warn("获取解析 credentials 失败",t),Promise.resolve({})}});e(this,"getAuthCode",async()=>(await I()).authCode);e(this,"getUserInfo",async()=>{const t=await this.getAuthCode();console.log("获取 authCode 成功",t);const s=await this.getAppToken();console.log("获取 appToken 成功",s);const i=await this.getUserToken();return console.log("获取 userToken 成功",i),await M(s,i)});e(this,"getAppToken",async()=>{const t=await D();return this.appToken=t.appToken,t.appToken});e(this,"getUserToken",async()=>{const t=await this.getAuthCode(),s=this.appToken,i=await q(t,s);return this.userToken=i.userToken,i.userToken});e(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));e(this,"setVolume",this.generateBridgeFunc("setVolume"));e(this,"setBrightness",this.generateBridgeFunc("setBrightness"));e(this,"makePhone",this.generateBridgeFunc("makePhone"));e(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));e(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));e(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));e(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));e(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));e(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));e(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));e(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));e(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));e(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));e(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));e(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));e(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));e(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));e(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));e(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));e(this,"getDirectoryFileList",t=>this.getDirectoryFileListNative(JSON.stringify(t)));e(this,"httpRequest",this.generateBridgeFunc("request","Http"));e(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));e(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));e(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));e(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));e(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));e(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));e(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));e(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));e(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));e(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));e(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));e(this,"setBootApp",t=>{var i;const s=(i=window.RKBridge)==null?void 0:i.GlassAppInstall;return!s||typeof s.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(t)});e(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));e(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));e(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));e(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));e(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){E("BKBridge"),window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(s,i,a,g)=>{s&&this.emitter.emit(s,i,a,g)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall,window.RKBridge.Http=window.RKBridge_Http);const t=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(s,i,a,g)=>{t==null||t(s,i,a,g),s&&this.emitter.emit(s,i,a,g)}}generateBridgeFunc(t,s){return(...i)=>{var g;const a=s?(g=window.RKBridge)==null?void 0:g[s]:window.RKBridge;return!a||!a[t]?(console.warn(`Bridge method ${s?`${s}.`:""}${t} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((p,F)=>{var d,c,u,B;const l=`cb_${K.v4()}`;this.emitter.on(l,(h,o,w)=>{if(h.toLowerCase()==="success"){if(o)try{o=JSON.parse(o)}catch(G){console.warn("解析 callback 结果失败",G)}p(o)}else h.toLowerCase()==="error"&&F(w);this.emitter.off(l)}),s?(c=(d=window.RKBridge[s])[t])==null||c.call(d,...i,l):(B=(u=window.RKBridge)[t])==null||B.call(u,...i,l)})}}initNativeEventListener(){const t=(s,i)=>{this.emitter.emit(s,i.data)};if(window.dispatchNativeEvent){const s=window.dispatchNativeEvent;window.dispatchNativeEvent=(...i)=>{s(...i),t(...i)}}else window.dispatchNativeEvent=t}};const U=new O;class x extends f{constructor(){super(...arguments);e(this,"emitter",new v);e(this,"hasBackground",!0);e(this,"initSDK",this.generateBridgeFunc("initSDK"));e(this,"registerClientId",this.generateBridgeFunc("registerClientId"));e(this,"navigate",t=>(window.JSBridge.navigate(t),Promise.resolve()));e(this,"goBack",()=>(window.JSBridge.goBack(),Promise.resolve()));e(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));e(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));e(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));e(this,"getAuthCode",this.generateBridgeFunc("getAuthCode"));e(this,"getUserInfo",()=>window.JSBridge.getUserInfo());e(this,"getCredentials",()=>{var t,s;try{const i=JSON.parse((s=(t=window.JSBridge)==null?void 0:t.getCredentials)==null?void 0:s.call(t));return Promise.resolve(i)}catch(i){return console.warn("获取解析 credentials 失败",i),Promise.resolve({})}});e(this,"getAppToken",this.generateBridgeFunc("getAppToken"));e(this,"getUserToken",this.generateBridgeFunc("getUserToken"));e(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));e(this,"setVolume",this.generateBridgeFunc("setVolume"));e(this,"setBrightness",this.generateBridgeFunc("setBrightness"));e(this,"makePhone",this.generateBridgeFunc("makePhone"));e(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));e(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));e(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));e(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));e(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));e(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));e(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));e(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));e(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));e(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));e(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));e(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));e(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));e(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));e(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));e(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));e(this,"getDirectoryFileList",t=>this.getDirectoryFileListNative(JSON.stringify(t)));e(this,"httpRequest",this.generateBridgeFunc("request","Http"));e(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));e(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));e(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));e(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));e(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));e(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));e(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));e(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));e(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));e(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));e(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));e(this,"setBootApp",t=>{var i;const s=(i=window.RKBridge)==null?void 0:i.GlassAppInstall;return!s||typeof s.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(t)});e(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));e(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));e(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));e(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));e(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(s,i,a,g)=>{s&&this.emitter.emit(s,i,a,g)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall);const t=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(s,i,a,g)=>{t==null||t(s,i,a,g),s&&this.emitter.emit(s,i,a,g)}}generateBridgeFunc(t,s){return(...i)=>{var g;const a=s?(g=window.RKBridge)==null?void 0:g[s]:window.RKBridge;return!a||!a[t]?(console.warn(`Bridge method ${s?`${s}.`:""}${t} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((p,F)=>{var d,c,u,B;const l=`cb_${K.v4()}`;this.emitter.on(l,(h,o,w)=>{if(h.toLowerCase()==="success"){if(o)try{o=JSON.parse(o)}catch(G){console.warn("解析 callback 结果失败",G),console.log(t,s,o,w)}p(o)}else h.toLowerCase()==="error"&&F(w);this.emitter.off(l)}),s?(c=(d=window.RKBridge[s])[t])==null||c.call(d,...i,l):(B=(u=window.RKBridge)[t])==null||B.call(u,...i,l)})}}initNativeEventListener(){const t=(s,i)=>{this.emitter.emit(s,i.data)};if(window.dispatchNativeEvent){const s=window.dispatchNativeEvent;window.dispatchNativeEvent=(...i)=>{s(...i),t(...i)}}else window.dispatchNativeEvent=t}}const W=new x;var C;const J=((C=window==null?void 0:window.navigator)==null?void 0:C.userAgent)||"",H=J.includes("lanxin")?U:W;exports.BaseBridge=f;exports.rkBridge=H;
|
|
1
|
+
"use strict";var y=Object.defineProperty;var I=(r,s,e)=>s in r?y(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var t=(r,s,e)=>I(r,typeof s!="symbol"?s+"":s,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("uuid"),v=require("eventemitter3"),f="1048576-10772480",_="66D9EF553887B5054FFC4AC1CB2CB590",N=window.lx;function D(){return new Promise((r,s)=>{console.log("获取 authCode 参数 appId: ",f),N.biz.getAuthCode({appId:f,success:function(e){console.log("获取 authCode 成功",e),r(e)},fail:function(e){console.log("获取 authCode 失败",e),s(e)}})})}class q{constructor(s){t(this,"baseURL");t(this,"baseRequest");this.baseURL=(s==null?void 0:s.baseURL)||"",this.baseRequest=(s==null?void 0:s.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(s){try{const{statusCode:e,body:i}=await this.baseRequest(JSON.stringify(s));console.log("native http response:",e,i);const n=JSON.parse(i);if(n.errCode===0)return n.data;throw new Error(n.errMsg||"未知错误")}catch(e){throw console.warn("native http request error:",e),e}}get(s,e){return this.httpRequest({method:"GET",url:this.baseURL+s,queryParams:e==null?void 0:e.params,headers:{"Content-Type":"application/json",...(e==null?void 0:e.headers)??{}}})}post(s,e){return this.httpRequest({method:"POST",url:this.baseURL+s,body:e==null?void 0:e.data,headers:{"Content-Type":"application/json",...(e==null?void 0:e.headers)??{}}})}}var k,S;const R=new q({baseURL:"http://20.65.2.12:10443/open/apigw",baseRequest:typeof window<"u"&&((S=(k=window==null?void 0:window.RKBridge)==null?void 0:k.Http)==null?void 0:S.request)||void 0});class E{constructor(s){t(this,"baseURL");t(this,"baseRequest");this.baseURL=(s==null?void 0:s.baseURL)||"",this.baseRequest=(s==null?void 0:s.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(s){try{const{statusCode:e,body:i}=await this.baseRequest(JSON.stringify(s));console.log("native http response:",e,i);const n=JSON.parse(i);if(n.resultCode===0)return n;throw new Error(n.message||"未知错误")}catch(e){throw console.warn("native http request error:",e),e}}get(s,e){return this.httpRequest({method:"GET",url:this.baseURL+s,queryParams:e==null?void 0:e.params,headers:{...(e==null?void 0:e.headers)??{}}})}post(s,e){return this.httpRequest({method:"POST",url:this.baseURL+s,body:e==null?void 0:e.data,headers:{...(e==null?void 0:e.headers)??{}}})}}var b,T;new E({baseURL:"http://20.65.1.157",baseRequest:typeof window<"u"&&((T=(b=window==null?void 0:window.RKBridge)==null?void 0:b.Http)==null?void 0:T.request)||void 0});function M(){return R.get("/v1/apptoken/create",{params:{grant_type:"client_credential",appid:f,secret:_}})}function O(r,s){return R.get("/v1/usertoken/create",{params:{grant_type:"authorization_code",app_token:s,code:r}})}function U(r,s){return R.get("/v1/users/fetch",{params:{user_token:s,app_token:r}})}class P{constructor(){t(this,"emitter",new v);t(this,"hasBackground",!1);this.initCallback(),this.initNativeEventListener()}on(s,e){this.emitter.on(s,e)}off(s,e){this.emitter.off(s,e)}}const x=-999;function K(r){const s=window.JSBridge;if(s==null||s[r]==null)return Promise.reject(x);try{return s[r]()}catch(e){return console.warn(`${r} failed`,e),Promise.reject(-1)}}function p(r){const s=K(r);if(s instanceof Promise)return s;try{const e=typeof s=="string"?JSON.parse(s):s;return e!=null&&e.success?Promise.resolve():Promise.reject((e==null?void 0:e.code)??-1)}catch(e){return console.warn(`${r} failed`,e),Promise.reject(-1)}}function m(){const r=K("isLockScreenShowing");if(r instanceof Promise)return r;try{const s=typeof r=="string"?JSON.parse(r):r;return Promise.resolve(!!(s!=null&&s.showing))}catch(s){return console.warn("isLockScreenShowing failed",s),Promise.reject(-1)}}function W(r){window[r]&&(window.RKBridge=window[r],window.RKBridge_GlassBluetooth=window[r+"_GlassBluetooth"],window.RKBridge_GlassWifiP2P=window[r+"_GlassWifiP2P"],window.RKBridge_GlassAiChat=window[r+"_GlassAiChat"],window.RKBridge_GlassTranslation=window[r+"_GlassTranslation"],window.RKBridge_GlassAlbum=window[r+"_GlassAlbum"],window.RKBridge_GlassFileSystem=window[r+"_GlassFileSystem"],window.RKBridge_GlassMessage=window[r+"_GlassMessage"],window.RKBridge_GlassAppInstall=window[r+"_GlassAppInstall"],window.RKBridge_Http=window[r+"_Http"])}let J=class extends P{constructor(){super();t(this,"emitter",new v);t(this,"appToken","");t(this,"userToken","");t(this,"hasBackground",!1);t(this,"initSDK",this.generateBridgeFunc("initSDK"));t(this,"registerClientId",this.generateBridgeFunc("registerClientId"));t(this,"navigate",e=>(e+=(e.includes("?")?"&":"?")+"adjust_fullscreen_inset=true",e+="&rkbridge=true",console.log("跳转页面: ",e),window.lx.ui.openView({mode:"webview",navigationBarBackgroundColor:"#FFFFFF",navigationBarFrontStyle:"#0C120D",url:e,useSplitScreen:!1}),Promise.resolve()));t(this,"goBack",()=>(window.lx.ui.closeWindow(),Promise.resolve()));t(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));t(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));t(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));t(this,"getCredentials",()=>{try{const e=localStorage.getItem("appCredential")||"",i=localStorage.getItem("userCredential")||"",n={appCredential:e,userCredential:i};return Promise.resolve(n)}catch(e){return console.warn("获取解析 credentials 失败",e),Promise.resolve({})}});t(this,"getAuthCode",async()=>(await D()).authCode);t(this,"getUserInfo",async()=>{const e=await this.getAuthCode();console.log("获取 authCode 成功",e);const i=await this.getAppToken();console.log("获取 appToken 成功",i);const n=await this.getUserToken();return console.log("获取 userToken 成功",n),await U(i,n)});t(this,"getAppToken",async()=>{const e=await M();return this.appToken=e.appToken,e.appToken});t(this,"getUserToken",async()=>{const e=await this.getAuthCode(),i=this.appToken,n=await O(e,i);return this.userToken=n.userToken,n.userToken});t(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));t(this,"setVolume",this.generateBridgeFunc("setVolume"));t(this,"setBrightness",this.generateBridgeFunc("setBrightness"));t(this,"makePhone",this.generateBridgeFunc("makePhone"));t(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));t(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));t(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));t(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));t(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));t(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));t(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));t(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));t(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));t(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));t(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));t(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));t(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));t(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));t(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));t(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));t(this,"getDirectoryFileList",e=>this.getDirectoryFileListNative(JSON.stringify(e)));t(this,"httpRequest",this.generateBridgeFunc("request","Http"));t(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));t(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));t(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));t(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));t(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));t(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));t(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));t(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));t(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));t(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));t(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));t(this,"setBootApp",e=>{var n;const i=(n=window.RKBridge)==null?void 0:n.GlassAppInstall;return!i||typeof i.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(e)});t(this,"showLockScreen",()=>p("showLockScreen"));t(this,"dismissLockScreen",()=>p("dismissLockScreen"));t(this,"isLockScreenShowing",()=>m());t(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));t(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));t(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));t(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));t(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){W("BKBridge"),window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(i,n,a,g)=>{i&&this.emitter.emit(i,n,a,g)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall,window.RKBridge.Http=window.RKBridge_Http);const e=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(i,n,a,g)=>{e==null||e(i,n,a,g),i&&this.emitter.emit(i,n,a,g)}}generateBridgeFunc(e,i){return(...n)=>{var g;const a=i?(g=window.RKBridge)==null?void 0:g[i]:window.RKBridge;return!a||!a[e]?(console.warn(`Bridge method ${i?`${i}.`:""}${e} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((F,A)=>{var d,c,u,w;const l=`cb_${C.v4()}`;this.emitter.on(l,(h,o,B)=>{if(h.toLowerCase()==="success"){if(o)try{o=JSON.parse(o)}catch(G){console.warn("解析 callback 结果失败",G)}F(o)}else h.toLowerCase()==="error"&&A(B);this.emitter.off(l)}),i?(c=(d=window.RKBridge[i])[e])==null||c.call(d,...n,l):(w=(u=window.RKBridge)[e])==null||w.call(u,...n,l)})}}initNativeEventListener(){const e=(i,n)=>{this.emitter.emit(i,n.data)};if(window.dispatchNativeEvent){const i=window.dispatchNativeEvent;window.dispatchNativeEvent=(...n)=>{i(...n),e(...n)}}else window.dispatchNativeEvent=e}};const j=new J;class $ extends P{constructor(){super(...arguments);t(this,"emitter",new v);t(this,"hasBackground",!0);t(this,"initSDK",this.generateBridgeFunc("initSDK"));t(this,"registerClientId",this.generateBridgeFunc("registerClientId"));t(this,"navigate",e=>(window.JSBridge.navigate(e),Promise.resolve()));t(this,"goBack",()=>(window.JSBridge.goBack(),Promise.resolve()));t(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));t(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));t(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));t(this,"getAuthCode",this.generateBridgeFunc("getAuthCode"));t(this,"getUserInfo",()=>window.JSBridge.getUserInfo());t(this,"getCredentials",()=>{var e,i;try{const n=JSON.parse((i=(e=window.JSBridge)==null?void 0:e.getCredentials)==null?void 0:i.call(e));return Promise.resolve(n)}catch(n){return console.warn("获取解析 credentials 失败",n),Promise.resolve({})}});t(this,"getAppToken",this.generateBridgeFunc("getAppToken"));t(this,"getUserToken",this.generateBridgeFunc("getUserToken"));t(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));t(this,"setVolume",this.generateBridgeFunc("setVolume"));t(this,"setBrightness",this.generateBridgeFunc("setBrightness"));t(this,"makePhone",this.generateBridgeFunc("makePhone"));t(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));t(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));t(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));t(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));t(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));t(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));t(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));t(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));t(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));t(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));t(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));t(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));t(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));t(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));t(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));t(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));t(this,"getDirectoryFileList",e=>this.getDirectoryFileListNative(JSON.stringify(e)));t(this,"httpRequest",this.generateBridgeFunc("request","Http"));t(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));t(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));t(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));t(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));t(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));t(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));t(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));t(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));t(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));t(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));t(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));t(this,"setBootApp",e=>{var n;const i=(n=window.RKBridge)==null?void 0:n.GlassAppInstall;return!i||typeof i.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(e)});t(this,"showLockScreen",()=>p("showLockScreen"));t(this,"dismissLockScreen",()=>p("dismissLockScreen"));t(this,"isLockScreenShowing",()=>m());t(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));t(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));t(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));t(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));t(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(i,n,a,g)=>{i&&this.emitter.emit(i,n,a,g)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall);const e=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(i,n,a,g)=>{e==null||e(i,n,a,g),i&&this.emitter.emit(i,n,a,g)}}generateBridgeFunc(e,i){return(...n)=>{var g;const a=i?(g=window.RKBridge)==null?void 0:g[i]:window.RKBridge;return!a||!a[e]?(console.warn(`Bridge method ${i?`${i}.`:""}${e} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((F,A)=>{var d,c,u,w;const l=`cb_${C.v4()}`;this.emitter.on(l,(h,o,B)=>{if(h.toLowerCase()==="success"){if(o)try{o=JSON.parse(o)}catch(G){console.warn("解析 callback 结果失败",G),console.log(e,i,o,B)}F(o)}else h.toLowerCase()==="error"&&A(B);this.emitter.off(l)}),i?(c=(d=window.RKBridge[i])[e])==null||c.call(d,...n,l):(w=(u=window.RKBridge)[e])==null||w.call(u,...n,l)})}}initNativeEventListener(){const e=(i,n)=>{this.emitter.emit(i,n.data)};if(window.dispatchNativeEvent){const i=window.dispatchNativeEvent;window.dispatchNativeEvent=(...n)=>{i(...n),e(...n)}}else window.dispatchNativeEvent=e}}const H=new $;var L;const V=((L=window==null?void 0:window.navigator)==null?void 0:L.userAgent)||"",z=V.includes("lanxin")?j:H;exports.BaseBridge=P;exports.rkBridge=z;
|
package/index.esm.js
CHANGED
|
@@ -1,328 +1,364 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { v4 as
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var I = (r, s, e) => s in r ? y(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
|
|
3
|
+
var t = (r, s, e) => I(r, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { v4 as L } from "uuid";
|
|
5
5
|
import v from "eventemitter3";
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return new Promise((r,
|
|
9
|
-
console.log("获取 authCode 参数 appId: ",
|
|
10
|
-
appId:
|
|
11
|
-
success: function(
|
|
12
|
-
console.log("获取 authCode 成功",
|
|
6
|
+
const f = "1048576-10772480", _ = "66D9EF553887B5054FFC4AC1CB2CB590", N = window.lx;
|
|
7
|
+
function D() {
|
|
8
|
+
return new Promise((r, s) => {
|
|
9
|
+
console.log("获取 authCode 参数 appId: ", f), N.biz.getAuthCode({
|
|
10
|
+
appId: f,
|
|
11
|
+
success: function(e) {
|
|
12
|
+
console.log("获取 authCode 成功", e), r(e);
|
|
13
13
|
},
|
|
14
|
-
fail: function(
|
|
15
|
-
console.log("获取 authCode 失败",
|
|
14
|
+
fail: function(e) {
|
|
15
|
+
console.log("获取 authCode 失败", e), s(e);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
class
|
|
21
|
-
constructor(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.baseURL = (
|
|
20
|
+
class E {
|
|
21
|
+
constructor(s) {
|
|
22
|
+
t(this, "baseURL");
|
|
23
|
+
t(this, "baseRequest");
|
|
24
|
+
this.baseURL = (s == null ? void 0 : s.baseURL) || "", this.baseRequest = (s == null ? void 0 : s.baseRequest) || (() => Promise.resolve({ statusCode: -1, body: "" }));
|
|
25
25
|
}
|
|
26
|
-
async httpRequest(
|
|
26
|
+
async httpRequest(s) {
|
|
27
27
|
try {
|
|
28
|
-
const { statusCode:
|
|
29
|
-
console.log("native http response:",
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
33
|
-
throw new Error(
|
|
34
|
-
} catch (
|
|
35
|
-
throw console.warn("native http request error:",
|
|
28
|
+
const { statusCode: e, body: i } = await this.baseRequest(JSON.stringify(s));
|
|
29
|
+
console.log("native http response:", e, i);
|
|
30
|
+
const n = JSON.parse(i);
|
|
31
|
+
if (n.errCode === 0)
|
|
32
|
+
return n.data;
|
|
33
|
+
throw new Error(n.errMsg || "未知错误");
|
|
34
|
+
} catch (e) {
|
|
35
|
+
throw console.warn("native http request error:", e), e;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
get(
|
|
38
|
+
get(s, e) {
|
|
39
39
|
return this.httpRequest({
|
|
40
40
|
method: "GET",
|
|
41
|
-
url: this.baseURL +
|
|
42
|
-
queryParams:
|
|
41
|
+
url: this.baseURL + s,
|
|
42
|
+
queryParams: e == null ? void 0 : e.params,
|
|
43
43
|
headers: {
|
|
44
44
|
"Content-Type": "application/json",
|
|
45
|
-
...(
|
|
45
|
+
...(e == null ? void 0 : e.headers) ?? {}
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
post(
|
|
49
|
+
post(s, e) {
|
|
50
50
|
return this.httpRequest({
|
|
51
51
|
method: "POST",
|
|
52
|
-
url: this.baseURL +
|
|
53
|
-
body:
|
|
52
|
+
url: this.baseURL + s,
|
|
53
|
+
body: e == null ? void 0 : e.data,
|
|
54
54
|
headers: {
|
|
55
55
|
"Content-Type": "application/json",
|
|
56
|
-
...(
|
|
56
|
+
...(e == null ? void 0 : e.headers) ?? {}
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
var
|
|
62
|
-
const R = new
|
|
61
|
+
var P, k;
|
|
62
|
+
const R = new E({
|
|
63
63
|
baseURL: "http://20.65.2.12:10443/open/apigw",
|
|
64
|
-
baseRequest: typeof window < "u" && ((
|
|
64
|
+
baseRequest: typeof window < "u" && ((k = (P = window == null ? void 0 : window.RKBridge) == null ? void 0 : P.Http) == null ? void 0 : k.request) || void 0
|
|
65
65
|
});
|
|
66
|
-
class
|
|
67
|
-
constructor(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.baseURL = (
|
|
66
|
+
class q {
|
|
67
|
+
constructor(s) {
|
|
68
|
+
t(this, "baseURL");
|
|
69
|
+
t(this, "baseRequest");
|
|
70
|
+
this.baseURL = (s == null ? void 0 : s.baseURL) || "", this.baseRequest = (s == null ? void 0 : s.baseRequest) || (() => Promise.resolve({ statusCode: -1, body: "" }));
|
|
71
71
|
}
|
|
72
|
-
async httpRequest(
|
|
72
|
+
async httpRequest(s) {
|
|
73
73
|
try {
|
|
74
|
-
const { statusCode:
|
|
75
|
-
console.log("native http response:",
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
return
|
|
79
|
-
throw new Error(
|
|
80
|
-
} catch (
|
|
81
|
-
throw console.warn("native http request error:",
|
|
74
|
+
const { statusCode: e, body: i } = await this.baseRequest(JSON.stringify(s));
|
|
75
|
+
console.log("native http response:", e, i);
|
|
76
|
+
const n = JSON.parse(i);
|
|
77
|
+
if (n.resultCode === 0)
|
|
78
|
+
return n;
|
|
79
|
+
throw new Error(n.message || "未知错误");
|
|
80
|
+
} catch (e) {
|
|
81
|
+
throw console.warn("native http request error:", e), e;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
get(
|
|
84
|
+
get(s, e) {
|
|
85
85
|
return this.httpRequest({
|
|
86
86
|
method: "GET",
|
|
87
|
-
url: this.baseURL +
|
|
88
|
-
queryParams:
|
|
87
|
+
url: this.baseURL + s,
|
|
88
|
+
queryParams: e == null ? void 0 : e.params,
|
|
89
89
|
headers: {
|
|
90
90
|
// 'Content-Type': 'application/json',
|
|
91
|
-
...(
|
|
91
|
+
...(e == null ? void 0 : e.headers) ?? {}
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
post(
|
|
95
|
+
post(s, e) {
|
|
96
96
|
return this.httpRequest({
|
|
97
97
|
method: "POST",
|
|
98
|
-
url: this.baseURL +
|
|
99
|
-
body:
|
|
98
|
+
url: this.baseURL + s,
|
|
99
|
+
body: e == null ? void 0 : e.data,
|
|
100
100
|
headers: {
|
|
101
101
|
// 'Content-Type': 'application/json',
|
|
102
|
-
...(
|
|
102
|
+
...(e == null ? void 0 : e.headers) ?? {}
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
var
|
|
108
|
-
new
|
|
107
|
+
var S, T;
|
|
108
|
+
new q({
|
|
109
109
|
baseURL: "http://20.65.1.157",
|
|
110
|
-
baseRequest: typeof window < "u" && ((
|
|
110
|
+
baseRequest: typeof window < "u" && ((T = (S = window == null ? void 0 : window.RKBridge) == null ? void 0 : S.Http) == null ? void 0 : T.request) || void 0
|
|
111
111
|
});
|
|
112
|
-
function
|
|
112
|
+
function M() {
|
|
113
113
|
return R.get("/v1/apptoken/create", {
|
|
114
114
|
params: {
|
|
115
115
|
grant_type: "client_credential",
|
|
116
|
-
appid:
|
|
117
|
-
secret:
|
|
116
|
+
appid: f,
|
|
117
|
+
secret: _
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function O(r, s) {
|
|
122
122
|
return R.get("/v1/usertoken/create", {
|
|
123
123
|
params: {
|
|
124
124
|
grant_type: "authorization_code",
|
|
125
|
-
app_token:
|
|
125
|
+
app_token: s,
|
|
126
126
|
code: r
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function U(r, s) {
|
|
131
131
|
return R.get("/v1/users/fetch", {
|
|
132
132
|
params: {
|
|
133
|
-
user_token:
|
|
133
|
+
user_token: s,
|
|
134
134
|
app_token: r
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
class
|
|
138
|
+
class C {
|
|
139
139
|
constructor() {
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
t(this, "emitter", new v());
|
|
141
|
+
t(this, "hasBackground", !1);
|
|
142
142
|
this.initCallback(), this.initNativeEventListener();
|
|
143
143
|
}
|
|
144
144
|
// --- bridge 事件 ---
|
|
145
|
-
on(
|
|
146
|
-
this.emitter.on(
|
|
145
|
+
on(s, e) {
|
|
146
|
+
this.emitter.on(s, e);
|
|
147
|
+
}
|
|
148
|
+
off(s, e) {
|
|
149
|
+
this.emitter.off(s, e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const x = -999;
|
|
153
|
+
function K(r) {
|
|
154
|
+
const s = window.JSBridge;
|
|
155
|
+
if (s == null || s[r] == null)
|
|
156
|
+
return Promise.reject(x);
|
|
157
|
+
try {
|
|
158
|
+
return s[r]();
|
|
159
|
+
} catch (e) {
|
|
160
|
+
return console.warn(`${r} failed`, e), Promise.reject(-1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function p(r) {
|
|
164
|
+
const s = K(r);
|
|
165
|
+
if (s instanceof Promise)
|
|
166
|
+
return s;
|
|
167
|
+
try {
|
|
168
|
+
const e = typeof s == "string" ? JSON.parse(s) : s;
|
|
169
|
+
return e != null && e.success ? Promise.resolve() : Promise.reject((e == null ? void 0 : e.code) ?? -1);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
return console.warn(`${r} failed`, e), Promise.reject(-1);
|
|
147
172
|
}
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
}
|
|
174
|
+
function m() {
|
|
175
|
+
const r = K("isLockScreenShowing");
|
|
176
|
+
if (r instanceof Promise)
|
|
177
|
+
return r;
|
|
178
|
+
try {
|
|
179
|
+
const s = typeof r == "string" ? JSON.parse(r) : r;
|
|
180
|
+
return Promise.resolve(!!(s != null && s.showing));
|
|
181
|
+
} catch (s) {
|
|
182
|
+
return console.warn("isLockScreenShowing failed", s), Promise.reject(-1);
|
|
150
183
|
}
|
|
151
184
|
}
|
|
152
|
-
function
|
|
185
|
+
function W(r) {
|
|
153
186
|
window[r] && (window.RKBridge = window[r], window.RKBridge_GlassBluetooth = window[r + "_GlassBluetooth"], window.RKBridge_GlassWifiP2P = window[r + "_GlassWifiP2P"], window.RKBridge_GlassAiChat = window[r + "_GlassAiChat"], window.RKBridge_GlassTranslation = window[r + "_GlassTranslation"], window.RKBridge_GlassAlbum = window[r + "_GlassAlbum"], window.RKBridge_GlassFileSystem = window[r + "_GlassFileSystem"], window.RKBridge_GlassMessage = window[r + "_GlassMessage"], window.RKBridge_GlassAppInstall = window[r + "_GlassAppInstall"], window.RKBridge_Http = window[r + "_Http"]);
|
|
154
187
|
}
|
|
155
|
-
let
|
|
188
|
+
let J = class extends C {
|
|
156
189
|
constructor() {
|
|
157
190
|
super();
|
|
158
|
-
|
|
191
|
+
t(this, "emitter", new v());
|
|
159
192
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
160
193
|
// @ts-ignore
|
|
161
|
-
|
|
194
|
+
t(this, "appToken", "");
|
|
162
195
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
163
196
|
// @ts-ignore
|
|
164
|
-
|
|
165
|
-
|
|
197
|
+
t(this, "userToken", "");
|
|
198
|
+
t(this, "hasBackground", !1);
|
|
166
199
|
// --- bridge 函数 ---
|
|
167
200
|
// 初始化SDK
|
|
168
|
-
|
|
201
|
+
t(this, "initSDK", this.generateBridgeFunc("initSDK"));
|
|
169
202
|
// 注册ClientId
|
|
170
|
-
|
|
203
|
+
t(this, "registerClientId", this.generateBridgeFunc("registerClientId"));
|
|
171
204
|
// 路由-打开页面
|
|
172
205
|
// override navigate = this.generateBridgeFunc<void, [string]>('navigate');
|
|
173
|
-
|
|
206
|
+
t(this, "navigate", (e) => (e += (e.includes("?") ? "&" : "?") + "adjust_fullscreen_inset=true", e += "&rkbridge=true", console.log("跳转页面: ", e), window.lx.ui.openView({
|
|
174
207
|
mode: "webview",
|
|
175
208
|
navigationBarBackgroundColor: "#FFFFFF",
|
|
176
209
|
navigationBarFrontStyle: "#0C120D",
|
|
177
|
-
url:
|
|
210
|
+
url: e,
|
|
178
211
|
useSplitScreen: !1
|
|
179
212
|
}), Promise.resolve()));
|
|
180
213
|
// 路由-返回
|
|
181
214
|
// override goBack = this.generateBridgeFunc<void, []>('goBack');
|
|
182
|
-
|
|
215
|
+
t(this, "goBack", () => (window.lx.ui.closeWindow(), Promise.resolve()));
|
|
183
216
|
// 通用-获取设备信息
|
|
184
|
-
|
|
217
|
+
t(this, "getDeviceInfo", this.generateBridgeFunc("getDeviceInfo"));
|
|
185
218
|
// 通用-获取位置信息
|
|
186
|
-
|
|
219
|
+
t(this, "getLocationInfo", this.generateBridgeFunc("getLocationInfo"));
|
|
187
220
|
// 通用-获取状态栏高度
|
|
188
|
-
|
|
221
|
+
t(this, "getStatusBarHeight", this.generateBridgeFunc("getStatusBarHeight"));
|
|
189
222
|
// 通用-获取凭证
|
|
190
|
-
|
|
223
|
+
t(this, "getCredentials", () => {
|
|
191
224
|
try {
|
|
192
|
-
const
|
|
193
|
-
appCredential:
|
|
194
|
-
userCredential:
|
|
225
|
+
const e = localStorage.getItem("appCredential") || "", i = localStorage.getItem("userCredential") || "", n = {
|
|
226
|
+
appCredential: e,
|
|
227
|
+
userCredential: i
|
|
195
228
|
};
|
|
196
|
-
return Promise.resolve(
|
|
197
|
-
} catch (
|
|
198
|
-
return console.warn("获取解析 credentials 失败",
|
|
229
|
+
return Promise.resolve(n);
|
|
230
|
+
} catch (e) {
|
|
231
|
+
return console.warn("获取解析 credentials 失败", e), Promise.resolve({});
|
|
199
232
|
}
|
|
200
233
|
});
|
|
201
234
|
// 通用-获取授权码
|
|
202
|
-
|
|
235
|
+
t(this, "getAuthCode", async () => (await D()).authCode);
|
|
203
236
|
// 通用-获取用户信息
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
console.log("获取 authCode 成功",
|
|
207
|
-
const
|
|
208
|
-
console.log("获取 appToken 成功",
|
|
209
|
-
const
|
|
210
|
-
return console.log("获取 userToken 成功",
|
|
237
|
+
t(this, "getUserInfo", async () => {
|
|
238
|
+
const e = await this.getAuthCode();
|
|
239
|
+
console.log("获取 authCode 成功", e);
|
|
240
|
+
const i = await this.getAppToken();
|
|
241
|
+
console.log("获取 appToken 成功", i);
|
|
242
|
+
const n = await this.getUserToken();
|
|
243
|
+
return console.log("获取 userToken 成功", n), await U(i, n);
|
|
211
244
|
});
|
|
212
245
|
// 通用-获取应用token
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
return this.appToken =
|
|
246
|
+
t(this, "getAppToken", async () => {
|
|
247
|
+
const e = await M();
|
|
248
|
+
return this.appToken = e.appToken, e.appToken;
|
|
216
249
|
});
|
|
217
250
|
// 通用-获取用户token
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
return this.userToken =
|
|
251
|
+
t(this, "getUserToken", async () => {
|
|
252
|
+
const e = await this.getAuthCode(), i = this.appToken, n = await O(e, i);
|
|
253
|
+
return this.userToken = n.userToken, n.userToken;
|
|
221
254
|
});
|
|
222
255
|
// 通用-获取SDKToken
|
|
223
|
-
|
|
256
|
+
t(this, "getSdkToken", this.generateBridgeFunc("getSdkToken"));
|
|
224
257
|
// 通用-设置音量
|
|
225
|
-
|
|
258
|
+
t(this, "setVolume", this.generateBridgeFunc("setVolume"));
|
|
226
259
|
// 通用-设置亮度
|
|
227
|
-
|
|
260
|
+
t(this, "setBrightness", this.generateBridgeFunc("setBrightness"));
|
|
228
261
|
// 通用-打电话
|
|
229
|
-
|
|
262
|
+
t(this, "makePhone", this.generateBridgeFunc("makePhone"));
|
|
230
263
|
// 通用-获取应用包名
|
|
231
|
-
|
|
264
|
+
t(this, "getFileProvider", this.generateBridgeFunc("getFileProvider"));
|
|
232
265
|
// 通用-发送事件
|
|
233
|
-
|
|
266
|
+
t(this, "sendEventToNative", this.generateBridgeFunc("sendEventToNative"));
|
|
234
267
|
// 蓝牙-开始扫描
|
|
235
|
-
|
|
268
|
+
t(this, "startBluetoothScan", this.generateBridgeFunc("startScan", "GlassBluetooth"));
|
|
236
269
|
// 蓝牙-停止扫描
|
|
237
|
-
|
|
270
|
+
t(this, "stopBluetoothScan", this.generateBridgeFunc("stopScan", "GlassBluetooth"));
|
|
238
271
|
// 蓝牙-发起连接
|
|
239
|
-
|
|
272
|
+
t(this, "connectBluetooth", this.generateBridgeFunc("connect", "GlassBluetooth"));
|
|
240
273
|
// p2p-发起设备扫描
|
|
241
|
-
|
|
274
|
+
t(this, "startWifiP2PDiscoverPeers", this.generateBridgeFunc("startDiscoverPeers", "GlassWifiP2P"));
|
|
242
275
|
// p2p-停止设备扫描
|
|
243
|
-
|
|
276
|
+
t(this, "stopWifiP2PDiscoverPeers", this.generateBridgeFunc("stopDiscoverPeers", "GlassWifiP2P"));
|
|
244
277
|
// p2p-发起连接
|
|
245
|
-
|
|
278
|
+
t(this, "connectWifiP2P", this.generateBridgeFunc("connect", "GlassWifiP2P"));
|
|
246
279
|
// ai-chat-获取列表
|
|
247
|
-
|
|
280
|
+
t(this, "getChatList", this.generateBridgeFunc("getChatList", "GlassAiChat"));
|
|
248
281
|
// 翻译-获取源语言列表
|
|
249
|
-
|
|
282
|
+
t(this, "getSourceLanguageOptions", this.generateBridgeFunc(
|
|
250
283
|
"getSourceLanguageOptions",
|
|
251
284
|
"GlassTranslation"
|
|
252
285
|
));
|
|
253
286
|
// 翻译-获取目标语言列表
|
|
254
|
-
|
|
287
|
+
t(this, "getTargetLanguageOptions", this.generateBridgeFunc(
|
|
255
288
|
"getTargetLanguageOptions",
|
|
256
289
|
"GlassTranslation"
|
|
257
290
|
));
|
|
258
291
|
// 翻译-获取当前源语言
|
|
259
|
-
|
|
292
|
+
t(this, "getSourceLanguage", this.generateBridgeFunc("getSourceLanguage", "GlassTranslation"));
|
|
260
293
|
// 翻译-获取当前目标语言
|
|
261
|
-
|
|
294
|
+
t(this, "getTargetLanguage", this.generateBridgeFunc("getTargetLanguage", "GlassTranslation"));
|
|
262
295
|
// 翻译-设置语言
|
|
263
|
-
|
|
296
|
+
t(this, "setLanguage", this.generateBridgeFunc("setLanguage", "GlassTranslation"));
|
|
264
297
|
// 相册-获取相册文件列表
|
|
265
|
-
|
|
266
|
-
|
|
298
|
+
t(this, "getAlbumFileList", this.generateBridgeFunc("getAlbumFileList", "GlassAlbum"));
|
|
299
|
+
t(this, "getDirectoryFileListNative", this.generateBridgeFunc(
|
|
267
300
|
"getDirectoryFileList",
|
|
268
301
|
"GlassFileSystem"
|
|
269
302
|
));
|
|
270
303
|
// 文件系统-获取目录文件列表
|
|
271
|
-
|
|
304
|
+
t(this, "getDirectoryFileList", (e) => this.getDirectoryFileListNative(JSON.stringify(e)));
|
|
272
305
|
// http 请求
|
|
273
|
-
|
|
306
|
+
t(this, "httpRequest", this.generateBridgeFunc("request", "Http"));
|
|
274
307
|
// 应用管理
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var
|
|
288
|
-
const
|
|
289
|
-
return !
|
|
308
|
+
t(this, "getApps", this.generateBridgeFunc("getApps", "GlassAppInstall"));
|
|
309
|
+
t(this, "getAppInfo", this.generateBridgeFunc("getAppInfo", "GlassAppInstall"));
|
|
310
|
+
t(this, "installApp", this.generateBridgeFunc("installApp", "GlassAppInstall"));
|
|
311
|
+
t(this, "uninstallApp", this.generateBridgeFunc("uninstallApp", "GlassAppInstall"));
|
|
312
|
+
t(this, "launchApp", this.generateBridgeFunc("launchApp", "GlassAppInstall"));
|
|
313
|
+
t(this, "stopApp", this.generateBridgeFunc("stopApp", "GlassAppInstall"));
|
|
314
|
+
t(this, "downloadApk", this.generateBridgeFunc("downloadApk", "GlassAppInstall"));
|
|
315
|
+
t(this, "getActiveInstallTask", this.generateBridgeFunc("getActiveInstallTask", "GlassAppInstall"));
|
|
316
|
+
t(this, "subscribeAppProgress", this.generateBridgeFunc("subscribeAppProgress", "GlassAppInstall"));
|
|
317
|
+
t(this, "unsubscribeAppProgress", this.generateBridgeFunc("unsubscribeAppProgress", "GlassAppInstall"));
|
|
318
|
+
t(this, "setBootAppNative", this.generateBridgeFunc("setBootApp", "GlassAppInstall"));
|
|
319
|
+
t(this, "setBootApp", (e) => {
|
|
320
|
+
var n;
|
|
321
|
+
const i = (n = window.RKBridge) == null ? void 0 : n.GlassAppInstall;
|
|
322
|
+
return !i || typeof i.setBootApp != "function" ? Promise.reject(-999) : this.setBootAppNative(e);
|
|
290
323
|
});
|
|
324
|
+
t(this, "showLockScreen", () => p("showLockScreen"));
|
|
325
|
+
t(this, "dismissLockScreen", () => p("dismissLockScreen"));
|
|
326
|
+
t(this, "isLockScreenShowing", () => m());
|
|
291
327
|
// 眼镜消息通信
|
|
292
328
|
// 通过经典蓝牙发送文本消息
|
|
293
|
-
|
|
329
|
+
t(this, "sendTextMessageByClassicBT", this.generateBridgeFunc(
|
|
294
330
|
"sendTextMessageByClassicBT",
|
|
295
331
|
"GlassMessage"
|
|
296
332
|
));
|
|
297
333
|
// 通过 BLE 发送文本消息
|
|
298
|
-
|
|
334
|
+
t(this, "sendTextMessageByBle", this.generateBridgeFunc("sendTextMessageByBLE", "GlassMessage"));
|
|
299
335
|
// 通过P2P发送文本消息
|
|
300
|
-
|
|
336
|
+
t(this, "sendTextMessageByP2P", this.generateBridgeFunc("sendTextMessageByP2P", "GlassMessage"));
|
|
301
337
|
// 蓝牙发送长文本
|
|
302
|
-
|
|
338
|
+
t(this, "sendStreamData", this.generateBridgeFunc("sendStreamData", "GlassMessage"));
|
|
303
339
|
// 广播通知Glass
|
|
304
|
-
|
|
340
|
+
t(this, "sendGlassBroadcast", this.generateBridgeFunc("sendGlassBroadcast", "GlassMessage"));
|
|
305
341
|
}
|
|
306
342
|
initCallback() {
|
|
307
|
-
|
|
308
|
-
_onCallback: (
|
|
309
|
-
|
|
343
|
+
W("BKBridge"), window.RKBridgeCallback || (window.RKBridgeCallback = {
|
|
344
|
+
_onCallback: (i, n, a, g) => {
|
|
345
|
+
i && this.emitter.emit(i, n, a, g);
|
|
310
346
|
}
|
|
311
347
|
}), window.RKBridge && (window.RKBridge.GlassBluetooth = window.RKBridge_GlassBluetooth, window.RKBridge.GlassWifiP2P = window.RKBridge_GlassWifiP2P, window.RKBridge.GlassAiChat = window.RKBridge_GlassAiChat, window.RKBridge.GlassTranslation = window.RKBridge_GlassTranslation, window.RKBridge.GlassAlbum = window.RKBridge_GlassAlbum, window.RKBridge.GlassFileSystem = window.RKBridge_GlassFileSystem, window.RKBridge.GlassMessage = window.RKBridge_GlassMessage, window.RKBridge.GlassAppInstall = window.RKBridge_GlassAppInstall, window.RKBridge.Http = window.RKBridge_Http);
|
|
312
|
-
const
|
|
313
|
-
window.RKBridgeCallback._onCallback = (
|
|
314
|
-
|
|
348
|
+
const e = window.RKBridgeCallback._onCallback;
|
|
349
|
+
window.RKBridgeCallback._onCallback = (i, n, a, g) => {
|
|
350
|
+
e == null || e(i, n, a, g), i && this.emitter.emit(i, n, a, g);
|
|
315
351
|
};
|
|
316
352
|
}
|
|
317
353
|
// todo progress
|
|
318
|
-
generateBridgeFunc(
|
|
319
|
-
return (...
|
|
354
|
+
generateBridgeFunc(e, i) {
|
|
355
|
+
return (...n) => {
|
|
320
356
|
var g;
|
|
321
|
-
const a =
|
|
322
|
-
return !a || !a[
|
|
323
|
-
var d, c, u,
|
|
324
|
-
const l = `cb_${
|
|
325
|
-
this.emitter.on(l, (h, o,
|
|
357
|
+
const a = i ? (g = window.RKBridge) == null ? void 0 : g[i] : window.RKBridge;
|
|
358
|
+
return !a || !a[e] ? (console.warn(`Bridge method ${i ? `${i}.` : ""}${e} is not available, returning default value.`), Promise.resolve(void 0)) : new Promise((F, A) => {
|
|
359
|
+
var d, c, u, w;
|
|
360
|
+
const l = `cb_${L()}`;
|
|
361
|
+
this.emitter.on(l, (h, o, B) => {
|
|
326
362
|
if (h.toLowerCase() === "success") {
|
|
327
363
|
if (o)
|
|
328
364
|
try {
|
|
@@ -330,203 +366,206 @@ let x = class extends k {
|
|
|
330
366
|
} catch (G) {
|
|
331
367
|
console.warn("解析 callback 结果失败", G);
|
|
332
368
|
}
|
|
333
|
-
|
|
334
|
-
} else h.toLowerCase() === "error" &&
|
|
369
|
+
F(o);
|
|
370
|
+
} else h.toLowerCase() === "error" && A(B);
|
|
335
371
|
this.emitter.off(l);
|
|
336
|
-
}),
|
|
372
|
+
}), i ? (c = (d = window.RKBridge[i])[e]) == null || c.call(d, ...n, l) : (w = (u = window.RKBridge)[e]) == null || w.call(u, ...n, l);
|
|
337
373
|
});
|
|
338
374
|
};
|
|
339
375
|
}
|
|
340
376
|
initNativeEventListener() {
|
|
341
|
-
const
|
|
342
|
-
this.emitter.emit(
|
|
377
|
+
const e = (i, n) => {
|
|
378
|
+
this.emitter.emit(i, n.data);
|
|
343
379
|
};
|
|
344
380
|
if (window.dispatchNativeEvent) {
|
|
345
|
-
const
|
|
346
|
-
window.dispatchNativeEvent = (...
|
|
347
|
-
|
|
381
|
+
const i = window.dispatchNativeEvent;
|
|
382
|
+
window.dispatchNativeEvent = (...n) => {
|
|
383
|
+
i(...n), e(...n);
|
|
348
384
|
};
|
|
349
385
|
} else
|
|
350
|
-
window.dispatchNativeEvent =
|
|
386
|
+
window.dispatchNativeEvent = e;
|
|
351
387
|
}
|
|
352
388
|
};
|
|
353
|
-
const
|
|
354
|
-
class
|
|
389
|
+
const $ = new J();
|
|
390
|
+
class j extends C {
|
|
355
391
|
constructor() {
|
|
356
392
|
super(...arguments);
|
|
357
|
-
|
|
358
|
-
|
|
393
|
+
t(this, "emitter", new v());
|
|
394
|
+
t(this, "hasBackground", !0);
|
|
359
395
|
// --- bridge 函数 ---
|
|
360
396
|
// 初始化SDK
|
|
361
|
-
|
|
397
|
+
t(this, "initSDK", this.generateBridgeFunc("initSDK"));
|
|
362
398
|
// 注册ClientId
|
|
363
|
-
|
|
399
|
+
t(this, "registerClientId", this.generateBridgeFunc("registerClientId"));
|
|
364
400
|
// 路由-打开页面
|
|
365
|
-
|
|
401
|
+
t(this, "navigate", (e) => (window.JSBridge.navigate(e), Promise.resolve()));
|
|
366
402
|
// 路由-返回
|
|
367
|
-
|
|
403
|
+
t(this, "goBack", () => (window.JSBridge.goBack(), Promise.resolve()));
|
|
368
404
|
// 通用-获取设备信息
|
|
369
|
-
|
|
405
|
+
t(this, "getDeviceInfo", this.generateBridgeFunc("getDeviceInfo"));
|
|
370
406
|
// 通用-获取状态栏高度
|
|
371
|
-
|
|
407
|
+
t(this, "getStatusBarHeight", this.generateBridgeFunc("getStatusBarHeight"));
|
|
372
408
|
// 通用-获取位置信息
|
|
373
|
-
|
|
409
|
+
t(this, "getLocationInfo", this.generateBridgeFunc("getLocationInfo"));
|
|
374
410
|
// 通用-获取授权码
|
|
375
|
-
|
|
411
|
+
t(this, "getAuthCode", this.generateBridgeFunc("getAuthCode"));
|
|
376
412
|
// 通用-获取用户信息
|
|
377
|
-
|
|
413
|
+
t(this, "getUserInfo", () => window.JSBridge.getUserInfo());
|
|
378
414
|
// 通用-获取凭证
|
|
379
|
-
|
|
380
|
-
var
|
|
415
|
+
t(this, "getCredentials", () => {
|
|
416
|
+
var e, i;
|
|
381
417
|
try {
|
|
382
|
-
const
|
|
383
|
-
return Promise.resolve(
|
|
384
|
-
} catch (
|
|
385
|
-
return console.warn("获取解析 credentials 失败",
|
|
418
|
+
const n = JSON.parse((i = (e = window.JSBridge) == null ? void 0 : e.getCredentials) == null ? void 0 : i.call(e));
|
|
419
|
+
return Promise.resolve(n);
|
|
420
|
+
} catch (n) {
|
|
421
|
+
return console.warn("获取解析 credentials 失败", n), Promise.resolve({});
|
|
386
422
|
}
|
|
387
423
|
});
|
|
388
424
|
// 通用-获取应用token
|
|
389
|
-
|
|
425
|
+
t(this, "getAppToken", this.generateBridgeFunc("getAppToken"));
|
|
390
426
|
// 通用-获取用户token
|
|
391
|
-
|
|
427
|
+
t(this, "getUserToken", this.generateBridgeFunc("getUserToken"));
|
|
392
428
|
// 通用-获取SDKToken
|
|
393
|
-
|
|
429
|
+
t(this, "getSdkToken", this.generateBridgeFunc("getSdkToken"));
|
|
394
430
|
// 通用-设置音量
|
|
395
|
-
|
|
431
|
+
t(this, "setVolume", this.generateBridgeFunc("setVolume"));
|
|
396
432
|
// 通用-设置亮度
|
|
397
|
-
|
|
433
|
+
t(this, "setBrightness", this.generateBridgeFunc("setBrightness"));
|
|
398
434
|
// 通用-打电话
|
|
399
|
-
|
|
435
|
+
t(this, "makePhone", this.generateBridgeFunc("makePhone"));
|
|
400
436
|
// 通用-发送事件
|
|
401
|
-
|
|
437
|
+
t(this, "sendEventToNative", this.generateBridgeFunc("sendEventToNative"));
|
|
402
438
|
// 通用-获取应用包名
|
|
403
|
-
|
|
439
|
+
t(this, "getFileProvider", this.generateBridgeFunc("getFileProvider"));
|
|
404
440
|
// 蓝牙-开始扫描
|
|
405
|
-
|
|
441
|
+
t(this, "startBluetoothScan", this.generateBridgeFunc("startScan", "GlassBluetooth"));
|
|
406
442
|
// 蓝牙-停止扫描
|
|
407
|
-
|
|
443
|
+
t(this, "stopBluetoothScan", this.generateBridgeFunc("stopScan", "GlassBluetooth"));
|
|
408
444
|
// 蓝牙-发起连接
|
|
409
|
-
|
|
445
|
+
t(this, "connectBluetooth", this.generateBridgeFunc("connect", "GlassBluetooth"));
|
|
410
446
|
// p2p-发起设备扫描
|
|
411
|
-
|
|
447
|
+
t(this, "startWifiP2PDiscoverPeers", this.generateBridgeFunc("startDiscoverPeers", "GlassWifiP2P"));
|
|
412
448
|
// p2p-停止设备扫描
|
|
413
|
-
|
|
449
|
+
t(this, "stopWifiP2PDiscoverPeers", this.generateBridgeFunc("stopDiscoverPeers", "GlassWifiP2P"));
|
|
414
450
|
// p2p-发起连接
|
|
415
|
-
|
|
451
|
+
t(this, "connectWifiP2P", this.generateBridgeFunc("connect", "GlassWifiP2P"));
|
|
416
452
|
// ai-chat-获取列表
|
|
417
|
-
|
|
453
|
+
t(this, "getChatList", this.generateBridgeFunc("getChatList", "GlassAiChat"));
|
|
418
454
|
// 翻译-获取源语言列表
|
|
419
|
-
|
|
455
|
+
t(this, "getSourceLanguageOptions", this.generateBridgeFunc(
|
|
420
456
|
"getSourceLanguageOptions",
|
|
421
457
|
"GlassTranslation"
|
|
422
458
|
));
|
|
423
459
|
// 翻译-获取目标语言列表
|
|
424
|
-
|
|
460
|
+
t(this, "getTargetLanguageOptions", this.generateBridgeFunc(
|
|
425
461
|
"getTargetLanguageOptions",
|
|
426
462
|
"GlassTranslation"
|
|
427
463
|
));
|
|
428
464
|
// 翻译-获取当前源语言
|
|
429
|
-
|
|
465
|
+
t(this, "getSourceLanguage", this.generateBridgeFunc("getSourceLanguage", "GlassTranslation"));
|
|
430
466
|
// 翻译-获取当前目标语言
|
|
431
|
-
|
|
467
|
+
t(this, "getTargetLanguage", this.generateBridgeFunc("getTargetLanguage", "GlassTranslation"));
|
|
432
468
|
// 翻译-设置语言
|
|
433
|
-
|
|
469
|
+
t(this, "setLanguage", this.generateBridgeFunc("setLanguage", "GlassTranslation"));
|
|
434
470
|
// 相册-获取相册文件列表
|
|
435
|
-
|
|
436
|
-
|
|
471
|
+
t(this, "getAlbumFileList", this.generateBridgeFunc("getAlbumFileList", "GlassAlbum"));
|
|
472
|
+
t(this, "getDirectoryFileListNative", this.generateBridgeFunc(
|
|
437
473
|
"getDirectoryFileList",
|
|
438
474
|
"GlassFileSystem"
|
|
439
475
|
));
|
|
440
476
|
// 文件系统-获取目录文件列表
|
|
441
|
-
|
|
477
|
+
t(this, "getDirectoryFileList", (e) => this.getDirectoryFileListNative(JSON.stringify(e)));
|
|
442
478
|
// http 请求
|
|
443
|
-
|
|
479
|
+
t(this, "httpRequest", this.generateBridgeFunc("request", "Http"));
|
|
444
480
|
// 应用管理
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
481
|
+
t(this, "getApps", this.generateBridgeFunc("getApps", "GlassAppInstall"));
|
|
482
|
+
t(this, "getAppInfo", this.generateBridgeFunc("getAppInfo", "GlassAppInstall"));
|
|
483
|
+
t(this, "installApp", this.generateBridgeFunc("installApp", "GlassAppInstall"));
|
|
484
|
+
t(this, "uninstallApp", this.generateBridgeFunc("uninstallApp", "GlassAppInstall"));
|
|
485
|
+
t(this, "launchApp", this.generateBridgeFunc("launchApp", "GlassAppInstall"));
|
|
486
|
+
t(this, "stopApp", this.generateBridgeFunc("stopApp", "GlassAppInstall"));
|
|
487
|
+
t(this, "downloadApk", this.generateBridgeFunc("downloadApk", "GlassAppInstall"));
|
|
488
|
+
t(this, "getActiveInstallTask", this.generateBridgeFunc("getActiveInstallTask", "GlassAppInstall"));
|
|
489
|
+
t(this, "subscribeAppProgress", this.generateBridgeFunc("subscribeAppProgress", "GlassAppInstall"));
|
|
490
|
+
t(this, "unsubscribeAppProgress", this.generateBridgeFunc("unsubscribeAppProgress", "GlassAppInstall"));
|
|
491
|
+
t(this, "setBootAppNative", this.generateBridgeFunc("setBootApp", "GlassAppInstall"));
|
|
456
492
|
/**
|
|
457
493
|
* 开机自启:Native 未合入时 reject(-999),避免 generateBridgeFunc 缺方法时 resolve(undefined) 误判成功。
|
|
458
494
|
*/
|
|
459
|
-
|
|
460
|
-
var
|
|
461
|
-
const
|
|
462
|
-
return !
|
|
495
|
+
t(this, "setBootApp", (e) => {
|
|
496
|
+
var n;
|
|
497
|
+
const i = (n = window.RKBridge) == null ? void 0 : n.GlassAppInstall;
|
|
498
|
+
return !i || typeof i.setBootApp != "function" ? Promise.reject(-999) : this.setBootAppNative(e);
|
|
463
499
|
});
|
|
500
|
+
t(this, "showLockScreen", () => p("showLockScreen"));
|
|
501
|
+
t(this, "dismissLockScreen", () => p("dismissLockScreen"));
|
|
502
|
+
t(this, "isLockScreenShowing", () => m());
|
|
464
503
|
// 眼镜消息通信
|
|
465
504
|
// 通过经典蓝牙发送文本消息
|
|
466
|
-
|
|
505
|
+
t(this, "sendTextMessageByClassicBT", this.generateBridgeFunc(
|
|
467
506
|
"sendTextMessageByClassicBT",
|
|
468
507
|
"GlassMessage"
|
|
469
508
|
));
|
|
470
509
|
// 通过 BLE 发送文本消息
|
|
471
|
-
|
|
510
|
+
t(this, "sendTextMessageByBle", this.generateBridgeFunc("sendTextMessageByBLE", "GlassMessage"));
|
|
472
511
|
// 通过P2P发送文本消息
|
|
473
|
-
|
|
512
|
+
t(this, "sendTextMessageByP2P", this.generateBridgeFunc("sendTextMessageByP2P", "GlassMessage"));
|
|
474
513
|
// 蓝牙发送长文本
|
|
475
|
-
|
|
514
|
+
t(this, "sendStreamData", this.generateBridgeFunc("sendStreamData", "GlassMessage"));
|
|
476
515
|
// 广播通知Glass
|
|
477
|
-
|
|
516
|
+
t(this, "sendGlassBroadcast", this.generateBridgeFunc("sendGlassBroadcast", "GlassMessage"));
|
|
478
517
|
}
|
|
479
518
|
initCallback() {
|
|
480
519
|
window.RKBridgeCallback || (window.RKBridgeCallback = {
|
|
481
|
-
_onCallback: (
|
|
482
|
-
|
|
520
|
+
_onCallback: (i, n, a, g) => {
|
|
521
|
+
i && this.emitter.emit(i, n, a, g);
|
|
483
522
|
}
|
|
484
523
|
}), window.RKBridge && (window.RKBridge.GlassBluetooth = window.RKBridge_GlassBluetooth, window.RKBridge.GlassWifiP2P = window.RKBridge_GlassWifiP2P, window.RKBridge.GlassAiChat = window.RKBridge_GlassAiChat, window.RKBridge.GlassTranslation = window.RKBridge_GlassTranslation, window.RKBridge.GlassAlbum = window.RKBridge_GlassAlbum, window.RKBridge.GlassFileSystem = window.RKBridge_GlassFileSystem, window.RKBridge.GlassMessage = window.RKBridge_GlassMessage, window.RKBridge.GlassAppInstall = window.RKBridge_GlassAppInstall);
|
|
485
|
-
const
|
|
486
|
-
window.RKBridgeCallback._onCallback = (
|
|
487
|
-
|
|
524
|
+
const e = window.RKBridgeCallback._onCallback;
|
|
525
|
+
window.RKBridgeCallback._onCallback = (i, n, a, g) => {
|
|
526
|
+
e == null || e(i, n, a, g), i && this.emitter.emit(i, n, a, g);
|
|
488
527
|
};
|
|
489
528
|
}
|
|
490
529
|
// todo progress
|
|
491
|
-
generateBridgeFunc(
|
|
492
|
-
return (...
|
|
530
|
+
generateBridgeFunc(e, i) {
|
|
531
|
+
return (...n) => {
|
|
493
532
|
var g;
|
|
494
|
-
const a =
|
|
495
|
-
return !a || !a[
|
|
496
|
-
var d, c, u,
|
|
497
|
-
const l = `cb_${
|
|
498
|
-
this.emitter.on(l, (h, o,
|
|
533
|
+
const a = i ? (g = window.RKBridge) == null ? void 0 : g[i] : window.RKBridge;
|
|
534
|
+
return !a || !a[e] ? (console.warn(`Bridge method ${i ? `${i}.` : ""}${e} is not available, returning default value.`), Promise.resolve(void 0)) : new Promise((F, A) => {
|
|
535
|
+
var d, c, u, w;
|
|
536
|
+
const l = `cb_${L()}`;
|
|
537
|
+
this.emitter.on(l, (h, o, B) => {
|
|
499
538
|
if (h.toLowerCase() === "success") {
|
|
500
539
|
if (o)
|
|
501
540
|
try {
|
|
502
541
|
o = JSON.parse(o);
|
|
503
542
|
} catch (G) {
|
|
504
|
-
console.warn("解析 callback 结果失败", G), console.log(
|
|
543
|
+
console.warn("解析 callback 结果失败", G), console.log(e, i, o, B);
|
|
505
544
|
}
|
|
506
|
-
|
|
507
|
-
} else h.toLowerCase() === "error" &&
|
|
545
|
+
F(o);
|
|
546
|
+
} else h.toLowerCase() === "error" && A(B);
|
|
508
547
|
this.emitter.off(l);
|
|
509
|
-
}),
|
|
548
|
+
}), i ? (c = (d = window.RKBridge[i])[e]) == null || c.call(d, ...n, l) : (w = (u = window.RKBridge)[e]) == null || w.call(u, ...n, l);
|
|
510
549
|
});
|
|
511
550
|
};
|
|
512
551
|
}
|
|
513
552
|
initNativeEventListener() {
|
|
514
|
-
const
|
|
515
|
-
this.emitter.emit(
|
|
553
|
+
const e = (i, n) => {
|
|
554
|
+
this.emitter.emit(i, n.data);
|
|
516
555
|
};
|
|
517
556
|
if (window.dispatchNativeEvent) {
|
|
518
|
-
const
|
|
519
|
-
window.dispatchNativeEvent = (...
|
|
520
|
-
|
|
557
|
+
const i = window.dispatchNativeEvent;
|
|
558
|
+
window.dispatchNativeEvent = (...n) => {
|
|
559
|
+
i(...n), e(...n);
|
|
521
560
|
};
|
|
522
561
|
} else
|
|
523
|
-
window.dispatchNativeEvent =
|
|
562
|
+
window.dispatchNativeEvent = e;
|
|
524
563
|
}
|
|
525
564
|
}
|
|
526
|
-
const
|
|
527
|
-
var
|
|
528
|
-
const
|
|
565
|
+
const H = new j();
|
|
566
|
+
var b;
|
|
567
|
+
const V = ((b = window == null ? void 0 : window.navigator) == null ? void 0 : b.userAgent) || "", Z = V.includes("lanxin") ? $ : H;
|
|
529
568
|
export {
|
|
530
|
-
|
|
531
|
-
|
|
569
|
+
C as BaseBridge,
|
|
570
|
+
Z as rkBridge
|
|
532
571
|
};
|
package/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("uuid"),require("eventemitter3")):typeof define=="function"&&define.amd?define(["exports","uuid","eventemitter3"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a["rk-bridge"]={},a.uuid,a.EventEmitter))})(this,function(a,l,c){"use strict";var J=Object.defineProperty;var H=(a,l,c)=>l in a?J(a,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):a[l]=c;var e=(a,l,c)=>H(a,typeof l!="symbol"?l+"":l,c);var b,k,C,K,y;const A="1048576-10772480",S="66D9EF553887B5054FFC4AC1CB2CB590",L=window.lx;function m(){return new Promise((r,n)=>{console.log("获取 authCode 参数 appId: ",A),L.biz.getAuthCode({appId:A,success:function(t){console.log("获取 authCode 成功",t),r(t)},fail:function(t){console.log("获取 authCode 失败",t),n(t)}})})}class I{constructor(n){e(this,"baseURL");e(this,"baseRequest");this.baseURL=(n==null?void 0:n.baseURL)||"",this.baseRequest=(n==null?void 0:n.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(n){try{const{statusCode:t,body:s}=await this.baseRequest(JSON.stringify(n));console.log("native http response:",t,s);const i=JSON.parse(s);if(i.errCode===0)return i.data;throw new Error(i.errMsg||"未知错误")}catch(t){throw console.warn("native http request error:",t),t}}get(n,t){return this.httpRequest({method:"GET",url:this.baseURL+n,queryParams:t==null?void 0:t.params,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}})}post(n,t){return this.httpRequest({method:"POST",url:this.baseURL+n,body:t==null?void 0:t.data,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}})}}const f=new I({baseURL:"http://20.65.2.12:10443/open/apigw",baseRequest:typeof window<"u"&&((k=(b=window==null?void 0:window.RKBridge)==null?void 0:b.Http)==null?void 0:k.request)||void 0});class _{constructor(n){e(this,"baseURL");e(this,"baseRequest");this.baseURL=(n==null?void 0:n.baseURL)||"",this.baseRequest=(n==null?void 0:n.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(n){try{const{statusCode:t,body:s}=await this.baseRequest(JSON.stringify(n));console.log("native http response:",t,s);const i=JSON.parse(s);if(i.resultCode===0)return i;throw new Error(i.message||"未知错误")}catch(t){throw console.warn("native http request error:",t),t}}get(n,t){return this.httpRequest({method:"GET",url:this.baseURL+n,queryParams:t==null?void 0:t.params,headers:{...(t==null?void 0:t.headers)??{}}})}post(n,t){return this.httpRequest({method:"POST",url:this.baseURL+n,body:t==null?void 0:t.data,headers:{...(t==null?void 0:t.headers)??{}}})}}new _({baseURL:"http://20.65.1.157",baseRequest:typeof window<"u"&&((K=(C=window==null?void 0:window.RKBridge)==null?void 0:C.Http)==null?void 0:K.request)||void 0});function N(){return f.get("/v1/apptoken/create",{params:{grant_type:"client_credential",appid:A,secret:S}})}function D(r,n){return f.get("/v1/usertoken/create",{params:{grant_type:"authorization_code",app_token:n,code:r}})}function q(r,n){return f.get("/v1/users/fetch",{params:{user_token:n,app_token:r}})}class v{constructor(){e(this,"emitter",new c);e(this,"hasBackground",!1);this.initCallback(),this.initNativeEventListener()}on(n,t){this.emitter.on(n,t)}off(n,t){this.emitter.off(n,t)}}function M(r){window[r]&&(window.RKBridge=window[r],window.RKBridge_GlassBluetooth=window[r+"_GlassBluetooth"],window.RKBridge_GlassWifiP2P=window[r+"_GlassWifiP2P"],window.RKBridge_GlassAiChat=window[r+"_GlassAiChat"],window.RKBridge_GlassTranslation=window[r+"_GlassTranslation"],window.RKBridge_GlassAlbum=window[r+"_GlassAlbum"],window.RKBridge_GlassFileSystem=window[r+"_GlassFileSystem"],window.RKBridge_GlassMessage=window[r+"_GlassMessage"],window.RKBridge_GlassAppInstall=window[r+"_GlassAppInstall"],window.RKBridge_Http=window[r+"_Http"])}let E=class extends v{constructor(){super();e(this,"emitter",new c);e(this,"appToken","");e(this,"userToken","");e(this,"hasBackground",!1);e(this,"initSDK",this.generateBridgeFunc("initSDK"));e(this,"registerClientId",this.generateBridgeFunc("registerClientId"));e(this,"navigate",t=>(t+=(t.includes("?")?"&":"?")+"adjust_fullscreen_inset=true",t+="&rkbridge=true",console.log("跳转页面: ",t),window.lx.ui.openView({mode:"webview",navigationBarBackgroundColor:"#FFFFFF",navigationBarFrontStyle:"#0C120D",url:t,useSplitScreen:!1}),Promise.resolve()));e(this,"goBack",()=>(window.lx.ui.closeWindow(),Promise.resolve()));e(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));e(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));e(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));e(this,"getCredentials",()=>{try{const t=localStorage.getItem("appCredential")||"",s=localStorage.getItem("userCredential")||"",i={appCredential:t,userCredential:s};return Promise.resolve(i)}catch(t){return console.warn("获取解析 credentials 失败",t),Promise.resolve({})}});e(this,"getAuthCode",async()=>(await m()).authCode);e(this,"getUserInfo",async()=>{const t=await this.getAuthCode();console.log("获取 authCode 成功",t);const s=await this.getAppToken();console.log("获取 appToken 成功",s);const i=await this.getUserToken();return console.log("获取 userToken 成功",i),await q(s,i)});e(this,"getAppToken",async()=>{const t=await N();return this.appToken=t.appToken,t.appToken});e(this,"getUserToken",async()=>{const t=await this.getAuthCode(),s=this.appToken,i=await D(t,s);return this.userToken=i.userToken,i.userToken});e(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));e(this,"setVolume",this.generateBridgeFunc("setVolume"));e(this,"setBrightness",this.generateBridgeFunc("setBrightness"));e(this,"makePhone",this.generateBridgeFunc("makePhone"));e(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));e(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));e(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));e(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));e(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));e(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));e(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));e(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));e(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));e(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));e(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));e(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));e(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));e(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));e(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));e(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));e(this,"getDirectoryFileList",t=>this.getDirectoryFileListNative(JSON.stringify(t)));e(this,"httpRequest",this.generateBridgeFunc("request","Http"));e(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));e(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));e(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));e(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));e(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));e(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));e(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));e(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));e(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));e(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));e(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));e(this,"setBootApp",t=>{var i;const s=(i=window.RKBridge)==null?void 0:i.GlassAppInstall;return!s||typeof s.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(t)});e(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));e(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));e(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));e(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));e(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){M("BKBridge"),window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(s,i,g,o)=>{s&&this.emitter.emit(s,i,g,o)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall,window.RKBridge.Http=window.RKBridge_Http);const t=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(s,i,g,o)=>{t==null||t(s,i,g,o),s&&this.emitter.emit(s,i,g,o)}}generateBridgeFunc(t,s){return(...i)=>{var o;const g=s?(o=window.RKBridge)==null?void 0:o[s]:window.RKBridge;return!g||!g[t]?(console.warn(`Bridge method ${s?`${s}.`:""}${t} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((R,P)=>{var B,h,w,p;const u=`cb_${l.v4()}`;this.emitter.on(u,(F,d,G)=>{if(F.toLowerCase()==="success"){if(d)try{d=JSON.parse(d)}catch(T){console.warn("解析 callback 结果失败",T)}R(d)}else F.toLowerCase()==="error"&&P(G);this.emitter.off(u)}),s?(h=(B=window.RKBridge[s])[t])==null||h.call(B,...i,u):(p=(w=window.RKBridge)[t])==null||p.call(w,...i,u)})}}initNativeEventListener(){const t=(s,i)=>{this.emitter.emit(s,i.data)};if(window.dispatchNativeEvent){const s=window.dispatchNativeEvent;window.dispatchNativeEvent=(...i)=>{s(...i),t(...i)}}else window.dispatchNativeEvent=t}};const O=new E;class x extends v{constructor(){super(...arguments);e(this,"emitter",new c);e(this,"hasBackground",!0);e(this,"initSDK",this.generateBridgeFunc("initSDK"));e(this,"registerClientId",this.generateBridgeFunc("registerClientId"));e(this,"navigate",t=>(window.JSBridge.navigate(t),Promise.resolve()));e(this,"goBack",()=>(window.JSBridge.goBack(),Promise.resolve()));e(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));e(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));e(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));e(this,"getAuthCode",this.generateBridgeFunc("getAuthCode"));e(this,"getUserInfo",()=>window.JSBridge.getUserInfo());e(this,"getCredentials",()=>{var t,s;try{const i=JSON.parse((s=(t=window.JSBridge)==null?void 0:t.getCredentials)==null?void 0:s.call(t));return Promise.resolve(i)}catch(i){return console.warn("获取解析 credentials 失败",i),Promise.resolve({})}});e(this,"getAppToken",this.generateBridgeFunc("getAppToken"));e(this,"getUserToken",this.generateBridgeFunc("getUserToken"));e(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));e(this,"setVolume",this.generateBridgeFunc("setVolume"));e(this,"setBrightness",this.generateBridgeFunc("setBrightness"));e(this,"makePhone",this.generateBridgeFunc("makePhone"));e(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));e(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));e(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));e(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));e(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));e(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));e(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));e(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));e(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));e(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));e(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));e(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));e(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));e(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));e(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));e(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));e(this,"getDirectoryFileList",t=>this.getDirectoryFileListNative(JSON.stringify(t)));e(this,"httpRequest",this.generateBridgeFunc("request","Http"));e(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));e(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));e(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));e(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));e(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));e(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));e(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));e(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));e(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));e(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));e(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));e(this,"setBootApp",t=>{var i;const s=(i=window.RKBridge)==null?void 0:i.GlassAppInstall;return!s||typeof s.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(t)});e(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));e(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));e(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));e(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));e(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(s,i,g,o)=>{s&&this.emitter.emit(s,i,g,o)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall);const t=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(s,i,g,o)=>{t==null||t(s,i,g,o),s&&this.emitter.emit(s,i,g,o)}}generateBridgeFunc(t,s){return(...i)=>{var o;const g=s?(o=window.RKBridge)==null?void 0:o[s]:window.RKBridge;return!g||!g[t]?(console.warn(`Bridge method ${s?`${s}.`:""}${t} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((R,P)=>{var B,h,w,p;const u=`cb_${l.v4()}`;this.emitter.on(u,(F,d,G)=>{if(F.toLowerCase()==="success"){if(d)try{d=JSON.parse(d)}catch(T){console.warn("解析 callback 结果失败",T),console.log(t,s,d,G)}R(d)}else F.toLowerCase()==="error"&&P(G);this.emitter.off(u)}),s?(h=(B=window.RKBridge[s])[t])==null||h.call(B,...i,u):(p=(w=window.RKBridge)[t])==null||p.call(w,...i,u)})}}initNativeEventListener(){const t=(s,i)=>{this.emitter.emit(s,i.data)};if(window.dispatchNativeEvent){const s=window.dispatchNativeEvent;window.dispatchNativeEvent=(...i)=>{s(...i),t(...i)}}else window.dispatchNativeEvent=t}}const U=new x,W=(((y=window==null?void 0:window.navigator)==null?void 0:y.userAgent)||"").includes("lanxin")?O:U;a.BaseBridge=v,a.rkBridge=W,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("uuid"),require("eventemitter3")):typeof define=="function"&&define.amd?define(["exports","uuid","eventemitter3"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a["rk-bridge"]={},a.uuid,a.EventEmitter))})(this,function(a,l,u){"use strict";var V=Object.defineProperty;var z=(a,l,u)=>l in a?V(a,l,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[l]=u;var e=(a,l,u)=>z(a,typeof l!="symbol"?l+"":l,u);var L,C,K,m,y;const G="1048576-10772480",I="66D9EF553887B5054FFC4AC1CB2CB590",_=window.lx;function N(){return new Promise((r,i)=>{console.log("获取 authCode 参数 appId: ",G),_.biz.getAuthCode({appId:G,success:function(t){console.log("获取 authCode 成功",t),r(t)},fail:function(t){console.log("获取 authCode 失败",t),i(t)}})})}class D{constructor(i){e(this,"baseURL");e(this,"baseRequest");this.baseURL=(i==null?void 0:i.baseURL)||"",this.baseRequest=(i==null?void 0:i.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(i){try{const{statusCode:t,body:s}=await this.baseRequest(JSON.stringify(i));console.log("native http response:",t,s);const n=JSON.parse(s);if(n.errCode===0)return n.data;throw new Error(n.errMsg||"未知错误")}catch(t){throw console.warn("native http request error:",t),t}}get(i,t){return this.httpRequest({method:"GET",url:this.baseURL+i,queryParams:t==null?void 0:t.params,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}})}post(i,t){return this.httpRequest({method:"POST",url:this.baseURL+i,body:t==null?void 0:t.data,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}})}}const v=new D({baseURL:"http://20.65.2.12:10443/open/apigw",baseRequest:typeof window<"u"&&((C=(L=window==null?void 0:window.RKBridge)==null?void 0:L.Http)==null?void 0:C.request)||void 0});class q{constructor(i){e(this,"baseURL");e(this,"baseRequest");this.baseURL=(i==null?void 0:i.baseURL)||"",this.baseRequest=(i==null?void 0:i.baseRequest)||(()=>Promise.resolve({statusCode:-1,body:""}))}async httpRequest(i){try{const{statusCode:t,body:s}=await this.baseRequest(JSON.stringify(i));console.log("native http response:",t,s);const n=JSON.parse(s);if(n.resultCode===0)return n;throw new Error(n.message||"未知错误")}catch(t){throw console.warn("native http request error:",t),t}}get(i,t){return this.httpRequest({method:"GET",url:this.baseURL+i,queryParams:t==null?void 0:t.params,headers:{...(t==null?void 0:t.headers)??{}}})}post(i,t){return this.httpRequest({method:"POST",url:this.baseURL+i,body:t==null?void 0:t.data,headers:{...(t==null?void 0:t.headers)??{}}})}}new q({baseURL:"http://20.65.1.157",baseRequest:typeof window<"u"&&((m=(K=window==null?void 0:window.RKBridge)==null?void 0:K.Http)==null?void 0:m.request)||void 0});function M(){return v.get("/v1/apptoken/create",{params:{grant_type:"client_credential",appid:G,secret:I}})}function E(r,i){return v.get("/v1/usertoken/create",{params:{grant_type:"authorization_code",app_token:i,code:r}})}function O(r,i){return v.get("/v1/users/fetch",{params:{user_token:i,app_token:r}})}class R{constructor(){e(this,"emitter",new u);e(this,"hasBackground",!1);this.initCallback(),this.initNativeEventListener()}on(i,t){this.emitter.on(i,t)}off(i,t){this.emitter.off(i,t)}}const U=-999;function S(r){const i=window.JSBridge;if(i==null||i[r]==null)return Promise.reject(U);try{return i[r]()}catch(t){return console.warn(`${r} failed`,t),Promise.reject(-1)}}function f(r){const i=S(r);if(i instanceof Promise)return i;try{const t=typeof i=="string"?JSON.parse(i):i;return t!=null&&t.success?Promise.resolve():Promise.reject((t==null?void 0:t.code)??-1)}catch(t){return console.warn(`${r} failed`,t),Promise.reject(-1)}}function b(){const r=S("isLockScreenShowing");if(r instanceof Promise)return r;try{const i=typeof r=="string"?JSON.parse(r):r;return Promise.resolve(!!(i!=null&&i.showing))}catch(i){return console.warn("isLockScreenShowing failed",i),Promise.reject(-1)}}function x(r){window[r]&&(window.RKBridge=window[r],window.RKBridge_GlassBluetooth=window[r+"_GlassBluetooth"],window.RKBridge_GlassWifiP2P=window[r+"_GlassWifiP2P"],window.RKBridge_GlassAiChat=window[r+"_GlassAiChat"],window.RKBridge_GlassTranslation=window[r+"_GlassTranslation"],window.RKBridge_GlassAlbum=window[r+"_GlassAlbum"],window.RKBridge_GlassFileSystem=window[r+"_GlassFileSystem"],window.RKBridge_GlassMessage=window[r+"_GlassMessage"],window.RKBridge_GlassAppInstall=window[r+"_GlassAppInstall"],window.RKBridge_Http=window[r+"_Http"])}let W=class extends R{constructor(){super();e(this,"emitter",new u);e(this,"appToken","");e(this,"userToken","");e(this,"hasBackground",!1);e(this,"initSDK",this.generateBridgeFunc("initSDK"));e(this,"registerClientId",this.generateBridgeFunc("registerClientId"));e(this,"navigate",t=>(t+=(t.includes("?")?"&":"?")+"adjust_fullscreen_inset=true",t+="&rkbridge=true",console.log("跳转页面: ",t),window.lx.ui.openView({mode:"webview",navigationBarBackgroundColor:"#FFFFFF",navigationBarFrontStyle:"#0C120D",url:t,useSplitScreen:!1}),Promise.resolve()));e(this,"goBack",()=>(window.lx.ui.closeWindow(),Promise.resolve()));e(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));e(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));e(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));e(this,"getCredentials",()=>{try{const t=localStorage.getItem("appCredential")||"",s=localStorage.getItem("userCredential")||"",n={appCredential:t,userCredential:s};return Promise.resolve(n)}catch(t){return console.warn("获取解析 credentials 失败",t),Promise.resolve({})}});e(this,"getAuthCode",async()=>(await N()).authCode);e(this,"getUserInfo",async()=>{const t=await this.getAuthCode();console.log("获取 authCode 成功",t);const s=await this.getAppToken();console.log("获取 appToken 成功",s);const n=await this.getUserToken();return console.log("获取 userToken 成功",n),await O(s,n)});e(this,"getAppToken",async()=>{const t=await M();return this.appToken=t.appToken,t.appToken});e(this,"getUserToken",async()=>{const t=await this.getAuthCode(),s=this.appToken,n=await E(t,s);return this.userToken=n.userToken,n.userToken});e(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));e(this,"setVolume",this.generateBridgeFunc("setVolume"));e(this,"setBrightness",this.generateBridgeFunc("setBrightness"));e(this,"makePhone",this.generateBridgeFunc("makePhone"));e(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));e(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));e(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));e(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));e(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));e(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));e(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));e(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));e(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));e(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));e(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));e(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));e(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));e(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));e(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));e(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));e(this,"getDirectoryFileList",t=>this.getDirectoryFileListNative(JSON.stringify(t)));e(this,"httpRequest",this.generateBridgeFunc("request","Http"));e(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));e(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));e(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));e(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));e(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));e(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));e(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));e(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));e(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));e(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));e(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));e(this,"setBootApp",t=>{var n;const s=(n=window.RKBridge)==null?void 0:n.GlassAppInstall;return!s||typeof s.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(t)});e(this,"showLockScreen",()=>f("showLockScreen"));e(this,"dismissLockScreen",()=>f("dismissLockScreen"));e(this,"isLockScreenShowing",()=>b());e(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));e(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));e(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));e(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));e(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){x("BKBridge"),window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(s,n,g,o)=>{s&&this.emitter.emit(s,n,g,o)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall,window.RKBridge.Http=window.RKBridge_Http);const t=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(s,n,g,o)=>{t==null||t(s,n,g,o),s&&this.emitter.emit(s,n,g,o)}}generateBridgeFunc(t,s){return(...n)=>{var o;const g=s?(o=window.RKBridge)==null?void 0:o[s]:window.RKBridge;return!g||!g[t]?(console.warn(`Bridge method ${s?`${s}.`:""}${t} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((P,k)=>{var h,w,B,p;const c=`cb_${l.v4()}`;this.emitter.on(c,(F,d,A)=>{if(F.toLowerCase()==="success"){if(d)try{d=JSON.parse(d)}catch(T){console.warn("解析 callback 结果失败",T)}P(d)}else F.toLowerCase()==="error"&&k(A);this.emitter.off(c)}),s?(w=(h=window.RKBridge[s])[t])==null||w.call(h,...n,c):(p=(B=window.RKBridge)[t])==null||p.call(B,...n,c)})}}initNativeEventListener(){const t=(s,n)=>{this.emitter.emit(s,n.data)};if(window.dispatchNativeEvent){const s=window.dispatchNativeEvent;window.dispatchNativeEvent=(...n)=>{s(...n),t(...n)}}else window.dispatchNativeEvent=t}};const J=new W;class j extends R{constructor(){super(...arguments);e(this,"emitter",new u);e(this,"hasBackground",!0);e(this,"initSDK",this.generateBridgeFunc("initSDK"));e(this,"registerClientId",this.generateBridgeFunc("registerClientId"));e(this,"navigate",t=>(window.JSBridge.navigate(t),Promise.resolve()));e(this,"goBack",()=>(window.JSBridge.goBack(),Promise.resolve()));e(this,"getDeviceInfo",this.generateBridgeFunc("getDeviceInfo"));e(this,"getStatusBarHeight",this.generateBridgeFunc("getStatusBarHeight"));e(this,"getLocationInfo",this.generateBridgeFunc("getLocationInfo"));e(this,"getAuthCode",this.generateBridgeFunc("getAuthCode"));e(this,"getUserInfo",()=>window.JSBridge.getUserInfo());e(this,"getCredentials",()=>{var t,s;try{const n=JSON.parse((s=(t=window.JSBridge)==null?void 0:t.getCredentials)==null?void 0:s.call(t));return Promise.resolve(n)}catch(n){return console.warn("获取解析 credentials 失败",n),Promise.resolve({})}});e(this,"getAppToken",this.generateBridgeFunc("getAppToken"));e(this,"getUserToken",this.generateBridgeFunc("getUserToken"));e(this,"getSdkToken",this.generateBridgeFunc("getSdkToken"));e(this,"setVolume",this.generateBridgeFunc("setVolume"));e(this,"setBrightness",this.generateBridgeFunc("setBrightness"));e(this,"makePhone",this.generateBridgeFunc("makePhone"));e(this,"sendEventToNative",this.generateBridgeFunc("sendEventToNative"));e(this,"getFileProvider",this.generateBridgeFunc("getFileProvider"));e(this,"startBluetoothScan",this.generateBridgeFunc("startScan","GlassBluetooth"));e(this,"stopBluetoothScan",this.generateBridgeFunc("stopScan","GlassBluetooth"));e(this,"connectBluetooth",this.generateBridgeFunc("connect","GlassBluetooth"));e(this,"startWifiP2PDiscoverPeers",this.generateBridgeFunc("startDiscoverPeers","GlassWifiP2P"));e(this,"stopWifiP2PDiscoverPeers",this.generateBridgeFunc("stopDiscoverPeers","GlassWifiP2P"));e(this,"connectWifiP2P",this.generateBridgeFunc("connect","GlassWifiP2P"));e(this,"getChatList",this.generateBridgeFunc("getChatList","GlassAiChat"));e(this,"getSourceLanguageOptions",this.generateBridgeFunc("getSourceLanguageOptions","GlassTranslation"));e(this,"getTargetLanguageOptions",this.generateBridgeFunc("getTargetLanguageOptions","GlassTranslation"));e(this,"getSourceLanguage",this.generateBridgeFunc("getSourceLanguage","GlassTranslation"));e(this,"getTargetLanguage",this.generateBridgeFunc("getTargetLanguage","GlassTranslation"));e(this,"setLanguage",this.generateBridgeFunc("setLanguage","GlassTranslation"));e(this,"getAlbumFileList",this.generateBridgeFunc("getAlbumFileList","GlassAlbum"));e(this,"getDirectoryFileListNative",this.generateBridgeFunc("getDirectoryFileList","GlassFileSystem"));e(this,"getDirectoryFileList",t=>this.getDirectoryFileListNative(JSON.stringify(t)));e(this,"httpRequest",this.generateBridgeFunc("request","Http"));e(this,"getApps",this.generateBridgeFunc("getApps","GlassAppInstall"));e(this,"getAppInfo",this.generateBridgeFunc("getAppInfo","GlassAppInstall"));e(this,"installApp",this.generateBridgeFunc("installApp","GlassAppInstall"));e(this,"uninstallApp",this.generateBridgeFunc("uninstallApp","GlassAppInstall"));e(this,"launchApp",this.generateBridgeFunc("launchApp","GlassAppInstall"));e(this,"stopApp",this.generateBridgeFunc("stopApp","GlassAppInstall"));e(this,"downloadApk",this.generateBridgeFunc("downloadApk","GlassAppInstall"));e(this,"getActiveInstallTask",this.generateBridgeFunc("getActiveInstallTask","GlassAppInstall"));e(this,"subscribeAppProgress",this.generateBridgeFunc("subscribeAppProgress","GlassAppInstall"));e(this,"unsubscribeAppProgress",this.generateBridgeFunc("unsubscribeAppProgress","GlassAppInstall"));e(this,"setBootAppNative",this.generateBridgeFunc("setBootApp","GlassAppInstall"));e(this,"setBootApp",t=>{var n;const s=(n=window.RKBridge)==null?void 0:n.GlassAppInstall;return!s||typeof s.setBootApp!="function"?Promise.reject(-999):this.setBootAppNative(t)});e(this,"showLockScreen",()=>f("showLockScreen"));e(this,"dismissLockScreen",()=>f("dismissLockScreen"));e(this,"isLockScreenShowing",()=>b());e(this,"sendTextMessageByClassicBT",this.generateBridgeFunc("sendTextMessageByClassicBT","GlassMessage"));e(this,"sendTextMessageByBle",this.generateBridgeFunc("sendTextMessageByBLE","GlassMessage"));e(this,"sendTextMessageByP2P",this.generateBridgeFunc("sendTextMessageByP2P","GlassMessage"));e(this,"sendStreamData",this.generateBridgeFunc("sendStreamData","GlassMessage"));e(this,"sendGlassBroadcast",this.generateBridgeFunc("sendGlassBroadcast","GlassMessage"))}initCallback(){window.RKBridgeCallback||(window.RKBridgeCallback={_onCallback:(s,n,g,o)=>{s&&this.emitter.emit(s,n,g,o)}}),window.RKBridge&&(window.RKBridge.GlassBluetooth=window.RKBridge_GlassBluetooth,window.RKBridge.GlassWifiP2P=window.RKBridge_GlassWifiP2P,window.RKBridge.GlassAiChat=window.RKBridge_GlassAiChat,window.RKBridge.GlassTranslation=window.RKBridge_GlassTranslation,window.RKBridge.GlassAlbum=window.RKBridge_GlassAlbum,window.RKBridge.GlassFileSystem=window.RKBridge_GlassFileSystem,window.RKBridge.GlassMessage=window.RKBridge_GlassMessage,window.RKBridge.GlassAppInstall=window.RKBridge_GlassAppInstall);const t=window.RKBridgeCallback._onCallback;window.RKBridgeCallback._onCallback=(s,n,g,o)=>{t==null||t(s,n,g,o),s&&this.emitter.emit(s,n,g,o)}}generateBridgeFunc(t,s){return(...n)=>{var o;const g=s?(o=window.RKBridge)==null?void 0:o[s]:window.RKBridge;return!g||!g[t]?(console.warn(`Bridge method ${s?`${s}.`:""}${t} is not available, returning default value.`),Promise.resolve(void 0)):new Promise((P,k)=>{var h,w,B,p;const c=`cb_${l.v4()}`;this.emitter.on(c,(F,d,A)=>{if(F.toLowerCase()==="success"){if(d)try{d=JSON.parse(d)}catch(T){console.warn("解析 callback 结果失败",T),console.log(t,s,d,A)}P(d)}else F.toLowerCase()==="error"&&k(A);this.emitter.off(c)}),s?(w=(h=window.RKBridge[s])[t])==null||w.call(h,...n,c):(p=(B=window.RKBridge)[t])==null||p.call(B,...n,c)})}}initNativeEventListener(){const t=(s,n)=>{this.emitter.emit(s,n.data)};if(window.dispatchNativeEvent){const s=window.dispatchNativeEvent;window.dispatchNativeEvent=(...n)=>{s(...n),t(...n)}}else window.dispatchNativeEvent=t}}const $=new j,H=(((y=window==null?void 0:window.navigator)==null?void 0:y.userAgent)||"").includes("lanxin")?J:$;a.BaseBridge=R,a.rkBridge=H,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/lock-screen.d.ts
ADDED
package/package.json
CHANGED
package/rokid/index.d.ts
CHANGED
|
@@ -55,6 +55,9 @@ declare class RKBridge extends BaseBridge {
|
|
|
55
55
|
* 开机自启:Native 未合入时 reject(-999),避免 generateBridgeFunc 缺方法时 resolve(undefined) 误判成功。
|
|
56
56
|
*/
|
|
57
57
|
setBootApp: (packageName: string) => Promise<void>;
|
|
58
|
+
showLockScreen: () => Promise<void>;
|
|
59
|
+
dismissLockScreen: () => Promise<void>;
|
|
60
|
+
isLockScreenShowing: () => Promise<boolean>;
|
|
58
61
|
sendTextMessageByClassicBT: BridgeFuncAsync<void, [string]>;
|
|
59
62
|
sendTextMessageByBle: BridgeFuncAsync<void, [string]>;
|
|
60
63
|
sendTextMessageByP2P: BridgeFuncAsync<void, [string]>;
|
package/zjt/index.d.ts
CHANGED
|
@@ -55,6 +55,9 @@ declare class RKBridge extends BaseBridge {
|
|
|
55
55
|
unsubscribeAppProgress: BridgeFuncAsync<void, []>;
|
|
56
56
|
private setBootAppNative;
|
|
57
57
|
setBootApp: (packageName: string) => Promise<void>;
|
|
58
|
+
showLockScreen: () => Promise<void>;
|
|
59
|
+
dismissLockScreen: () => Promise<void>;
|
|
60
|
+
isLockScreenShowing: () => Promise<boolean>;
|
|
58
61
|
sendTextMessageByClassicBT: BridgeFuncAsync<void, [string]>;
|
|
59
62
|
sendTextMessageByBle: BridgeFuncAsync<void, [string]>;
|
|
60
63
|
sendTextMessageByP2P: BridgeFuncAsync<void, [string]>;
|