@lnltch/unitalk-sdk 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/unitalk-sdk.js +13 -2
- package/dist/unitalk-sdk.umd.cjs +2 -2
- package/package.json +1 -1
- package/types/core/sdk.d.ts +4 -1
package/dist/unitalk-sdk.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! UnitalkSDK v1.0.
|
|
1
|
+
/*! UnitalkSDK v1.0.3 | Build Date: 2026-06-04T06:18:05.560Z */
|
|
2
2
|
//#region lib/core/bridge.ts
|
|
3
3
|
var e = class {
|
|
4
4
|
eventListeners = /* @__PURE__ */ new Map();
|
|
@@ -115,7 +115,7 @@ var e = class {
|
|
|
115
115
|
this.options = {
|
|
116
116
|
debug: !1,
|
|
117
117
|
...t
|
|
118
|
-
}, this.version = "1.0.
|
|
118
|
+
}, this.version = "1.0.3", window.UniTalkCompatibleBridge || (window.UniTalkCompatibleBridge = new e()), this.log("SDK 初始化完成");
|
|
119
119
|
}
|
|
120
120
|
log(...e) {
|
|
121
121
|
this.options.debug && console.log("[UnitalkSDK]", ...e);
|
|
@@ -144,6 +144,17 @@ var e = class {
|
|
|
144
144
|
stopScanDevice(e) {
|
|
145
145
|
this.sendAction(r.STOP_SCAN, {}, e);
|
|
146
146
|
}
|
|
147
|
+
checkConnection(e) {
|
|
148
|
+
this.sendAction(r.CHECK_CONNECTION, {}, (t) => {
|
|
149
|
+
t?.code === 0 && t?.data?.connected ? e?.(t) : e?.(!1);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
startRecord(e, t) {
|
|
153
|
+
this.sendAction(r.START_RECORD, e, t);
|
|
154
|
+
}
|
|
155
|
+
stopRecord(e, t) {
|
|
156
|
+
this.sendAction(r.STOP_RECORD, e, t);
|
|
157
|
+
}
|
|
147
158
|
on(e, t) {
|
|
148
159
|
window.UniTalkCompatibleBridge.onEvent(e, t);
|
|
149
160
|
}
|
package/dist/unitalk-sdk.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! UnitalkSDK v1.0.
|
|
1
|
+
/*! UnitalkSDK v1.0.3 | Build Date: 2026-06-04T06:18:05.560Z */
|
|
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.
|
|
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});
|
package/package.json
CHANGED
package/types/core/sdk.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface UnitalkSDKOptions {
|
|
2
2
|
unitalkServerUrl: string;
|
|
3
|
-
unitalkServerToken
|
|
3
|
+
unitalkServerToken?: string;
|
|
4
4
|
debug?: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare class UnitalkSDK {
|
|
@@ -45,6 +45,9 @@ export declare class UnitalkSDK {
|
|
|
45
45
|
* @param callback 停止扫描设备回调
|
|
46
46
|
*/
|
|
47
47
|
stopScanDevice(callback?: (result?: any) => void): void;
|
|
48
|
+
checkConnection(callback?: (result?: any) => void): void;
|
|
49
|
+
startRecord(params?: object, callback?: (result?: any) => void): void;
|
|
50
|
+
stopRecord(params?: object, callback?: (result?: any) => void): void;
|
|
48
51
|
on(eventName: string, callback: (result?: any) => void): void;
|
|
49
52
|
off(eventName: string, callback: (result?: any) => void): void;
|
|
50
53
|
getVersion(): string;
|