@lnltch/unitalk-sdk 1.0.2
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/LICENSE +22 -0
- package/dist/unitalk-sdk.js +161 -0
- package/dist/unitalk-sdk.umd.cjs +47 -0
- package/package.json +52 -0
- package/types/core/bridge.d.ts +55 -0
- package/types/core/dialog.d.ts +14 -0
- package/types/core/sdk.d.ts +51 -0
- package/types/dom/page.d.ts +9 -0
- package/types/enum/action.d.ts +36 -0
- package/types/index.d.ts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Unitalk
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*! UnitalkSDK v1.0.1 | Build Date: 2026-06-02T02:27:38.523Z */
|
|
2
|
+
//#region lib/core/bridge.ts
|
|
3
|
+
var e = class {
|
|
4
|
+
eventListeners = /* @__PURE__ */ new Map();
|
|
5
|
+
callbacks = /* @__PURE__ */ new Map();
|
|
6
|
+
constructor() {
|
|
7
|
+
window.UniTalkBridge_handleCallback = this._handleCallback.bind(this), window.UniTalkBridge_dispatchEvent = this._dispatchEvent.bind(this), this.checkNativeBridgeAvailability();
|
|
8
|
+
}
|
|
9
|
+
onEvent(e, t) {
|
|
10
|
+
this.eventListeners.has(e) || this.eventListeners.set(e, /* @__PURE__ */ new Set()), this.eventListeners.get(e).add(t);
|
|
11
|
+
}
|
|
12
|
+
offEvent(e, t) {
|
|
13
|
+
t ? this.eventListeners.get(e)?.delete(t) : this.eventListeners.delete(e);
|
|
14
|
+
}
|
|
15
|
+
invokeNative(e, t, n) {
|
|
16
|
+
let r = `cb_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
17
|
+
n && this.callbacks.set(r, n);
|
|
18
|
+
let i = JSON.stringify(t ?? {});
|
|
19
|
+
window.UniTalkNativeBridge?.invoke ? window.UniTalkNativeBridge.invoke(e, i, r) : window.webkit?.messageHandlers?.UniTalkNativeBridge?.postMessage ? window.webkit.messageHandlers.UniTalkNativeBridge.postMessage({
|
|
20
|
+
method: e,
|
|
21
|
+
params: i,
|
|
22
|
+
callbackId: r
|
|
23
|
+
}) : n && n(/* @__PURE__ */ Error("[UniTalkNativeBridge] No native bridge found"));
|
|
24
|
+
}
|
|
25
|
+
toLogin() {
|
|
26
|
+
window.UniTalkNativeBridge && typeof window.UniTalkNativeBridge.toLogin == "function" ? window.UniTalkNativeBridge.toLogin() : window.location.href = "/login";
|
|
27
|
+
}
|
|
28
|
+
getToken() {
|
|
29
|
+
return window.UniTalkNativeBridge?.getToken() || "";
|
|
30
|
+
}
|
|
31
|
+
_handleCallback(e, t) {
|
|
32
|
+
let n = this.callbacks.get(e);
|
|
33
|
+
n && (n(t), this.callbacks.delete(e));
|
|
34
|
+
}
|
|
35
|
+
_dispatchEvent(e, t) {
|
|
36
|
+
let n = this.eventListeners.get(e);
|
|
37
|
+
n && n.forEach((n) => {
|
|
38
|
+
try {
|
|
39
|
+
n(t);
|
|
40
|
+
} catch (t) {
|
|
41
|
+
console.error(`[UniTalkNativeBridge] Error in event listener for "${e}"`, t);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
checkNativeBridgeAvailability() {
|
|
46
|
+
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] 未知环境,无法检测原生桥接");
|
|
47
|
+
}
|
|
48
|
+
isAndroidOrHarmony() {
|
|
49
|
+
let e = navigator.userAgent.toLowerCase();
|
|
50
|
+
return e.includes("android") || e.includes("harmony") || e.includes("openharmony");
|
|
51
|
+
}
|
|
52
|
+
isIOS() {
|
|
53
|
+
let e = navigator.userAgent.toLowerCase();
|
|
54
|
+
return e.includes("iphone") || e.includes("ipad") || e.includes("ipod");
|
|
55
|
+
}
|
|
56
|
+
}, t = "<div class=\"sdk-panel\">\n <!-- <img class=\"sdk-logo\" data-img=\"logo\" alt=\"logo\" /> -->\n <h3 class=\"sdk-title\">SDK 内置页面</h3>\n <div class=\"sdk-content\" data-content></div>\n <button class=\"sdk-close\" data-close>关闭</button>\n</div>\n\n<style>\n .sdk-panel {\n position: fixed;\n top: 20px;\n right: 20px;\n width: 320px;\n padding: 16px;\n background: #fff;\n border-radius: 8px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);\n z-index: 9999;\n }\n .sdk-logo {\n width: 120px;\n margin-bottom: 10px;\n }\n .sdk-title {\n margin: 0 0 12px;\n font-size: 16px;\n }\n .sdk-content {\n font-size: 14px;\n color: #333;\n }\n .sdk-close {\n margin-top: 12px;\n padding: 4px 8px;\n }\n</style>\n", n = class {
|
|
57
|
+
container = null;
|
|
58
|
+
template;
|
|
59
|
+
constructor(e) {
|
|
60
|
+
this.template = document.createElement("template"), this.template.innerHTML = t;
|
|
61
|
+
}
|
|
62
|
+
createContainer() {
|
|
63
|
+
let e = document.createElement("div");
|
|
64
|
+
return e.id = "unitalk-sdk-dialog", e.style.cssText = "\n position: fixed;\n top: 0;\n bottom: 0;\n right: 0;\n left: 0;\n background: rgba(0,0,0,0.7);\n box-shadow: 0 0 10px rgba(0,0,0,0.2);\n z-index: 9999;\n ", document.body.appendChild(e), e?.addEventListener("click", () => {
|
|
65
|
+
this.destroy();
|
|
66
|
+
}), this.container = e, e;
|
|
67
|
+
}
|
|
68
|
+
renderPage(e) {
|
|
69
|
+
let t = (this.container || this.createContainer()).attachShadow({ mode: "open" }), n = this.template.content.cloneNode(!0);
|
|
70
|
+
t.appendChild(n);
|
|
71
|
+
let r = t.querySelector("[data-content]");
|
|
72
|
+
r && (r.textContent = e), t.querySelector("[data-close]")?.addEventListener("click", () => this.destroy());
|
|
73
|
+
}
|
|
74
|
+
destroy() {
|
|
75
|
+
this.container?.remove(), this.container = null;
|
|
76
|
+
}
|
|
77
|
+
}, r = {
|
|
78
|
+
AUTH: "auth",
|
|
79
|
+
SCAN: "scan",
|
|
80
|
+
STOP_SCAN: "stopScan",
|
|
81
|
+
CONNECT: "connect",
|
|
82
|
+
AUTO_CONNECT: "autoConnect",
|
|
83
|
+
DISCONNECT: "disconnect",
|
|
84
|
+
CHECK_CONNECTION: "checkConnection",
|
|
85
|
+
SWITCH_DEVICE: "switchDevice",
|
|
86
|
+
GET_ABILITY: "getAbility",
|
|
87
|
+
GET_BASIC_INFO: "getBasicInfo",
|
|
88
|
+
GET_STATUS: "getStatus",
|
|
89
|
+
GET_DEVICE_INFO: "getDeviceInfo",
|
|
90
|
+
GET_STORAGE_INFO: "getStorageInfo",
|
|
91
|
+
PICKUP_MODE: "pickupMode",
|
|
92
|
+
QUERY_SN: "querySN",
|
|
93
|
+
BIND: "bind",
|
|
94
|
+
UNBIND: "unbind",
|
|
95
|
+
START_RECORD: "startRecord",
|
|
96
|
+
PAUSE_RECORD: "pauseRecord",
|
|
97
|
+
RESUME_RECORD: "resumeRecord",
|
|
98
|
+
STOP_RECORD: "stopRecord",
|
|
99
|
+
SET_NAME: "setName",
|
|
100
|
+
SWITCH_AIMODE: "switchAIMode",
|
|
101
|
+
FORMAT_DEVICE: "formatDevice",
|
|
102
|
+
RESET_SETTINGS: "resetSettings",
|
|
103
|
+
SWITCH_WIFI: "switchWifi",
|
|
104
|
+
GET_FILES: "getFiles",
|
|
105
|
+
DOWNLOAD_FILES: "downloadFiles",
|
|
106
|
+
STOP_DOWNLOAD: "stopDownload",
|
|
107
|
+
DELETE_FILE: "deleteFile",
|
|
108
|
+
SYNC_FILE: "syncFile",
|
|
109
|
+
SYNC_DEVICE_FILES: "syncDeviceFiles",
|
|
110
|
+
SET_SLEEP_TIME: "setSleepTime"
|
|
111
|
+
}, i = class {
|
|
112
|
+
options;
|
|
113
|
+
version;
|
|
114
|
+
constructor(t) {
|
|
115
|
+
this.options = {
|
|
116
|
+
debug: !1,
|
|
117
|
+
...t
|
|
118
|
+
}, this.version = "1.0.1", window.UniTalkCompatibleBridge || (window.UniTalkCompatibleBridge = new e()), this.log("SDK 初始化完成");
|
|
119
|
+
}
|
|
120
|
+
log(...e) {
|
|
121
|
+
this.options.debug && console.log("[UnitalkSDK]", ...e);
|
|
122
|
+
}
|
|
123
|
+
setServer(e) {
|
|
124
|
+
this.options.unitalkServerUrl = e;
|
|
125
|
+
}
|
|
126
|
+
setToken(e) {
|
|
127
|
+
this.options.unitalkServerToken = e;
|
|
128
|
+
}
|
|
129
|
+
sendAction(e, t, n) {
|
|
130
|
+
window.UniTalkCompatibleBridge.invokeNative(e, t, n);
|
|
131
|
+
}
|
|
132
|
+
auth(e) {
|
|
133
|
+
this.sendAction(r.AUTH, {}, e);
|
|
134
|
+
}
|
|
135
|
+
openScanDeviceDialog() {
|
|
136
|
+
new n({ title: "添加设备" }).renderPage("请扫描设备以授权");
|
|
137
|
+
}
|
|
138
|
+
openDeviceSelectDialog() {
|
|
139
|
+
fetch(this.options.unitalkServerUrl + "/api/device/list");
|
|
140
|
+
}
|
|
141
|
+
scanDevice(e) {
|
|
142
|
+
this.sendAction(r.SCAN, {}, e);
|
|
143
|
+
}
|
|
144
|
+
stopScanDevice(e) {
|
|
145
|
+
this.sendAction(r.STOP_SCAN, {}, e);
|
|
146
|
+
}
|
|
147
|
+
on(e, t) {
|
|
148
|
+
window.UniTalkCompatibleBridge.onEvent(e, t);
|
|
149
|
+
}
|
|
150
|
+
off(e, t) {
|
|
151
|
+
window.UniTalkCompatibleBridge.offEvent(e, t);
|
|
152
|
+
}
|
|
153
|
+
getVersion() {
|
|
154
|
+
return this.version;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region lib/index.ts
|
|
159
|
+
window.UnitalkSDK = i;
|
|
160
|
+
//#endregion
|
|
161
|
+
export { i as UnitalkSDK };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*! UnitalkSDK v1.0.1 | Build Date: 2026-06-02T02:27:38.523Z */
|
|
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
|
+
<!-- <img class="sdk-logo" data-img="logo" alt="logo" /> -->
|
|
4
|
+
<h3 class="sdk-title">SDK 内置页面</h3>
|
|
5
|
+
<div class="sdk-content" data-content></div>
|
|
6
|
+
<button class="sdk-close" data-close>关闭</button>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
.sdk-panel {
|
|
11
|
+
position: fixed;
|
|
12
|
+
top: 20px;
|
|
13
|
+
right: 20px;
|
|
14
|
+
width: 320px;
|
|
15
|
+
padding: 16px;
|
|
16
|
+
background: #fff;
|
|
17
|
+
border-radius: 8px;
|
|
18
|
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
|
|
19
|
+
z-index: 9999;
|
|
20
|
+
}
|
|
21
|
+
.sdk-logo {
|
|
22
|
+
width: 120px;
|
|
23
|
+
margin-bottom: 10px;
|
|
24
|
+
}
|
|
25
|
+
.sdk-title {
|
|
26
|
+
margin: 0 0 12px;
|
|
27
|
+
font-size: 16px;
|
|
28
|
+
}
|
|
29
|
+
.sdk-content {
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
color: #333;
|
|
32
|
+
}
|
|
33
|
+
.sdk-close {
|
|
34
|
+
margin-top: 12px;
|
|
35
|
+
padding: 4px 8px;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
38
|
+
`,r=class{container=null;template;constructor(e){this.template=document.createElement(`template`),this.template.innerHTML=n}createContainer(){let e=document.createElement(`div`);return e.id=`unitalk-sdk-dialog`,e.style.cssText=`
|
|
39
|
+
position: fixed;
|
|
40
|
+
top: 0;
|
|
41
|
+
bottom: 0;
|
|
42
|
+
right: 0;
|
|
43
|
+
left: 0;
|
|
44
|
+
background: rgba(0,0,0,0.7);
|
|
45
|
+
box-shadow: 0 0 10px rgba(0,0,0,0.2);
|
|
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.1`,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)}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
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lnltch/unitalk-sdk",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/unitalk-sdk.umd.cjs",
|
|
6
|
+
"module": "./dist/unitalk-sdk.js",
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/unitalk-sdk.js",
|
|
11
|
+
"require": "./dist/unitalk-sdk.umd.cjs",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"types"
|
|
18
|
+
],
|
|
19
|
+
"private": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"author": "lnltch",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "tsc && vite build",
|
|
29
|
+
"lint": "oxlint",
|
|
30
|
+
"lint:fix": "oxlint --fix",
|
|
31
|
+
"format": "oxfmt lib/",
|
|
32
|
+
"format:check": "oxfmt --check lib/",
|
|
33
|
+
"release": "pnpm publish --no-git-checks"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^24.11.1",
|
|
37
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
38
|
+
"@vue/runtime-core": "^3.5.35",
|
|
39
|
+
"@vue/tsconfig": "^0.9.1",
|
|
40
|
+
"oxfmt": "^0.52.0",
|
|
41
|
+
"oxlint": "^1.67.0",
|
|
42
|
+
"path": "^0.12.7",
|
|
43
|
+
"sass": "^1.100.0",
|
|
44
|
+
"sass-loader": "^17.0.0",
|
|
45
|
+
"typescript": "~6.0.2",
|
|
46
|
+
"vite": "^8.0.3",
|
|
47
|
+
"vite-plugin-banner": "^0.8.1",
|
|
48
|
+
"vite-plugin-oxlint": "^2.1.1",
|
|
49
|
+
"vue": "^3.5.34",
|
|
50
|
+
"vue-tsc": "^3.3.2"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
interface UniTalkCompatibleBridge {
|
|
2
|
+
onEvent(eventName: string, callback: (data?: any) => void): void;
|
|
3
|
+
offEvent(eventName: string, callback?: (data?: any) => void): void;
|
|
4
|
+
invokeNative(method: string, params?: any, callback?: (result?: any) => void): void;
|
|
5
|
+
toLogin(): void;
|
|
6
|
+
getToken(): string;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
UniTalkCompatibleBridge: UniTalkCompatibleBridge;
|
|
11
|
+
UniTalkBridge_handleCallback?: (callbackId: string, result: any) => void;
|
|
12
|
+
UniTalkBridge_dispatchEvent?: (eventName: string, data?: any) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 内部使用 - 原生注入的底层桥对象,业务代码请使用 UniTalkCompatibleBridge
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
UniTalkNativeBridge?: {
|
|
18
|
+
invoke(method: string, params: string, callbackId: string): void;
|
|
19
|
+
getToken(): string;
|
|
20
|
+
toLogin(): void;
|
|
21
|
+
};
|
|
22
|
+
webkit?: {
|
|
23
|
+
messageHandlers?: {
|
|
24
|
+
UniTalkNativeBridge?: {
|
|
25
|
+
postMessage(message: any): void;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export default class Bridge implements UniTalkCompatibleBridge {
|
|
32
|
+
private eventListeners;
|
|
33
|
+
private callbacks;
|
|
34
|
+
constructor();
|
|
35
|
+
onEvent(eventName: string, callback: (data?: any) => void): void;
|
|
36
|
+
offEvent(eventName: string, callback?: (data?: any) => void): void;
|
|
37
|
+
invokeNative(method: string, params?: any, callback?: (error: any, result?: any) => void): void;
|
|
38
|
+
toLogin(): void;
|
|
39
|
+
getToken(): string;
|
|
40
|
+
private _handleCallback;
|
|
41
|
+
private _dispatchEvent;
|
|
42
|
+
/**
|
|
43
|
+
* 检测原生桥接环境,输出调试信息
|
|
44
|
+
*/
|
|
45
|
+
private checkNativeBridgeAvailability;
|
|
46
|
+
/**
|
|
47
|
+
* 判断是否为 Android 或鸿蒙
|
|
48
|
+
*/
|
|
49
|
+
private isAndroidOrHarmony;
|
|
50
|
+
/**
|
|
51
|
+
* 判断是否为 iOS
|
|
52
|
+
*/
|
|
53
|
+
private isIOS;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface DialogOption {
|
|
2
|
+
}
|
|
3
|
+
/**
|
|
4
|
+
* 动态创建 SDK 页面/弹窗
|
|
5
|
+
*/
|
|
6
|
+
export default class Dialog {
|
|
7
|
+
private container;
|
|
8
|
+
private template;
|
|
9
|
+
constructor(_option?: DialogOption);
|
|
10
|
+
private createContainer;
|
|
11
|
+
renderPage(content: string): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface UnitalkSDKOptions {
|
|
2
|
+
unitalkServerUrl: string;
|
|
3
|
+
unitalkServerToken: string;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class UnitalkSDK {
|
|
7
|
+
private options;
|
|
8
|
+
private version;
|
|
9
|
+
constructor(options: UnitalkSDKOptions);
|
|
10
|
+
private log;
|
|
11
|
+
/**
|
|
12
|
+
* 设置 Unitalk 服务器 URL
|
|
13
|
+
* @param url Unitalk 服务器 URL
|
|
14
|
+
*/
|
|
15
|
+
setServer(url: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* 设置 Unitalk 服务器 Token
|
|
18
|
+
* @param token Unitalk 服务器 Token
|
|
19
|
+
*/
|
|
20
|
+
setToken(token: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* 发送操作
|
|
23
|
+
* @param action 操作名称
|
|
24
|
+
* @param params 操作参数
|
|
25
|
+
* @param callback 操作回调
|
|
26
|
+
*/
|
|
27
|
+
private sendAction;
|
|
28
|
+
/**
|
|
29
|
+
* 蓝牙授权
|
|
30
|
+
* @param callback 蓝牙授权回调
|
|
31
|
+
*/
|
|
32
|
+
auth(callback?: (result?: any) => void): void;
|
|
33
|
+
/**
|
|
34
|
+
* 打开添加设备弹窗
|
|
35
|
+
*/
|
|
36
|
+
openScanDeviceDialog(): void;
|
|
37
|
+
openDeviceSelectDialog(): void;
|
|
38
|
+
/**
|
|
39
|
+
* 扫描设备
|
|
40
|
+
* @param callback 扫描设备回调
|
|
41
|
+
*/
|
|
42
|
+
scanDevice(callback?: (result?: any) => void): void;
|
|
43
|
+
/**
|
|
44
|
+
* 停止扫描设备
|
|
45
|
+
* @param callback 停止扫描设备回调
|
|
46
|
+
*/
|
|
47
|
+
stopScanDevice(callback?: (result?: any) => void): void;
|
|
48
|
+
on(eventName: string, callback: (result?: any) => void): void;
|
|
49
|
+
off(eventName: string, callback: (result?: any) => void): void;
|
|
50
|
+
getVersion(): string;
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const ActionEnum: {
|
|
2
|
+
AUTH: string;
|
|
3
|
+
SCAN: string;
|
|
4
|
+
STOP_SCAN: string;
|
|
5
|
+
CONNECT: string;
|
|
6
|
+
AUTO_CONNECT: string;
|
|
7
|
+
DISCONNECT: string;
|
|
8
|
+
CHECK_CONNECTION: string;
|
|
9
|
+
SWITCH_DEVICE: string;
|
|
10
|
+
GET_ABILITY: string;
|
|
11
|
+
GET_BASIC_INFO: string;
|
|
12
|
+
GET_STATUS: string;
|
|
13
|
+
GET_DEVICE_INFO: string;
|
|
14
|
+
GET_STORAGE_INFO: string;
|
|
15
|
+
PICKUP_MODE: string;
|
|
16
|
+
QUERY_SN: string;
|
|
17
|
+
BIND: string;
|
|
18
|
+
UNBIND: string;
|
|
19
|
+
START_RECORD: string;
|
|
20
|
+
PAUSE_RECORD: string;
|
|
21
|
+
RESUME_RECORD: string;
|
|
22
|
+
STOP_RECORD: string;
|
|
23
|
+
SET_NAME: string;
|
|
24
|
+
SWITCH_AIMODE: string;
|
|
25
|
+
FORMAT_DEVICE: string;
|
|
26
|
+
RESET_SETTINGS: string;
|
|
27
|
+
SWITCH_WIFI: string;
|
|
28
|
+
GET_FILES: string;
|
|
29
|
+
DOWNLOAD_FILES: string;
|
|
30
|
+
STOP_DOWNLOAD: string;
|
|
31
|
+
DELETE_FILE: string;
|
|
32
|
+
SYNC_FILE: string;
|
|
33
|
+
SYNC_DEVICE_FILES: string;
|
|
34
|
+
SET_SLEEP_TIME: string;
|
|
35
|
+
};
|
|
36
|
+
export type ActionEnumType = (typeof ActionEnum)[keyof typeof ActionEnum];
|
package/types/index.d.ts
ADDED