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