@lnltch/unitalk-sdk 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! UnitalkSDK v1.0.3 | Build Date: 2026-06-04T06:18:05.560Z */
1
+ /*! UnitalkSDK v1.0.4 | Build Date: 2026-06-04T07:27:19.741Z */
2
2
  //#region lib/core/bridge.ts
3
3
  var e = class {
4
4
  eventListeners = /* @__PURE__ */ new Map();
@@ -111,11 +111,12 @@ var e = class {
111
111
  }, i = class {
112
112
  options;
113
113
  version;
114
+ dialog = null;
114
115
  constructor(t) {
115
116
  this.options = {
116
117
  debug: !1,
117
118
  ...t
118
- }, this.version = "1.0.3", window.UniTalkCompatibleBridge || (window.UniTalkCompatibleBridge = new e()), this.log("SDK 初始化完成");
119
+ }, this.version = "1.0.4", window.UniTalkCompatibleBridge || (window.UniTalkCompatibleBridge = new e()), this.log("SDK 初始化完成");
119
120
  }
120
121
  log(...e) {
121
122
  this.options.debug && console.log("[UnitalkSDK]", ...e);
@@ -136,7 +137,16 @@ var e = class {
136
137
  new n({ title: "添加设备" }).renderPage("请扫描设备以授权");
137
138
  }
138
139
  openDeviceSelectDialog() {
139
- fetch(this.options.unitalkServerUrl + "/api/device/list");
140
+ fetch(this.options.unitalkServerUrl + "/api/device/list"), this.dialog = new n(), fetch(this.options.unitalkServerUrl + "/api/device/list", {
141
+ method: "GET",
142
+ headers: {
143
+ "X-Access-Token": this.options.unitalkServerToken || "",
144
+ "Content-Type": "application/json"
145
+ }
146
+ }).then((e) => (console.log(e, "=========1111"), e.json())).then((e) => console.log(e));
147
+ }
148
+ closeDeviceSelectDialog() {
149
+ this.dialog &&= (this.dialog.destroy(), null);
140
150
  }
141
151
  scanDevice(e) {
142
152
  this.sendAction(r.SCAN, {}, e);
@@ -146,7 +156,7 @@ var e = class {
146
156
  }
147
157
  checkConnection(e) {
148
158
  this.sendAction(r.CHECK_CONNECTION, {}, (t) => {
149
- t?.code === 0 && t?.data?.connected ? e?.(t) : e?.(!1);
159
+ console.log(t, "=======222======="), t?.code === 0 && t?.data?.connected ? e?.(!0, t) : e?.(!1, t);
150
160
  });
151
161
  }
152
162
  startRecord(e, t) {
@@ -1,4 +1,4 @@
1
- /*! UnitalkSDK v1.0.3 | Build Date: 2026-06-04T06:18:05.560Z */
1
+ /*! UnitalkSDK v1.0.4 | Build Date: 2026-06-04T07:27:19.741Z */
2
2
  (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UnitalkSDK={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{eventListeners=new Map;callbacks=new Map;constructor(){window.UniTalkBridge_handleCallback=this._handleCallback.bind(this),window.UniTalkBridge_dispatchEvent=this._dispatchEvent.bind(this),this.checkNativeBridgeAvailability()}onEvent(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,new Set),this.eventListeners.get(e).add(t)}offEvent(e,t){t?this.eventListeners.get(e)?.delete(t):this.eventListeners.delete(e)}invokeNative(e,t,n){let r=`cb_${Date.now()}_${Math.random().toString(36).slice(2)}`;n&&this.callbacks.set(r,n);let i=JSON.stringify(t??{});window.UniTalkNativeBridge?.invoke?window.UniTalkNativeBridge.invoke(e,i,r):window.webkit?.messageHandlers?.UniTalkNativeBridge?.postMessage?window.webkit.messageHandlers.UniTalkNativeBridge.postMessage({method:e,params:i,callbackId:r}):n&&n(Error(`[UniTalkNativeBridge] No native bridge found`))}toLogin(){window.UniTalkNativeBridge&&typeof window.UniTalkNativeBridge.toLogin==`function`?window.UniTalkNativeBridge.toLogin():window.location.href=`/login`}getToken(){return window.UniTalkNativeBridge?.getToken()||``}_handleCallback(e,t){let n=this.callbacks.get(e);n&&(n(t),this.callbacks.delete(e))}_dispatchEvent(e,t){let n=this.eventListeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[UniTalkNativeBridge] Error in event listener for "${e}"`,t)}})}checkNativeBridgeAvailability(){this.isAndroidOrHarmony()?window.UniTalkNativeBridge&&typeof window.UniTalkNativeBridge.invoke==`function`?console.log(`[UniTalkNativeBridge] Android/Harmony 原生桥接已就绪`):console.error(`[UniTalkNativeBridge] Android/Harmony 原生桥接不可用,请确保已注入 window.UniTalkNativeBridge.invoke`):this.isIOS()?window.webkit?.messageHandlers?.UniTalkNativeBridge?console.log(`[UniTalkNativeBridge] iOS 原生桥接已就绪`):console.error(`[UniTalkNativeBridge] iOS 原生桥接不可用,请确保已配置 messageHandlers.UniTalkNativeBridge`):console.error(`[UniTalkNativeBridge] 未知环境,无法检测原生桥接`)}isAndroidOrHarmony(){let e=navigator.userAgent.toLowerCase();return e.includes(`android`)||e.includes(`harmony`)||e.includes(`openharmony`)}isIOS(){let e=navigator.userAgent.toLowerCase();return e.includes(`iphone`)||e.includes(`ipad`)||e.includes(`ipod`)}},n=`<div class="sdk-panel">
3
3
  <!-- <img class="sdk-logo" data-img="logo" alt="logo" /> -->
4
4
  <h3 class="sdk-title">SDK 内置页面</h3>
@@ -44,4 +44,4 @@
44
44
  background: rgba(0,0,0,0.7);
45
45
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
46
46
  z-index: 9999;
47
- `,document.body.appendChild(e),e?.addEventListener(`click`,()=>{this.destroy()}),this.container=e,e}renderPage(e){let t=(this.container||this.createContainer()).attachShadow({mode:`open`}),n=this.template.content.cloneNode(!0);t.appendChild(n);let r=t.querySelector(`[data-content]`);r&&(r.textContent=e),t.querySelector(`[data-close]`)?.addEventListener(`click`,()=>this.destroy())}destroy(){this.container?.remove(),this.container=null}},i={AUTH:`auth`,SCAN:`scan`,STOP_SCAN:`stopScan`,CONNECT:`connect`,AUTO_CONNECT:`autoConnect`,DISCONNECT:`disconnect`,CHECK_CONNECTION:`checkConnection`,SWITCH_DEVICE:`switchDevice`,GET_ABILITY:`getAbility`,GET_BASIC_INFO:`getBasicInfo`,GET_STATUS:`getStatus`,GET_DEVICE_INFO:`getDeviceInfo`,GET_STORAGE_INFO:`getStorageInfo`,PICKUP_MODE:`pickupMode`,QUERY_SN:`querySN`,BIND:`bind`,UNBIND:`unbind`,START_RECORD:`startRecord`,PAUSE_RECORD:`pauseRecord`,RESUME_RECORD:`resumeRecord`,STOP_RECORD:`stopRecord`,SET_NAME:`setName`,SWITCH_AIMODE:`switchAIMode`,FORMAT_DEVICE:`formatDevice`,RESET_SETTINGS:`resetSettings`,SWITCH_WIFI:`switchWifi`,GET_FILES:`getFiles`,DOWNLOAD_FILES:`downloadFiles`,STOP_DOWNLOAD:`stopDownload`,DELETE_FILE:`deleteFile`,SYNC_FILE:`syncFile`,SYNC_DEVICE_FILES:`syncDeviceFiles`,SET_SLEEP_TIME:`setSleepTime`},a=class{options;version;constructor(e){this.options={debug:!1,...e},this.version=`1.0.3`,window.UniTalkCompatibleBridge||(window.UniTalkCompatibleBridge=new t),this.log(`SDK 初始化完成`)}log(...e){this.options.debug&&console.log(`[UnitalkSDK]`,...e)}setServer(e){this.options.unitalkServerUrl=e}setToken(e){this.options.unitalkServerToken=e}sendAction(e,t,n){window.UniTalkCompatibleBridge.invokeNative(e,t,n)}auth(e){this.sendAction(i.AUTH,{},e)}openScanDeviceDialog(){new r({title:`添加设备`}).renderPage(`请扫描设备以授权`)}openDeviceSelectDialog(){fetch(this.options.unitalkServerUrl+`/api/device/list`)}scanDevice(e){this.sendAction(i.SCAN,{},e)}stopScanDevice(e){this.sendAction(i.STOP_SCAN,{},e)}checkConnection(e){this.sendAction(i.CHECK_CONNECTION,{},t=>{t?.code===0&&t?.data?.connected?e?.(t):e?.(!1)})}startRecord(e,t){this.sendAction(i.START_RECORD,e,t)}stopRecord(e,t){this.sendAction(i.STOP_RECORD,e,t)}on(e,t){window.UniTalkCompatibleBridge.onEvent(e,t)}off(e,t){window.UniTalkCompatibleBridge.offEvent(e,t)}getVersion(){return this.version}};window.UnitalkSDK=a,e.UnitalkSDK=a});
47
+ `,document.body.appendChild(e),e?.addEventListener(`click`,()=>{this.destroy()}),this.container=e,e}renderPage(e){let t=(this.container||this.createContainer()).attachShadow({mode:`open`}),n=this.template.content.cloneNode(!0);t.appendChild(n);let r=t.querySelector(`[data-content]`);r&&(r.textContent=e),t.querySelector(`[data-close]`)?.addEventListener(`click`,()=>this.destroy())}destroy(){this.container?.remove(),this.container=null}},i={AUTH:`auth`,SCAN:`scan`,STOP_SCAN:`stopScan`,CONNECT:`connect`,AUTO_CONNECT:`autoConnect`,DISCONNECT:`disconnect`,CHECK_CONNECTION:`checkConnection`,SWITCH_DEVICE:`switchDevice`,GET_ABILITY:`getAbility`,GET_BASIC_INFO:`getBasicInfo`,GET_STATUS:`getStatus`,GET_DEVICE_INFO:`getDeviceInfo`,GET_STORAGE_INFO:`getStorageInfo`,PICKUP_MODE:`pickupMode`,QUERY_SN:`querySN`,BIND:`bind`,UNBIND:`unbind`,START_RECORD:`startRecord`,PAUSE_RECORD:`pauseRecord`,RESUME_RECORD:`resumeRecord`,STOP_RECORD:`stopRecord`,SET_NAME:`setName`,SWITCH_AIMODE:`switchAIMode`,FORMAT_DEVICE:`formatDevice`,RESET_SETTINGS:`resetSettings`,SWITCH_WIFI:`switchWifi`,GET_FILES:`getFiles`,DOWNLOAD_FILES:`downloadFiles`,STOP_DOWNLOAD:`stopDownload`,DELETE_FILE:`deleteFile`,SYNC_FILE:`syncFile`,SYNC_DEVICE_FILES:`syncDeviceFiles`,SET_SLEEP_TIME:`setSleepTime`},a=class{options;version;dialog=null;constructor(e){this.options={debug:!1,...e},this.version=`1.0.4`,window.UniTalkCompatibleBridge||(window.UniTalkCompatibleBridge=new t),this.log(`SDK 初始化完成`)}log(...e){this.options.debug&&console.log(`[UnitalkSDK]`,...e)}setServer(e){this.options.unitalkServerUrl=e}setToken(e){this.options.unitalkServerToken=e}sendAction(e,t,n){window.UniTalkCompatibleBridge.invokeNative(e,t,n)}auth(e){this.sendAction(i.AUTH,{},e)}openScanDeviceDialog(){new r({title:`添加设备`}).renderPage(`请扫描设备以授权`)}openDeviceSelectDialog(){fetch(this.options.unitalkServerUrl+`/api/device/list`),this.dialog=new r,fetch(this.options.unitalkServerUrl+`/api/device/list`,{method:`GET`,headers:{"X-Access-Token":this.options.unitalkServerToken||``,"Content-Type":`application/json`}}).then(e=>(console.log(e,`=========1111`),e.json())).then(e=>console.log(e))}closeDeviceSelectDialog(){this.dialog&&=(this.dialog.destroy(),null)}scanDevice(e){this.sendAction(i.SCAN,{},e)}stopScanDevice(e){this.sendAction(i.STOP_SCAN,{},e)}checkConnection(e){this.sendAction(i.CHECK_CONNECTION,{},t=>{console.log(t,`=======222=======`),t?.code===0&&t?.data?.connected?e?.(!0,t):e?.(!1,t)})}startRecord(e,t){this.sendAction(i.START_RECORD,e,t)}stopRecord(e,t){this.sendAction(i.STOP_RECORD,e,t)}on(e,t){window.UniTalkCompatibleBridge.onEvent(e,t)}off(e,t){window.UniTalkCompatibleBridge.offEvent(e,t)}getVersion(){return this.version}};window.UnitalkSDK=a,e.UnitalkSDK=a});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lnltch/unitalk-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/unitalk-sdk.umd.cjs",
6
6
  "module": "./dist/unitalk-sdk.js",
@@ -6,6 +6,7 @@ export interface UnitalkSDKOptions {
6
6
  export declare class UnitalkSDK {
7
7
  private options;
8
8
  private version;
9
+ private dialog;
9
10
  constructor(options: UnitalkSDKOptions);
10
11
  private log;
11
12
  /**
@@ -35,6 +36,7 @@ export declare class UnitalkSDK {
35
36
  */
36
37
  openScanDeviceDialog(): void;
37
38
  openDeviceSelectDialog(): void;
39
+ closeDeviceSelectDialog(): void;
38
40
  /**
39
41
  * 扫描设备
40
42
  * @param callback 扫描设备回调
@@ -45,7 +47,7 @@ export declare class UnitalkSDK {
45
47
  * @param callback 停止扫描设备回调
46
48
  */
47
49
  stopScanDevice(callback?: (result?: any) => void): void;
48
- checkConnection(callback?: (result?: any) => void): void;
50
+ checkConnection(callback?: (success?: boolean, result?: any) => void): void;
49
51
  startRecord(params?: object, callback?: (result?: any) => void): void;
50
52
  stopRecord(params?: object, callback?: (result?: any) => void): void;
51
53
  on(eventName: string, callback: (result?: any) => void): void;
package/types/index.d.ts CHANGED
@@ -2,8 +2,3 @@ import { UnitalkSDK } from './core/sdk';
2
2
  import type { UnitalkSDKOptions } from './core/sdk';
3
3
  export type { UnitalkSDKOptions };
4
4
  export { UnitalkSDK };
5
- declare global {
6
- interface Window {
7
- unitalkSDK: typeof UnitalkSDK;
8
- }
9
- }