@video-supply/dahua-player 0.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/CHANGELOG.md +9 -0
- package/LICENSE +1 -0
- package/README.md +192 -0
- package/README.zh-CN.md +202 -0
- package/dist/bin/copy-assets.cjs +51 -0
- package/dist/bin/copy-assets.cjs.map +1 -0
- package/dist/index.cjs +1447 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.js +1418 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
- package/wsplayer-gov/Version.xml +4 -0
- package/wsplayer-gov/WSPlayer/PlaySDKInterface.js +1 -0
- package/wsplayer-gov/WSPlayer/WSPlayer.js +1 -0
- package/wsplayer-gov/WSPlayer/audioTalkWorker.js +1 -0
- package/wsplayer-gov/WSPlayer/commonThread/libH264Enc.js +21 -0
- package/wsplayer-gov/WSPlayer/commonThread/libH264Enc.wasm +0 -0
- package/wsplayer-gov/WSPlayer/commonThread/libIVSDrawer.js +21 -0
- package/wsplayer-gov/WSPlayer/commonThread/libIVSDrawer.wasm +0 -0
- package/wsplayer-gov/WSPlayer/commonThread/libRenderEngine.js +21 -0
- package/wsplayer-gov/WSPlayer/commonThread/libRenderEngine.wasm +0 -0
- package/wsplayer-gov/WSPlayer/commonThread/libmavasp_litepacket.data +50 -0
- package/wsplayer-gov/WSPlayer/commonThread/libmavasp_litepacket.js +21 -0
- package/wsplayer-gov/WSPlayer/commonThread/libmavasp_litepacket.wasm +0 -0
- package/wsplayer-gov/WSPlayer/icon/RecordHover.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/RecordNormal.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/Recording.svg +15 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-b.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-l.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-lb.svg +10 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-lt.svg +10 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-r.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-rb.svg +10 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-rt.svg +10 -0
- package/wsplayer-gov/WSPlayer/icon/arrow-t.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/close-all-hover.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/close-all.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/close.svg +16 -0
- package/wsplayer-gov/WSPlayer/icon/close_hover.svg +16 -0
- package/wsplayer-gov/WSPlayer/icon/default.png +0 -0
- package/wsplayer-gov/WSPlayer/icon/draw-triangle_off.svg +14 -0
- package/wsplayer-gov/WSPlayer/icon/draw-triangle_off_hover.svg +14 -0
- package/wsplayer-gov/WSPlayer/icon/draw-triangle_on.svg +15 -0
- package/wsplayer-gov/WSPlayer/icon/draw-triangle_on_hover.svg +15 -0
- package/wsplayer-gov/WSPlayer/icon/fullscreen-hover.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/fullscreen.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/more.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/play-h.png +0 -0
- package/wsplayer-gov/WSPlayer/icon/play-n.png +0 -0
- package/wsplayer-gov/WSPlayer/icon/play-p.png +0 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-icon1.svg +4 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-icon2.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-icon3.svg +10 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-icon4.svg +10 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-icon5.svg +12 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-icon6.svg +14 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-select-hover.svg +3 -0
- package/wsplayer-gov/WSPlayer/icon/ptz-select.svg +3 -0
- package/wsplayer-gov/WSPlayer/icon/record_pause.svg +5 -0
- package/wsplayer-gov/WSPlayer/icon/record_play.svg +5 -0
- package/wsplayer-gov/WSPlayer/icon/screen_1.svg +11 -0
- package/wsplayer-gov/WSPlayer/icon/screen_16.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/screen_16_hover.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/screen_1_hover.svg +11 -0
- package/wsplayer-gov/WSPlayer/icon/screen_2.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/screen_25.svg +19 -0
- package/wsplayer-gov/WSPlayer/icon/screen_25_hover.svg +19 -0
- package/wsplayer-gov/WSPlayer/icon/screen_2_hover.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/screen_3.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/screen_3_hover.svg +13 -0
- package/wsplayer-gov/WSPlayer/icon/screen_4.svg +12 -0
- package/wsplayer-gov/WSPlayer/icon/screen_4_hover.svg +12 -0
- package/wsplayer-gov/WSPlayer/icon/screen_6.svg +16 -0
- package/wsplayer-gov/WSPlayer/icon/screen_6_hover.svg +16 -0
- package/wsplayer-gov/WSPlayer/icon/screen_8.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/screen_8_hover.svg +18 -0
- package/wsplayer-gov/WSPlayer/icon/screen_9.svg +17 -0
- package/wsplayer-gov/WSPlayer/icon/screen_9_hover.svg +17 -0
- package/wsplayer-gov/WSPlayer/icon/screen_custom_division.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/screen_custom_division_hover.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/screen_custom_division_merge.svg +3 -0
- package/wsplayer-gov/WSPlayer/icon/screen_custom_division_split.svg +6 -0
- package/wsplayer-gov/WSPlayer/icon/screen_more.svg +15 -0
- package/wsplayer-gov/WSPlayer/icon/snapshot.svg +38 -0
- package/wsplayer-gov/WSPlayer/icon/snapshot_hover.svg +38 -0
- package/wsplayer-gov/WSPlayer/icon/speed_left.svg +15 -0
- package/wsplayer-gov/WSPlayer/icon/speed_right.svg +15 -0
- package/wsplayer-gov/WSPlayer/icon/spread.png +0 -0
- package/wsplayer-gov/WSPlayer/icon/talk-off-hover.svg +11 -0
- package/wsplayer-gov/WSPlayer/icon/talk-off.svg +11 -0
- package/wsplayer-gov/WSPlayer/icon/talk-on.svg +9 -0
- package/wsplayer-gov/WSPlayer/icon/voice-have.svg +43 -0
- package/wsplayer-gov/WSPlayer/icon/voice-have_hover.svg +43 -0
- package/wsplayer-gov/WSPlayer/icon/voice-null.svg +38 -0
- package/wsplayer-gov/WSPlayer/icon/voice-null_hover.svg +38 -0
- package/wsplayer-gov/WSPlayer/icon/ws-ctrl-ellipsis-hover.svg +14 -0
- package/wsplayer-gov/WSPlayer/icon/ws-ctrl-ellipsis.svg +14 -0
- package/wsplayer-gov/WSPlayer/locale/lang/en_US.js +123 -0
- package/wsplayer-gov/WSPlayer/locale/lang/zh_CN.js +124 -0
- package/wsplayer-gov/WSPlayer/locale/localProvider.js +7 -0
- package/wsplayer-gov/WSPlayer/locale/locale.js +34 -0
- package/wsplayer-gov/WSPlayer/multiThread/libStreamClient.js +21 -0
- package/wsplayer-gov/WSPlayer/multiThread/libStreamClient.wasm +0 -0
- package/wsplayer-gov/WSPlayer/multiThread/libStreamClient.worker.js +1 -0
- package/wsplayer-gov/WSPlayer/multiThread/libplay.data +0 -0
- package/wsplayer-gov/WSPlayer/multiThread/libplay.js +1 -0
- package/wsplayer-gov/WSPlayer/multiThread/libplay.wasm +0 -0
- package/wsplayer-gov/WSPlayer/multiThread/libplay.worker.js +1 -0
- package/wsplayer-gov/WSPlayer/player.css +1098 -0
- package/wsplayer-gov/WSPlayer/singleThread/VideoDecodeWorker.js +1245 -0
- package/wsplayer-gov/WSPlayer/singleThread/libStreamClient.js +21 -0
- package/wsplayer-gov/WSPlayer/singleThread/libStreamClient.wasm +0 -0
- package/wsplayer-gov/WSPlayer/singleThread/libplay.data +0 -0
- package/wsplayer-gov/WSPlayer/singleThread/libplay.js +1 -0
- package/wsplayer-gov/WSPlayer/singleThread/libplay.wasm +0 -0
- package/wsplayer-gov/WSPlayer/window.division.css +80 -0
- package/wsplayer-gov/wsplayer.min.js +6 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1447 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DahuaPlayer: () => DahuaPlayer,
|
|
24
|
+
DahuaPlayerError: () => DahuaPlayerError,
|
|
25
|
+
ErrorCode: () => ErrorCode
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/errors.ts
|
|
30
|
+
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
31
|
+
ErrorCode2["CONTAINER_NOT_FOUND"] = "CONTAINER_NOT_FOUND";
|
|
32
|
+
ErrorCode2["INVALID_TOKEN"] = "INVALID_TOKEN";
|
|
33
|
+
ErrorCode2["SDK_LOAD_FAILED"] = "SDK_LOAD_FAILED";
|
|
34
|
+
ErrorCode2["SDK_LOAD_TIMEOUT"] = "SDK_LOAD_TIMEOUT";
|
|
35
|
+
ErrorCode2["SDK_INIT_FAILED"] = "SDK_INIT_FAILED";
|
|
36
|
+
ErrorCode2["PLAY_FAILED"] = "PLAY_FAILED";
|
|
37
|
+
ErrorCode2["NETWORK_DISCONNECTED"] = "NETWORK_DISCONNECTED";
|
|
38
|
+
ErrorCode2["DESTROYED"] = "DESTROYED";
|
|
39
|
+
return ErrorCode2;
|
|
40
|
+
})(ErrorCode || {});
|
|
41
|
+
var DahuaPlayerError = class extends Error {
|
|
42
|
+
constructor(params) {
|
|
43
|
+
super(params.message);
|
|
44
|
+
this.name = "DahuaPlayerError";
|
|
45
|
+
this.code = params.code;
|
|
46
|
+
this.userMessage = params.userMessage;
|
|
47
|
+
this.cause = params.cause;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function toDahuaError(e, fallback) {
|
|
51
|
+
if (e instanceof DahuaPlayerError) return e;
|
|
52
|
+
const cause = e;
|
|
53
|
+
return new DahuaPlayerError({ ...fallback, cause });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/sdk/SdkLoader.ts
|
|
57
|
+
var state = {
|
|
58
|
+
scripts: /* @__PURE__ */ new Map(),
|
|
59
|
+
styles: /* @__PURE__ */ new Map()
|
|
60
|
+
};
|
|
61
|
+
function loadStyleOnce(href) {
|
|
62
|
+
const url = href.trim();
|
|
63
|
+
if (!url) return Promise.resolve();
|
|
64
|
+
const existing = state.styles.get(url);
|
|
65
|
+
if (existing) return existing;
|
|
66
|
+
const p = new Promise((resolve, reject) => {
|
|
67
|
+
const link = document.createElement("link");
|
|
68
|
+
link.rel = "stylesheet";
|
|
69
|
+
link.href = url;
|
|
70
|
+
link.onload = () => resolve();
|
|
71
|
+
link.onerror = (e) => reject(e);
|
|
72
|
+
document.head.appendChild(link);
|
|
73
|
+
});
|
|
74
|
+
state.styles.set(url, p);
|
|
75
|
+
return p;
|
|
76
|
+
}
|
|
77
|
+
function loadScriptOnce(src, type) {
|
|
78
|
+
const url = src.trim();
|
|
79
|
+
if (!url) return Promise.resolve();
|
|
80
|
+
const existing = state.scripts.get(url);
|
|
81
|
+
if (existing) return existing;
|
|
82
|
+
const p = new Promise((resolve, reject) => {
|
|
83
|
+
const script = document.createElement("script");
|
|
84
|
+
script.type = type;
|
|
85
|
+
script.src = url;
|
|
86
|
+
script.onload = () => resolve();
|
|
87
|
+
script.onerror = (e) => reject(e);
|
|
88
|
+
document.head.appendChild(script);
|
|
89
|
+
});
|
|
90
|
+
state.scripts.set(url, p);
|
|
91
|
+
return p;
|
|
92
|
+
}
|
|
93
|
+
function waitFor(fn, timeoutMs) {
|
|
94
|
+
const start = Date.now();
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const tick = () => {
|
|
97
|
+
try {
|
|
98
|
+
const v = fn();
|
|
99
|
+
if (v) return resolve(v);
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
if (Date.now() - start >= timeoutMs) return reject(new Error("timeout"));
|
|
103
|
+
setTimeout(tick, 50);
|
|
104
|
+
};
|
|
105
|
+
tick();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async function ensureDahuaSdkLoaded(opts) {
|
|
109
|
+
var _a;
|
|
110
|
+
const sdkUrl = opts.sdkUrl;
|
|
111
|
+
const cssUrl = opts.cssUrl;
|
|
112
|
+
const timeoutMs = (_a = opts.timeoutMs) != null ? _a : 2e4;
|
|
113
|
+
if (cssUrl) {
|
|
114
|
+
try {
|
|
115
|
+
await loadStyleOnce(cssUrl);
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
await loadScriptOnce(sdkUrl, "module").catch(async () => {
|
|
120
|
+
await loadScriptOnce(sdkUrl, "text/javascript");
|
|
121
|
+
});
|
|
122
|
+
const PlayerManager = await waitFor(
|
|
123
|
+
() => window.PlayerManager,
|
|
124
|
+
timeoutMs
|
|
125
|
+
);
|
|
126
|
+
if (typeof PlayerManager !== "function") {
|
|
127
|
+
throw new Error("PlayerManager not available after SDK load");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/sdk/TokenVault.ts
|
|
132
|
+
var state2 = {
|
|
133
|
+
refCount: 0,
|
|
134
|
+
token: null
|
|
135
|
+
};
|
|
136
|
+
function syncToSessionStorage() {
|
|
137
|
+
try {
|
|
138
|
+
const ss = window.sessionStorage;
|
|
139
|
+
if (!ss) return;
|
|
140
|
+
if (state2.token) {
|
|
141
|
+
ss.setItem("psi_token", state2.token);
|
|
142
|
+
} else {
|
|
143
|
+
ss.removeItem("psi_token");
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function setToken(token) {
|
|
149
|
+
state2.token = token;
|
|
150
|
+
if (state2.refCount > 0) syncToSessionStorage();
|
|
151
|
+
}
|
|
152
|
+
function acquireTokenShim() {
|
|
153
|
+
state2.refCount++;
|
|
154
|
+
if (state2.refCount !== 1) return;
|
|
155
|
+
syncToSessionStorage();
|
|
156
|
+
}
|
|
157
|
+
function releaseTokenShim() {
|
|
158
|
+
var _a;
|
|
159
|
+
if (state2.refCount <= 0) return;
|
|
160
|
+
state2.refCount--;
|
|
161
|
+
if (state2.refCount !== 0) return;
|
|
162
|
+
try {
|
|
163
|
+
(_a = window.sessionStorage) == null ? void 0 : _a.removeItem("psi_token");
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/sdk/SelfTargetOriginShim.ts
|
|
169
|
+
var state3 = {
|
|
170
|
+
refCount: 0,
|
|
171
|
+
origin: null,
|
|
172
|
+
originalXhrOpen: null,
|
|
173
|
+
originalXhrSend: null,
|
|
174
|
+
originalXhrSetRequestHeader: null
|
|
175
|
+
};
|
|
176
|
+
function shouldAttachOrigin(url) {
|
|
177
|
+
if (typeof url !== "string") return false;
|
|
178
|
+
return url.includes("/videoService/") || url.includes("videoService/");
|
|
179
|
+
}
|
|
180
|
+
function normalizeHeaderName(name) {
|
|
181
|
+
return typeof name === "string" ? name.trim().toLowerCase() : "";
|
|
182
|
+
}
|
|
183
|
+
function setSelfTargetOrigin(origin) {
|
|
184
|
+
state3.origin = typeof origin === "string" ? origin.trim() || null : null;
|
|
185
|
+
}
|
|
186
|
+
function acquireSelfTargetOriginShim() {
|
|
187
|
+
state3.refCount++;
|
|
188
|
+
if (state3.refCount !== 1) return;
|
|
189
|
+
try {
|
|
190
|
+
const proto = XMLHttpRequest.prototype;
|
|
191
|
+
if (typeof proto.open !== "function" || typeof proto.send !== "function" || typeof proto.setRequestHeader !== "function") {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
state3.originalXhrOpen = proto.open;
|
|
195
|
+
state3.originalXhrSend = proto.send;
|
|
196
|
+
state3.originalXhrSetRequestHeader = proto.setRequestHeader;
|
|
197
|
+
proto.open = function(...args) {
|
|
198
|
+
try {
|
|
199
|
+
this.__dahua_request_url = args[1];
|
|
200
|
+
this.__dahua_has_self_target_origin = false;
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
return state3.originalXhrOpen.apply(this, args);
|
|
204
|
+
};
|
|
205
|
+
proto.setRequestHeader = function(name, value) {
|
|
206
|
+
try {
|
|
207
|
+
if (normalizeHeaderName(name) === "self-targetorigin") {
|
|
208
|
+
this.__dahua_has_self_target_origin = true;
|
|
209
|
+
}
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
return state3.originalXhrSetRequestHeader.call(this, name, value);
|
|
213
|
+
};
|
|
214
|
+
proto.send = function(...args) {
|
|
215
|
+
var _a, _b;
|
|
216
|
+
try {
|
|
217
|
+
const origin = state3.origin || ((_a = window.sessionStorage) == null ? void 0 : _a.getItem("wsplayer_origin")) || ((_b = window.localStorage) == null ? void 0 : _b.getItem("wsplayer_origin")) || null;
|
|
218
|
+
const url = this.__dahua_request_url;
|
|
219
|
+
const alreadySet = Boolean(this.__dahua_has_self_target_origin);
|
|
220
|
+
if (!alreadySet && origin && shouldAttachOrigin(url)) {
|
|
221
|
+
state3.originalXhrSetRequestHeader.call(this, "Self-TargetOrigin", origin);
|
|
222
|
+
}
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
return state3.originalXhrSend.apply(this, args);
|
|
226
|
+
};
|
|
227
|
+
} catch {
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function releaseSelfTargetOriginShim() {
|
|
231
|
+
if (state3.refCount <= 0) return;
|
|
232
|
+
state3.refCount--;
|
|
233
|
+
if (state3.refCount !== 0) return;
|
|
234
|
+
try {
|
|
235
|
+
const proto = XMLHttpRequest.prototype;
|
|
236
|
+
if (state3.originalXhrOpen) proto.open = state3.originalXhrOpen;
|
|
237
|
+
if (state3.originalXhrSend) proto.send = state3.originalXhrSend;
|
|
238
|
+
if (state3.originalXhrSetRequestHeader) proto.setRequestHeader = state3.originalXhrSetRequestHeader;
|
|
239
|
+
} catch {
|
|
240
|
+
}
|
|
241
|
+
state3.origin = null;
|
|
242
|
+
state3.originalXhrOpen = null;
|
|
243
|
+
state3.originalXhrSend = null;
|
|
244
|
+
state3.originalXhrSetRequestHeader = null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/sdk/PlayerAdapter.ts
|
|
248
|
+
var PlayerAdapter = class {
|
|
249
|
+
constructor(opts) {
|
|
250
|
+
this.playerManager = null;
|
|
251
|
+
this.destroyed = false;
|
|
252
|
+
this.readyResolved = false;
|
|
253
|
+
this.currentNum = 1;
|
|
254
|
+
this.currentMaxNum = 1;
|
|
255
|
+
this.opts = opts;
|
|
256
|
+
}
|
|
257
|
+
getRaw() {
|
|
258
|
+
return this.playerManager;
|
|
259
|
+
}
|
|
260
|
+
init() {
|
|
261
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
262
|
+
if (this.destroyed) {
|
|
263
|
+
throw new DahuaPlayerError({
|
|
264
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
265
|
+
message: "Player destroyed",
|
|
266
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
const PM = window.PlayerManager;
|
|
270
|
+
if (typeof PM !== "function") {
|
|
271
|
+
throw new DahuaPlayerError({
|
|
272
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
273
|
+
message: "PlayerManager is not available",
|
|
274
|
+
userMessage: "\u64AD\u653E\u5668\u5185\u6838\u672A\u52A0\u8F7D"
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const userReceive = this.opts.onMessage;
|
|
278
|
+
const showRecordProgressBar = typeof this.opts.showRecordProgressBar === "boolean" ? this.opts.showRecordProgressBar : this.opts.mode === "record";
|
|
279
|
+
const initialNum = this.normalizePositiveInt(
|
|
280
|
+
(_c = (_b = this.opts.num) != null ? _b : (_a = this.opts.playerOptions) == null ? void 0 : _a.num) != null ? _c : 1,
|
|
281
|
+
1
|
|
282
|
+
);
|
|
283
|
+
const initialMaxNum = this.normalizePositiveInt(
|
|
284
|
+
(_f = (_e = this.opts.maxNum) != null ? _e : (_d = this.opts.playerOptions) == null ? void 0 : _d.maxNum) != null ? _f : initialNum,
|
|
285
|
+
initialNum
|
|
286
|
+
);
|
|
287
|
+
const defaultOptions = {
|
|
288
|
+
type: this.opts.mode,
|
|
289
|
+
num: initialNum,
|
|
290
|
+
maxNum: initialMaxNum,
|
|
291
|
+
showControl: false,
|
|
292
|
+
showIcons: { hidden: true },
|
|
293
|
+
showRecordProgressBar,
|
|
294
|
+
useNginxProxy: (_g = this.opts.useNginxProxy) != null ? _g : false,
|
|
295
|
+
nginxProxyHost: (_h = this.opts.nginxProxyHost) != null ? _h : "",
|
|
296
|
+
useWSS: (_i = this.opts.useWSS) != null ? _i : false
|
|
297
|
+
};
|
|
298
|
+
const merged = {
|
|
299
|
+
...defaultOptions,
|
|
300
|
+
...(_j = this.opts.playerOptions) != null ? _j : {},
|
|
301
|
+
el: this.opts.containerId,
|
|
302
|
+
STATIC_PATH: this.opts.staticPath,
|
|
303
|
+
receiveMessageFromWSPlayer: (type, data) => {
|
|
304
|
+
if (this.destroyed) return;
|
|
305
|
+
try {
|
|
306
|
+
userReceive == null ? void 0 : userReceive(type, data);
|
|
307
|
+
} catch {
|
|
308
|
+
}
|
|
309
|
+
this.handleSdkMessage(type, data);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
this.playerManager = new PM(merged);
|
|
313
|
+
this.currentNum = this.normalizePositiveInt(merged.num, 1);
|
|
314
|
+
this.currentMaxNum = this.normalizePositiveInt(merged.maxNum, this.currentNum);
|
|
315
|
+
}
|
|
316
|
+
log(...args) {
|
|
317
|
+
if (!this.opts.debug) return;
|
|
318
|
+
try {
|
|
319
|
+
console.log("[dahua-player]", ...args);
|
|
320
|
+
} catch {
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
summarizeSdkMessage(type, data) {
|
|
324
|
+
if (type === "statusChanged") {
|
|
325
|
+
const status = data && typeof data === "object" ? data.status : void 0;
|
|
326
|
+
return { status };
|
|
327
|
+
}
|
|
328
|
+
if (type === "realError" || type === "recordError") {
|
|
329
|
+
const reason = data && typeof data === "object" ? data.reason : void 0;
|
|
330
|
+
return { reason };
|
|
331
|
+
}
|
|
332
|
+
if (type === "errorInfo") {
|
|
333
|
+
const status = data && typeof data === "object" ? data.status : void 0;
|
|
334
|
+
const code = data && typeof data === "object" ? data.code : void 0;
|
|
335
|
+
return { status, code };
|
|
336
|
+
}
|
|
337
|
+
return void 0;
|
|
338
|
+
}
|
|
339
|
+
handleSdkMessage(type, data) {
|
|
340
|
+
var _a, _b;
|
|
341
|
+
this.log("sdk", type, this.summarizeSdkMessage(type, data));
|
|
342
|
+
switch (type) {
|
|
343
|
+
case "initializationCompleted": {
|
|
344
|
+
if (!this.readyResolved) {
|
|
345
|
+
this.readyResolved = true;
|
|
346
|
+
this.opts.emit("ready");
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
case "realSuccess": {
|
|
351
|
+
this.opts.emit("play", { mode: "real" });
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
case "recordSuccess": {
|
|
355
|
+
this.opts.emit("play", { mode: "record" });
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
case "statusChanged": {
|
|
359
|
+
if (data && typeof data === "object" && (data.status === "pause" || data.status === "paused")) {
|
|
360
|
+
this.opts.emit("pause");
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
case "windowNumChanged": {
|
|
365
|
+
const n = typeof data === "number" ? data : data && typeof data === "object" ? (_b = (_a = data.num) != null ? _a : data.number) != null ? _b : data.windowNum : void 0;
|
|
366
|
+
const v = this.normalizePositiveInt(n, this.currentNum);
|
|
367
|
+
this.currentNum = v;
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
case "realError": {
|
|
371
|
+
this.opts.emit(
|
|
372
|
+
"error",
|
|
373
|
+
new DahuaPlayerError({
|
|
374
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
375
|
+
message: "Real play failed",
|
|
376
|
+
userMessage: "\u5B9E\u65F6\u9884\u89C8\u5931\u8D25",
|
|
377
|
+
cause: data
|
|
378
|
+
})
|
|
379
|
+
);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
case "recordError": {
|
|
383
|
+
this.opts.emit(
|
|
384
|
+
"error",
|
|
385
|
+
new DahuaPlayerError({
|
|
386
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
387
|
+
message: "Record play failed",
|
|
388
|
+
userMessage: "\u5F55\u50CF\u56DE\u653E\u5931\u8D25",
|
|
389
|
+
cause: data
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
default:
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
normalizeChannelList(opt) {
|
|
399
|
+
var _a;
|
|
400
|
+
const fromOpt = opt && typeof opt === "object" ? opt.channelList : void 0;
|
|
401
|
+
if (Array.isArray(fromOpt) && fromOpt.length > 0) return this.limitByCurrentNum(fromOpt);
|
|
402
|
+
const idsFromOpt = this.normalizeCameraIds(
|
|
403
|
+
opt && typeof opt === "object" ? (_a = opt.cameraIds) != null ? _a : opt.cameraId : void 0
|
|
404
|
+
);
|
|
405
|
+
if (idsFromOpt.length > 0) return this.limitByCurrentNum(idsFromOpt.map((id) => ({ channelCode: id })));
|
|
406
|
+
const initIds = this.normalizeCameraIds(this.opts.cameraIds);
|
|
407
|
+
if (initIds.length > 0) return this.limitByCurrentNum(initIds.map((id) => ({ channelCode: id })));
|
|
408
|
+
if (this.opts.cameraId) return [{ channelCode: this.opts.cameraId }];
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
normalizeCameraIds(input) {
|
|
412
|
+
const list = [];
|
|
413
|
+
if (typeof input === "string") {
|
|
414
|
+
const v = input.trim();
|
|
415
|
+
if (v) list.push(v);
|
|
416
|
+
} else if (Array.isArray(input)) {
|
|
417
|
+
for (const it of input) {
|
|
418
|
+
if (typeof it !== "string") continue;
|
|
419
|
+
const v = it.trim();
|
|
420
|
+
if (v) list.push(v);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const uniq = Array.from(new Set(list));
|
|
424
|
+
return uniq;
|
|
425
|
+
}
|
|
426
|
+
limitByCurrentNum(list) {
|
|
427
|
+
const cap = this.normalizePositiveInt(this.currentNum, 1);
|
|
428
|
+
if (list.length <= cap) return list;
|
|
429
|
+
const sliced = list.slice(0, cap);
|
|
430
|
+
this.log("channelList truncated by layout", { cap, original: list.length });
|
|
431
|
+
return sliced;
|
|
432
|
+
}
|
|
433
|
+
normalizePositiveInt(input, fallback) {
|
|
434
|
+
const n = typeof input === "number" ? input : typeof input === "string" ? Number(input) : NaN;
|
|
435
|
+
if (!Number.isFinite(n) || n <= 0) return fallback;
|
|
436
|
+
return Math.floor(n);
|
|
437
|
+
}
|
|
438
|
+
playRealVideo(opt) {
|
|
439
|
+
if (!this.playerManager || this.destroyed) {
|
|
440
|
+
throw new DahuaPlayerError({
|
|
441
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
442
|
+
message: "Player destroyed",
|
|
443
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const channelList = this.normalizeChannelList(opt);
|
|
447
|
+
if (!channelList) {
|
|
448
|
+
throw new DahuaPlayerError({
|
|
449
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
450
|
+
message: "channelList is required for real play",
|
|
451
|
+
userMessage: "\u7F3A\u5C11\u901A\u9053ID\uFF0C\u8BF7\u5728\u8C03\u7528\u65F6\u4F20\u5165 channelList \u6216\u521D\u59CB\u5316\u65F6\u4F20\u5165 cameraId"
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
if (typeof this.playerManager.playRealVideo !== "function") {
|
|
455
|
+
throw new DahuaPlayerError({
|
|
456
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
457
|
+
message: "playRealVideo is not available",
|
|
458
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u5B9E\u65F6\u9884\u89C8\u64AD\u653E"
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
this.log("playRealVideo");
|
|
462
|
+
this.playerManager.playRealVideo({ ...opt != null ? opt : {}, channelList });
|
|
463
|
+
}
|
|
464
|
+
playRecordVideo(opt) {
|
|
465
|
+
if (!this.playerManager || this.destroyed) {
|
|
466
|
+
throw new DahuaPlayerError({
|
|
467
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
468
|
+
message: "Player destroyed",
|
|
469
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
const channelList = this.normalizeChannelList(opt);
|
|
473
|
+
if (!channelList) {
|
|
474
|
+
throw new DahuaPlayerError({
|
|
475
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
476
|
+
message: "channelList is required for record play",
|
|
477
|
+
userMessage: "\u7F3A\u5C11\u901A\u9053ID\uFF0C\u8BF7\u5728\u8C03\u7528\u65F6\u4F20\u5165 channelList \u6216\u521D\u59CB\u5316\u65F6\u4F20\u5165 cameraId"
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
if (typeof this.playerManager.playRecordVideo !== "function") {
|
|
481
|
+
throw new DahuaPlayerError({
|
|
482
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
483
|
+
message: "playRecordVideo is not available",
|
|
484
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u5F55\u50CF\u56DE\u653E\u64AD\u653E"
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
this.log("playRecordVideo");
|
|
488
|
+
this.playerManager.playRecordVideo({ ...opt != null ? opt : {}, channelList });
|
|
489
|
+
}
|
|
490
|
+
setPlayerNum(num) {
|
|
491
|
+
var _a;
|
|
492
|
+
if (!this.playerManager || this.destroyed) {
|
|
493
|
+
throw new DahuaPlayerError({
|
|
494
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
495
|
+
message: "Player destroyed",
|
|
496
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
const v = this.normalizePositiveInt(num, this.currentNum);
|
|
500
|
+
const fn = (_a = this.playerManager) == null ? void 0 : _a.setPlayerNum;
|
|
501
|
+
if (typeof fn !== "function") {
|
|
502
|
+
throw new DahuaPlayerError({
|
|
503
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
504
|
+
message: "setPlayerNum is not available",
|
|
505
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u5207\u6362\u5E03\u5C40\u8DEF\u6570"
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
this.log("setPlayerNum", v);
|
|
509
|
+
fn.call(this.playerManager, v);
|
|
510
|
+
this.currentNum = v;
|
|
511
|
+
}
|
|
512
|
+
jumpPlayByDateTime(datetime, index) {
|
|
513
|
+
if (this.opts.mode !== "record") {
|
|
514
|
+
throw new DahuaPlayerError({
|
|
515
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
516
|
+
message: "jumpPlayByDateTime only supports record mode",
|
|
517
|
+
userMessage: "\u5B9E\u65F6\u9884\u89C8\u4E0D\u652F\u6301\u8DF3\u8F6C\u64AD\u653E"
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (!this.playerManager || this.destroyed) {
|
|
521
|
+
throw new DahuaPlayerError({
|
|
522
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
523
|
+
message: "Player destroyed",
|
|
524
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
const dt = this.formatDateTime(datetime);
|
|
528
|
+
const fn = this.pickMethod(["jumpPlayByDateTime", "jumpPlayByDatetime"]);
|
|
529
|
+
if (!fn) {
|
|
530
|
+
throw new DahuaPlayerError({
|
|
531
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
532
|
+
message: "jumpPlayByDateTime is not available",
|
|
533
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u5F55\u50CF\u8DF3\u8F6C\u64AD\u653E"
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
const idx = typeof index === "number" ? Math.floor(index) : void 0;
|
|
537
|
+
this.log("jumpPlayByDateTime", { dt, index: idx });
|
|
538
|
+
fn(dt, idx);
|
|
539
|
+
}
|
|
540
|
+
playSpeed(speed, index) {
|
|
541
|
+
var _a;
|
|
542
|
+
if (this.opts.mode !== "record") {
|
|
543
|
+
throw new DahuaPlayerError({
|
|
544
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
545
|
+
message: "playSpeed only supports record mode",
|
|
546
|
+
userMessage: "\u5B9E\u65F6\u9884\u89C8\u4E0D\u652F\u6301\u500D\u901F\u64AD\u653E"
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (!this.playerManager || this.destroyed) {
|
|
550
|
+
throw new DahuaPlayerError({
|
|
551
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
552
|
+
message: "Player destroyed",
|
|
553
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
const allowed = /* @__PURE__ */ new Set([0.125, 0.25, 0.5, 1, 1.25, 1.5, 2, 4, 8]);
|
|
557
|
+
if (!allowed.has(speed)) {
|
|
558
|
+
throw new DahuaPlayerError({
|
|
559
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
560
|
+
message: "invalid speed",
|
|
561
|
+
userMessage: "\u500D\u901F\u53C2\u6570\u4E0D\u5408\u6CD5",
|
|
562
|
+
cause: { speed }
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
const idx = this.normalizePositiveInt(index, 0);
|
|
566
|
+
const fn = (_a = this.playerManager) == null ? void 0 : _a.playSpeed;
|
|
567
|
+
if (typeof fn !== "function") {
|
|
568
|
+
throw new DahuaPlayerError({
|
|
569
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
570
|
+
message: "playSpeed is not available",
|
|
571
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u500D\u901F\u64AD\u653E"
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
this.log("playSpeed", { speed, index: idx });
|
|
575
|
+
fn.call(this.playerManager, speed, idx);
|
|
576
|
+
}
|
|
577
|
+
setFullScreen() {
|
|
578
|
+
var _a;
|
|
579
|
+
if (!this.playerManager || this.destroyed) {
|
|
580
|
+
throw new DahuaPlayerError({
|
|
581
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
582
|
+
message: "Player destroyed",
|
|
583
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
const fn = (_a = this.playerManager) == null ? void 0 : _a.setFullScreen;
|
|
587
|
+
if (typeof fn !== "function") {
|
|
588
|
+
throw new DahuaPlayerError({
|
|
589
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
590
|
+
message: "setFullScreen is not available",
|
|
591
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u5168\u5C4F"
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
this.log("setFullScreen");
|
|
595
|
+
fn.call(this.playerManager);
|
|
596
|
+
}
|
|
597
|
+
setExitFullScreen() {
|
|
598
|
+
var _a;
|
|
599
|
+
if (!this.playerManager || this.destroyed) {
|
|
600
|
+
throw new DahuaPlayerError({
|
|
601
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
602
|
+
message: "Player destroyed",
|
|
603
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
const fn = (_a = this.playerManager) == null ? void 0 : _a.setExitFullScreen;
|
|
607
|
+
if (typeof fn !== "function") {
|
|
608
|
+
throw new DahuaPlayerError({
|
|
609
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
610
|
+
message: "setExitFullScreen is not available",
|
|
611
|
+
userMessage: "\u5F53\u524D\u5185\u6838\u4E0D\u652F\u6301\u9000\u51FA\u5168\u5C4F"
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
this.log("setExitFullScreen");
|
|
615
|
+
fn.call(this.playerManager);
|
|
616
|
+
}
|
|
617
|
+
callRaw(method, ...args) {
|
|
618
|
+
if (!this.playerManager || this.destroyed) {
|
|
619
|
+
throw new DahuaPlayerError({
|
|
620
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
621
|
+
message: "Player destroyed",
|
|
622
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
const name = typeof method === "string" ? method.trim() : "";
|
|
626
|
+
if (!name) {
|
|
627
|
+
throw new DahuaPlayerError({
|
|
628
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
629
|
+
message: "method is required",
|
|
630
|
+
userMessage: "\u7F3A\u5C11 method \u53C2\u6570"
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
const fn = this.playerManager[name];
|
|
634
|
+
if (typeof fn !== "function") {
|
|
635
|
+
throw new DahuaPlayerError({
|
|
636
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
637
|
+
message: `method not found: ${name}`,
|
|
638
|
+
userMessage: `\u5E95\u5C42\u65B9\u6CD5\u4E0D\u5B58\u5728\uFF1A${name}`
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
this.log("callRaw", name);
|
|
642
|
+
return fn.apply(this.playerManager, args);
|
|
643
|
+
}
|
|
644
|
+
pickMethod(names) {
|
|
645
|
+
var _a;
|
|
646
|
+
for (const n of names) {
|
|
647
|
+
const fn = (_a = this.playerManager) == null ? void 0 : _a[n];
|
|
648
|
+
if (typeof fn === "function") return fn.bind(this.playerManager);
|
|
649
|
+
}
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
formatDateTime(input) {
|
|
653
|
+
if (typeof input === "string") return input.trim();
|
|
654
|
+
const d = typeof input === "number" ? new Date(input > 1e12 ? input : input * 1e3) : input instanceof Date ? input : /* @__PURE__ */ new Date(NaN);
|
|
655
|
+
if (!Number.isFinite(d.getTime())) {
|
|
656
|
+
throw new DahuaPlayerError({
|
|
657
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
658
|
+
message: "invalid datetime",
|
|
659
|
+
userMessage: "\u8DF3\u8F6C\u65F6\u95F4\u683C\u5F0F\u4E0D\u5408\u6CD5"
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
663
|
+
const y = d.getFullYear();
|
|
664
|
+
const m = pad2(d.getMonth() + 1);
|
|
665
|
+
const day = pad2(d.getDate());
|
|
666
|
+
const hh = pad2(d.getHours());
|
|
667
|
+
const mm = pad2(d.getMinutes());
|
|
668
|
+
const ss = pad2(d.getSeconds());
|
|
669
|
+
return `${y}-${m}-${day} ${hh}:${mm}:${ss}`;
|
|
670
|
+
}
|
|
671
|
+
pause() {
|
|
672
|
+
if (!this.playerManager || this.destroyed) return;
|
|
673
|
+
try {
|
|
674
|
+
this.log("pause");
|
|
675
|
+
if (typeof this.playerManager.pause === "function") {
|
|
676
|
+
this.playerManager.pause(0);
|
|
677
|
+
} else if (typeof this.playerManager.close === "function") {
|
|
678
|
+
this.playerManager.close(0);
|
|
679
|
+
}
|
|
680
|
+
this.opts.emit("pause");
|
|
681
|
+
} catch {
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
pauseWindow(windowIndex) {
|
|
685
|
+
if (!this.playerManager || this.destroyed) return;
|
|
686
|
+
try {
|
|
687
|
+
const idx = typeof windowIndex === "number" ? windowIndex : void 0;
|
|
688
|
+
this.log("pauseWindow", idx);
|
|
689
|
+
if (typeof this.playerManager.pause === "function") {
|
|
690
|
+
this.playerManager.pause(idx);
|
|
691
|
+
} else if (typeof this.playerManager.close === "function") {
|
|
692
|
+
this.playerManager.close(idx);
|
|
693
|
+
}
|
|
694
|
+
this.opts.emit("pause");
|
|
695
|
+
} catch {
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
playWindow(windowIndex) {
|
|
699
|
+
if (!this.playerManager || this.destroyed) return;
|
|
700
|
+
try {
|
|
701
|
+
const idx = typeof windowIndex === "number" ? windowIndex : void 0;
|
|
702
|
+
this.log("playWindow", idx);
|
|
703
|
+
if (typeof this.playerManager.play === "function") {
|
|
704
|
+
this.playerManager.play(idx);
|
|
705
|
+
}
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
closeWindow(windowIndex) {
|
|
710
|
+
if (!this.playerManager || this.destroyed) return;
|
|
711
|
+
try {
|
|
712
|
+
const idx = typeof windowIndex === "number" ? windowIndex : void 0;
|
|
713
|
+
this.log("closeWindow", idx);
|
|
714
|
+
if (typeof this.playerManager.close === "function") {
|
|
715
|
+
this.playerManager.close(idx);
|
|
716
|
+
}
|
|
717
|
+
} catch {
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
destroy() {
|
|
721
|
+
if (this.destroyed) return;
|
|
722
|
+
this.destroyed = true;
|
|
723
|
+
this.log("destroy");
|
|
724
|
+
if (this.playerManager) {
|
|
725
|
+
try {
|
|
726
|
+
this.playerManager.destroy();
|
|
727
|
+
} catch {
|
|
728
|
+
}
|
|
729
|
+
this.playerManager = null;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
// src/DahuaPlayer.ts
|
|
735
|
+
function normalizeStaticPath(path) {
|
|
736
|
+
const raw = (path || "").trim();
|
|
737
|
+
if (!raw) return "/wsplayer-gov";
|
|
738
|
+
const v = raw.replace(/\/+$/, "");
|
|
739
|
+
return v.startsWith("/") ? v : `/${v}`;
|
|
740
|
+
}
|
|
741
|
+
function buildTargetOriginFromAuth(auth) {
|
|
742
|
+
if (!auth) return "";
|
|
743
|
+
const ip = typeof auth.ip === "string" ? auth.ip.trim() : "";
|
|
744
|
+
const port = typeof auth.port === "number" ? auth.port : typeof auth.port === "string" ? Number(auth.port) : NaN;
|
|
745
|
+
if (!ip || !Number.isFinite(port) || port <= 0) return "";
|
|
746
|
+
const protocol = auth.protocol === "http" ? "http" : "https";
|
|
747
|
+
return `${protocol}://${ip}:${port}`;
|
|
748
|
+
}
|
|
749
|
+
function resolveContainer(container) {
|
|
750
|
+
if (typeof container === "string") {
|
|
751
|
+
const el = document.getElementById(container);
|
|
752
|
+
if (!el) {
|
|
753
|
+
throw new DahuaPlayerError({
|
|
754
|
+
code: "CONTAINER_NOT_FOUND" /* CONTAINER_NOT_FOUND */,
|
|
755
|
+
message: `container not found: ${container}`,
|
|
756
|
+
userMessage: "\u672A\u627E\u5230\u64AD\u653E\u5668\u6302\u8F7D\u8282\u70B9"
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
return el;
|
|
760
|
+
}
|
|
761
|
+
if (container && typeof container === "object") return container;
|
|
762
|
+
throw new DahuaPlayerError({
|
|
763
|
+
code: "CONTAINER_NOT_FOUND" /* CONTAINER_NOT_FOUND */,
|
|
764
|
+
message: "container is invalid",
|
|
765
|
+
userMessage: "\u64AD\u653E\u5668\u6302\u8F7D\u8282\u70B9\u65E0\u6548"
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
function createListeners() {
|
|
769
|
+
return /* @__PURE__ */ new Map();
|
|
770
|
+
}
|
|
771
|
+
function emit(listeners, event, payload) {
|
|
772
|
+
const set = listeners.get(event);
|
|
773
|
+
if (!set || set.size === 0) return;
|
|
774
|
+
for (const cb of set) {
|
|
775
|
+
try {
|
|
776
|
+
cb(payload);
|
|
777
|
+
} catch {
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
var DahuaPlayer = class {
|
|
782
|
+
/**
|
|
783
|
+
* 初始化播放器并返回实例。
|
|
784
|
+
*
|
|
785
|
+
* 生命周期:
|
|
786
|
+
*
|
|
787
|
+
* - 立即创建 DOM 结构并开始异步加载 SDK
|
|
788
|
+
* - `instance.ready` 会在 SDK 触发 `initializationCompleted` 后 resolve
|
|
789
|
+
* - `destroy()` 会销毁 SDK 实例、移除 DOM,并释放 token shim
|
|
790
|
+
*
|
|
791
|
+
* @throws DahuaPlayerError 当 container/token 不合法时抛出
|
|
792
|
+
*/
|
|
793
|
+
static init(options) {
|
|
794
|
+
var _a, _b, _c, _d;
|
|
795
|
+
const opts = options || {};
|
|
796
|
+
const container = resolveContainer(opts.container);
|
|
797
|
+
const mode = (_a = opts.mode) != null ? _a : "real";
|
|
798
|
+
const token = typeof ((_b = opts.auth) == null ? void 0 : _b.token) === "string" ? opts.auth.token.trim() : "";
|
|
799
|
+
if (!token) {
|
|
800
|
+
throw new DahuaPlayerError({
|
|
801
|
+
code: "INVALID_TOKEN" /* INVALID_TOKEN */,
|
|
802
|
+
message: "token is required",
|
|
803
|
+
userMessage: "\u7F3A\u5C11 token\uFF0C\u8BF7\u5148\u5B8C\u6210\u9274\u6743\u767B\u5F55"
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
const cameraId = typeof opts.cameraId === "string" ? opts.cameraId.trim() : "";
|
|
807
|
+
const cameraIds = Array.isArray(opts.cameraIds) ? opts.cameraIds.map((v) => v.trim()).filter(Boolean) : [];
|
|
808
|
+
const targetOrigin = buildTargetOriginFromAuth(opts.auth);
|
|
809
|
+
const id = `dahua-player-${Math.random().toString(36).slice(2, 10)}`;
|
|
810
|
+
const wrapper = document.createElement("div");
|
|
811
|
+
wrapper.id = id;
|
|
812
|
+
wrapper.style.position = "relative";
|
|
813
|
+
wrapper.style.width = opts.width === "auto" || opts.width == null ? "100%" : `${opts.width}px`;
|
|
814
|
+
wrapper.style.height = opts.height === "auto" || opts.height == null ? "100%" : `${opts.height}px`;
|
|
815
|
+
container.appendChild(wrapper);
|
|
816
|
+
const innerId = `${id}-inner`;
|
|
817
|
+
const inner = document.createElement("div");
|
|
818
|
+
inner.id = innerId;
|
|
819
|
+
inner.style.width = "100%";
|
|
820
|
+
inner.style.height = "100%";
|
|
821
|
+
wrapper.appendChild(inner);
|
|
822
|
+
const loading = document.createElement("div");
|
|
823
|
+
loading.style.position = "absolute";
|
|
824
|
+
loading.style.left = "0";
|
|
825
|
+
loading.style.top = "0";
|
|
826
|
+
loading.style.right = "0";
|
|
827
|
+
loading.style.bottom = "0";
|
|
828
|
+
loading.style.display = "flex";
|
|
829
|
+
loading.style.alignItems = "center";
|
|
830
|
+
loading.style.justifyContent = "center";
|
|
831
|
+
loading.style.background = "rgba(0,0,0,0.35)";
|
|
832
|
+
loading.style.color = "#fff";
|
|
833
|
+
loading.style.fontSize = "12px";
|
|
834
|
+
loading.style.pointerEvents = "none";
|
|
835
|
+
loading.style.zIndex = "10";
|
|
836
|
+
loading.style.visibility = "hidden";
|
|
837
|
+
const loadingText = document.createElement("div");
|
|
838
|
+
loadingText.textContent = "";
|
|
839
|
+
loading.appendChild(loadingText);
|
|
840
|
+
wrapper.appendChild(loading);
|
|
841
|
+
const setLoading = (visible, text) => {
|
|
842
|
+
loadingText.textContent = text || "";
|
|
843
|
+
loading.style.visibility = visible ? "visible" : "hidden";
|
|
844
|
+
};
|
|
845
|
+
let transientOverlayTimer = null;
|
|
846
|
+
let stickyOverlayVisible = false;
|
|
847
|
+
const showLoading = (text) => {
|
|
848
|
+
if (transientOverlayTimer) {
|
|
849
|
+
clearTimeout(transientOverlayTimer);
|
|
850
|
+
transientOverlayTimer = null;
|
|
851
|
+
}
|
|
852
|
+
stickyOverlayVisible = false;
|
|
853
|
+
setLoading(true, text);
|
|
854
|
+
};
|
|
855
|
+
const showTransientError = (text) => {
|
|
856
|
+
if (transientOverlayTimer) {
|
|
857
|
+
clearTimeout(transientOverlayTimer);
|
|
858
|
+
transientOverlayTimer = null;
|
|
859
|
+
}
|
|
860
|
+
stickyOverlayVisible = false;
|
|
861
|
+
setLoading(true, text);
|
|
862
|
+
transientOverlayTimer = setTimeout(() => {
|
|
863
|
+
transientOverlayTimer = null;
|
|
864
|
+
setLoading(false);
|
|
865
|
+
}, 3e3);
|
|
866
|
+
};
|
|
867
|
+
const showStickyError = (text) => {
|
|
868
|
+
if (transientOverlayTimer) {
|
|
869
|
+
clearTimeout(transientOverlayTimer);
|
|
870
|
+
transientOverlayTimer = null;
|
|
871
|
+
}
|
|
872
|
+
stickyOverlayVisible = true;
|
|
873
|
+
setLoading(true, text);
|
|
874
|
+
};
|
|
875
|
+
const formatUserMessage = (payload, fallback) => {
|
|
876
|
+
var _a2;
|
|
877
|
+
if (payload instanceof DahuaPlayerError) {
|
|
878
|
+
const base = payload.userMessage || fallback;
|
|
879
|
+
const cause = payload.cause;
|
|
880
|
+
const status = cause && typeof cause === "object" ? (_a2 = cause.status) != null ? _a2 : cause.code : void 0;
|
|
881
|
+
if (typeof status === "number" || typeof status === "string") {
|
|
882
|
+
return `${base}\uFF08${status}\uFF09`;
|
|
883
|
+
}
|
|
884
|
+
return base;
|
|
885
|
+
}
|
|
886
|
+
return typeof payload === "string" ? payload : fallback;
|
|
887
|
+
};
|
|
888
|
+
const listeners = createListeners();
|
|
889
|
+
const staticPath = normalizeStaticPath((_c = opts.staticPath) != null ? _c : "/wsplayer-gov");
|
|
890
|
+
const sdkUrl = (opts.sdkUrl || `${staticPath}/wsplayer.min.js`).trim();
|
|
891
|
+
const cssUrl = `${staticPath}/WSPlayer/player.css`;
|
|
892
|
+
const autoPlay = opts.autoPlay === true;
|
|
893
|
+
const streamType = (_d = opts.streamType) != null ? _d : 2;
|
|
894
|
+
const searchOnline = Boolean(opts.searchOnline);
|
|
895
|
+
const num = Number.isFinite(opts.num) ? Math.floor(Number(opts.num)) : void 0;
|
|
896
|
+
const maxNum = Number.isFinite(opts.maxNum) ? Math.floor(Number(opts.maxNum)) : void 0;
|
|
897
|
+
const showRecordProgressBar = typeof opts.showRecordProgressBar === "boolean" ? opts.showRecordProgressBar : void 0;
|
|
898
|
+
const dblClickFullscreen = opts.dblClickFullscreen !== false;
|
|
899
|
+
let destroyed = false;
|
|
900
|
+
let adapter = null;
|
|
901
|
+
let readyResolve = () => {
|
|
902
|
+
};
|
|
903
|
+
let readyReject = () => {
|
|
904
|
+
};
|
|
905
|
+
const safeOnError = (e) => {
|
|
906
|
+
var _a2;
|
|
907
|
+
try {
|
|
908
|
+
(_a2 = opts.onError) == null ? void 0 : _a2.call(opts, e);
|
|
909
|
+
} catch {
|
|
910
|
+
}
|
|
911
|
+
emit(listeners, "error", e);
|
|
912
|
+
};
|
|
913
|
+
const tryAutoPlay = () => {
|
|
914
|
+
if (!autoPlay) return;
|
|
915
|
+
if (mode === "real") {
|
|
916
|
+
if (!cameraId && cameraIds.length === 0) return;
|
|
917
|
+
try {
|
|
918
|
+
showLoading("\u52A0\u8F7D\u89C6\u9891\u4E2D\u2026");
|
|
919
|
+
adapter == null ? void 0 : adapter.playRealVideo({});
|
|
920
|
+
} catch (e) {
|
|
921
|
+
safeOnError(e);
|
|
922
|
+
}
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
if (mode === "record") {
|
|
926
|
+
if (!Number.isFinite(opts.recordStartTime)) return;
|
|
927
|
+
if (!Number.isFinite(opts.recordEndTime)) return;
|
|
928
|
+
if (!cameraId && cameraIds.length === 0) return;
|
|
929
|
+
const startTime = Math.floor(Number(opts.recordStartTime));
|
|
930
|
+
const endTime = Math.floor(Number(opts.recordEndTime));
|
|
931
|
+
const recordSource = Number.isFinite(opts.recordSource) ? Math.floor(Number(opts.recordSource)) : void 0;
|
|
932
|
+
try {
|
|
933
|
+
showLoading("\u52A0\u8F7D\u5F55\u50CF\u4E2D\u2026");
|
|
934
|
+
adapter == null ? void 0 : adapter.playRecordVideo(recordSource == null ? { startTime, endTime } : { startTime, endTime, recordSource });
|
|
935
|
+
} catch (e) {
|
|
936
|
+
safeOnError(e);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
const ready = new Promise((resolve, reject) => {
|
|
941
|
+
readyResolve = resolve;
|
|
942
|
+
readyReject = reject;
|
|
943
|
+
});
|
|
944
|
+
const readyTimer = setTimeout(() => {
|
|
945
|
+
const err = new DahuaPlayerError({
|
|
946
|
+
code: "SDK_LOAD_TIMEOUT" /* SDK_LOAD_TIMEOUT */,
|
|
947
|
+
message: "SDK ready timeout",
|
|
948
|
+
userMessage: "\u64AD\u653E\u5668\u521D\u59CB\u5316\u8D85\u65F6"
|
|
949
|
+
});
|
|
950
|
+
showStickyError(`\u521D\u59CB\u5316\u5931\u8D25\uFF1A${err.userMessage}`);
|
|
951
|
+
safeOnError(err);
|
|
952
|
+
readyReject(err);
|
|
953
|
+
}, 2e4);
|
|
954
|
+
showLoading("\u521D\u59CB\u5316\u4E2D\u2026");
|
|
955
|
+
void (async () => {
|
|
956
|
+
var _a2;
|
|
957
|
+
try {
|
|
958
|
+
setToken(token);
|
|
959
|
+
acquireTokenShim();
|
|
960
|
+
if (targetOrigin) {
|
|
961
|
+
try {
|
|
962
|
+
(_a2 = window.sessionStorage) == null ? void 0 : _a2.setItem("wsplayer_origin", targetOrigin);
|
|
963
|
+
} catch {
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
setSelfTargetOrigin(targetOrigin || null);
|
|
967
|
+
acquireSelfTargetOriginShim();
|
|
968
|
+
await ensureDahuaSdkLoaded({ sdkUrl, cssUrl, timeoutMs: 2e4 });
|
|
969
|
+
adapter = new PlayerAdapter({
|
|
970
|
+
containerId: innerId,
|
|
971
|
+
staticPath,
|
|
972
|
+
mode,
|
|
973
|
+
cameraId,
|
|
974
|
+
cameraIds,
|
|
975
|
+
streamType,
|
|
976
|
+
searchOnline,
|
|
977
|
+
useNginxProxy: opts.useNginxProxy,
|
|
978
|
+
nginxProxyHost: opts.nginxProxyHost,
|
|
979
|
+
useWSS: opts.useWSS,
|
|
980
|
+
num,
|
|
981
|
+
maxNum,
|
|
982
|
+
showRecordProgressBar,
|
|
983
|
+
playerOptions: opts.playerOptions,
|
|
984
|
+
debug: opts.debug,
|
|
985
|
+
onMessage: (type, data) => {
|
|
986
|
+
var _a3;
|
|
987
|
+
try {
|
|
988
|
+
(_a3 = opts.onSdkMessage) == null ? void 0 : _a3.call(opts, type, data);
|
|
989
|
+
} catch {
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
emit: (event, payload) => {
|
|
993
|
+
var _a3, _b2, _c2;
|
|
994
|
+
if (event === "ready") {
|
|
995
|
+
clearTimeout(readyTimer);
|
|
996
|
+
readyResolve();
|
|
997
|
+
setLoading(false);
|
|
998
|
+
stickyOverlayVisible = false;
|
|
999
|
+
try {
|
|
1000
|
+
(_a3 = opts.onReady) == null ? void 0 : _a3.call(opts);
|
|
1001
|
+
} catch {
|
|
1002
|
+
}
|
|
1003
|
+
emit(listeners, "ready");
|
|
1004
|
+
tryAutoPlay();
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
if (event === "play") {
|
|
1008
|
+
setLoading(false);
|
|
1009
|
+
try {
|
|
1010
|
+
(_b2 = opts.onPlay) == null ? void 0 : _b2.call(opts, payload);
|
|
1011
|
+
} catch {
|
|
1012
|
+
}
|
|
1013
|
+
emit(listeners, "play", payload);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (event === "pause") {
|
|
1017
|
+
setLoading(false);
|
|
1018
|
+
try {
|
|
1019
|
+
(_c2 = opts.onPause) == null ? void 0 : _c2.call(opts);
|
|
1020
|
+
} catch {
|
|
1021
|
+
}
|
|
1022
|
+
emit(listeners, "pause");
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (event === "error") {
|
|
1026
|
+
const msg = formatUserMessage(payload, "\u64AD\u653E\u5931\u8D25");
|
|
1027
|
+
if (payload instanceof DahuaPlayerError) {
|
|
1028
|
+
const initCodes = /* @__PURE__ */ new Set([
|
|
1029
|
+
"SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1030
|
+
"SDK_LOAD_FAILED" /* SDK_LOAD_FAILED */,
|
|
1031
|
+
"SDK_LOAD_TIMEOUT" /* SDK_LOAD_TIMEOUT */
|
|
1032
|
+
]);
|
|
1033
|
+
if (initCodes.has(payload.code)) {
|
|
1034
|
+
showStickyError(`\u521D\u59CB\u5316\u5931\u8D25\uFF1A${msg}`);
|
|
1035
|
+
safeOnError(payload);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (stickyOverlayVisible) return;
|
|
1040
|
+
showTransientError(msg);
|
|
1041
|
+
safeOnError(payload);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
adapter.init();
|
|
1046
|
+
} catch (e) {
|
|
1047
|
+
clearTimeout(readyTimer);
|
|
1048
|
+
const err = toDahuaError(e, {
|
|
1049
|
+
code: "SDK_LOAD_FAILED" /* SDK_LOAD_FAILED */,
|
|
1050
|
+
message: "SDK load/init failed",
|
|
1051
|
+
userMessage: "\u64AD\u653E\u5668\u521D\u59CB\u5316\u5931\u8D25"
|
|
1052
|
+
});
|
|
1053
|
+
showStickyError(`\u521D\u59CB\u5316\u5931\u8D25\uFF1A${err.userMessage}`);
|
|
1054
|
+
safeOnError(err);
|
|
1055
|
+
readyReject(err);
|
|
1056
|
+
}
|
|
1057
|
+
})();
|
|
1058
|
+
const instance = {
|
|
1059
|
+
id,
|
|
1060
|
+
ready,
|
|
1061
|
+
/**
|
|
1062
|
+
* 暂停播放。
|
|
1063
|
+
*
|
|
1064
|
+
* 注意:部分 SDK 版本 pause/close 的行为差异由内部适配处理。
|
|
1065
|
+
*/
|
|
1066
|
+
pause: () => {
|
|
1067
|
+
if (!adapter) return;
|
|
1068
|
+
adapter.pause();
|
|
1069
|
+
},
|
|
1070
|
+
/**
|
|
1071
|
+
* 销毁播放器实例并释放资源。
|
|
1072
|
+
*
|
|
1073
|
+
* - 移除创建的 DOM 节点
|
|
1074
|
+
* - 调用 SDK destroy(若存在)
|
|
1075
|
+
* - 释放 token shim,清理内存 token
|
|
1076
|
+
* - 触发 destroy 事件
|
|
1077
|
+
*/
|
|
1078
|
+
destroy: () => {
|
|
1079
|
+
var _a2;
|
|
1080
|
+
if (destroyed) return;
|
|
1081
|
+
destroyed = true;
|
|
1082
|
+
clearTimeout(readyTimer);
|
|
1083
|
+
if (transientOverlayTimer) {
|
|
1084
|
+
clearTimeout(transientOverlayTimer);
|
|
1085
|
+
transientOverlayTimer = null;
|
|
1086
|
+
}
|
|
1087
|
+
setLoading(false);
|
|
1088
|
+
try {
|
|
1089
|
+
adapter == null ? void 0 : adapter.destroy();
|
|
1090
|
+
} catch {
|
|
1091
|
+
}
|
|
1092
|
+
adapter = null;
|
|
1093
|
+
try {
|
|
1094
|
+
wrapper.remove();
|
|
1095
|
+
} catch {
|
|
1096
|
+
try {
|
|
1097
|
+
container.innerHTML = "";
|
|
1098
|
+
} catch {
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
try {
|
|
1102
|
+
releaseTokenShim();
|
|
1103
|
+
} catch {
|
|
1104
|
+
}
|
|
1105
|
+
try {
|
|
1106
|
+
releaseSelfTargetOriginShim();
|
|
1107
|
+
} catch {
|
|
1108
|
+
}
|
|
1109
|
+
try {
|
|
1110
|
+
setToken(null);
|
|
1111
|
+
} catch {
|
|
1112
|
+
}
|
|
1113
|
+
try {
|
|
1114
|
+
(_a2 = opts.onDestroy) == null ? void 0 : _a2.call(opts);
|
|
1115
|
+
} catch {
|
|
1116
|
+
}
|
|
1117
|
+
emit(listeners, "destroy");
|
|
1118
|
+
listeners.clear();
|
|
1119
|
+
},
|
|
1120
|
+
sdk: {
|
|
1121
|
+
getRaw: () => adapter == null ? void 0 : adapter.getRaw(),
|
|
1122
|
+
callRaw: (method, ...args) => {
|
|
1123
|
+
if (destroyed) {
|
|
1124
|
+
const err = new DahuaPlayerError({
|
|
1125
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1126
|
+
message: "destroyed",
|
|
1127
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1128
|
+
});
|
|
1129
|
+
safeOnError(err);
|
|
1130
|
+
throw err;
|
|
1131
|
+
}
|
|
1132
|
+
if (!adapter) {
|
|
1133
|
+
const err = new DahuaPlayerError({
|
|
1134
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1135
|
+
message: "player not ready",
|
|
1136
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1137
|
+
});
|
|
1138
|
+
safeOnError(err);
|
|
1139
|
+
throw err;
|
|
1140
|
+
}
|
|
1141
|
+
try {
|
|
1142
|
+
return adapter.callRaw(method, ...args);
|
|
1143
|
+
} catch (e) {
|
|
1144
|
+
const err = toDahuaError(e, {
|
|
1145
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1146
|
+
message: "callRaw failed",
|
|
1147
|
+
userMessage: "\u8C03\u7528\u5E95\u5C42\u65B9\u6CD5\u5931\u8D25"
|
|
1148
|
+
});
|
|
1149
|
+
safeOnError(err);
|
|
1150
|
+
throw err;
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1153
|
+
playRealVideo: (opt) => {
|
|
1154
|
+
if (destroyed) {
|
|
1155
|
+
const err = new DahuaPlayerError({
|
|
1156
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1157
|
+
message: "destroyed",
|
|
1158
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1159
|
+
});
|
|
1160
|
+
safeOnError(err);
|
|
1161
|
+
throw err;
|
|
1162
|
+
}
|
|
1163
|
+
if (!adapter) {
|
|
1164
|
+
const err = new DahuaPlayerError({
|
|
1165
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1166
|
+
message: "player not ready",
|
|
1167
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1168
|
+
});
|
|
1169
|
+
safeOnError(err);
|
|
1170
|
+
throw err;
|
|
1171
|
+
}
|
|
1172
|
+
showLoading("\u52A0\u8F7D\u89C6\u9891\u4E2D\u2026");
|
|
1173
|
+
try {
|
|
1174
|
+
adapter.playRealVideo(opt);
|
|
1175
|
+
} catch (e) {
|
|
1176
|
+
setLoading(false);
|
|
1177
|
+
const err = toDahuaError(e, {
|
|
1178
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1179
|
+
message: "playRealVideo failed",
|
|
1180
|
+
userMessage: "\u5B9E\u65F6\u9884\u89C8\u64AD\u653E\u5931\u8D25"
|
|
1181
|
+
});
|
|
1182
|
+
safeOnError(err);
|
|
1183
|
+
throw err;
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
playRecordVideo: (opt) => {
|
|
1187
|
+
if (destroyed) {
|
|
1188
|
+
const err = new DahuaPlayerError({
|
|
1189
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1190
|
+
message: "destroyed",
|
|
1191
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1192
|
+
});
|
|
1193
|
+
safeOnError(err);
|
|
1194
|
+
throw err;
|
|
1195
|
+
}
|
|
1196
|
+
if (!adapter) {
|
|
1197
|
+
const err = new DahuaPlayerError({
|
|
1198
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1199
|
+
message: "player not ready",
|
|
1200
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1201
|
+
});
|
|
1202
|
+
safeOnError(err);
|
|
1203
|
+
throw err;
|
|
1204
|
+
}
|
|
1205
|
+
showLoading("\u52A0\u8F7D\u5F55\u50CF\u4E2D\u2026");
|
|
1206
|
+
try {
|
|
1207
|
+
adapter.playRecordVideo(opt);
|
|
1208
|
+
} catch (e) {
|
|
1209
|
+
setLoading(false);
|
|
1210
|
+
const err = toDahuaError(e, {
|
|
1211
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1212
|
+
message: "playRecordVideo failed",
|
|
1213
|
+
userMessage: "\u5F55\u50CF\u56DE\u653E\u64AD\u653E\u5931\u8D25"
|
|
1214
|
+
});
|
|
1215
|
+
safeOnError(err);
|
|
1216
|
+
throw err;
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1219
|
+
pause: (windowIndex) => adapter == null ? void 0 : adapter.pauseWindow(windowIndex),
|
|
1220
|
+
play: (windowIndex) => adapter == null ? void 0 : adapter.playWindow(windowIndex),
|
|
1221
|
+
close: (windowIndex) => adapter == null ? void 0 : adapter.closeWindow(windowIndex),
|
|
1222
|
+
setPlayerNum: (n) => {
|
|
1223
|
+
if (destroyed) {
|
|
1224
|
+
const err = new DahuaPlayerError({
|
|
1225
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1226
|
+
message: "destroyed",
|
|
1227
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1228
|
+
});
|
|
1229
|
+
safeOnError(err);
|
|
1230
|
+
throw err;
|
|
1231
|
+
}
|
|
1232
|
+
if (!adapter) {
|
|
1233
|
+
const err = new DahuaPlayerError({
|
|
1234
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1235
|
+
message: "player not ready",
|
|
1236
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1237
|
+
});
|
|
1238
|
+
safeOnError(err);
|
|
1239
|
+
throw err;
|
|
1240
|
+
}
|
|
1241
|
+
try {
|
|
1242
|
+
adapter.setPlayerNum(n);
|
|
1243
|
+
} catch (e) {
|
|
1244
|
+
const err = toDahuaError(e, {
|
|
1245
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1246
|
+
message: "setPlayerNum failed",
|
|
1247
|
+
userMessage: "\u5207\u6362\u5E03\u5C40\u8DEF\u6570\u5931\u8D25"
|
|
1248
|
+
});
|
|
1249
|
+
safeOnError(err);
|
|
1250
|
+
throw err;
|
|
1251
|
+
}
|
|
1252
|
+
},
|
|
1253
|
+
jumpPlayByDateTime: (datetime, index) => {
|
|
1254
|
+
if (destroyed) {
|
|
1255
|
+
const err = new DahuaPlayerError({
|
|
1256
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1257
|
+
message: "destroyed",
|
|
1258
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1259
|
+
});
|
|
1260
|
+
safeOnError(err);
|
|
1261
|
+
throw err;
|
|
1262
|
+
}
|
|
1263
|
+
if (!adapter) {
|
|
1264
|
+
const err = new DahuaPlayerError({
|
|
1265
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1266
|
+
message: "player not ready",
|
|
1267
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1268
|
+
});
|
|
1269
|
+
safeOnError(err);
|
|
1270
|
+
throw err;
|
|
1271
|
+
}
|
|
1272
|
+
showLoading("\u8DF3\u8F6C\u4E2D\u2026");
|
|
1273
|
+
try {
|
|
1274
|
+
adapter.jumpPlayByDateTime(datetime, index);
|
|
1275
|
+
} catch (e) {
|
|
1276
|
+
setLoading(false);
|
|
1277
|
+
const err = toDahuaError(e, {
|
|
1278
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1279
|
+
message: "jumpPlayByDateTime failed",
|
|
1280
|
+
userMessage: "\u5F55\u50CF\u8DF3\u8F6C\u64AD\u653E\u5931\u8D25"
|
|
1281
|
+
});
|
|
1282
|
+
safeOnError(err);
|
|
1283
|
+
throw err;
|
|
1284
|
+
}
|
|
1285
|
+
},
|
|
1286
|
+
playSpeed: (speed, index) => {
|
|
1287
|
+
if (destroyed) {
|
|
1288
|
+
const err = new DahuaPlayerError({
|
|
1289
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1290
|
+
message: "destroyed",
|
|
1291
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1292
|
+
});
|
|
1293
|
+
safeOnError(err);
|
|
1294
|
+
throw err;
|
|
1295
|
+
}
|
|
1296
|
+
if (!adapter) {
|
|
1297
|
+
const err = new DahuaPlayerError({
|
|
1298
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1299
|
+
message: "player not ready",
|
|
1300
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1301
|
+
});
|
|
1302
|
+
safeOnError(err);
|
|
1303
|
+
throw err;
|
|
1304
|
+
}
|
|
1305
|
+
try {
|
|
1306
|
+
adapter.playSpeed(speed, index);
|
|
1307
|
+
} catch (e) {
|
|
1308
|
+
const err = toDahuaError(e, {
|
|
1309
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1310
|
+
message: "playSpeed failed",
|
|
1311
|
+
userMessage: "\u8BBE\u7F6E\u500D\u901F\u5931\u8D25"
|
|
1312
|
+
});
|
|
1313
|
+
safeOnError(err);
|
|
1314
|
+
throw err;
|
|
1315
|
+
}
|
|
1316
|
+
},
|
|
1317
|
+
setFullScreen: () => {
|
|
1318
|
+
if (destroyed) {
|
|
1319
|
+
const err = new DahuaPlayerError({
|
|
1320
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1321
|
+
message: "destroyed",
|
|
1322
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1323
|
+
});
|
|
1324
|
+
safeOnError(err);
|
|
1325
|
+
throw err;
|
|
1326
|
+
}
|
|
1327
|
+
if (!adapter) {
|
|
1328
|
+
const err = new DahuaPlayerError({
|
|
1329
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1330
|
+
message: "player not ready",
|
|
1331
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1332
|
+
});
|
|
1333
|
+
safeOnError(err);
|
|
1334
|
+
throw err;
|
|
1335
|
+
}
|
|
1336
|
+
try {
|
|
1337
|
+
adapter.setFullScreen();
|
|
1338
|
+
return;
|
|
1339
|
+
} catch {
|
|
1340
|
+
}
|
|
1341
|
+
const el = wrapper;
|
|
1342
|
+
const req = el == null ? void 0 : el.requestFullscreen;
|
|
1343
|
+
if (typeof req !== "function") {
|
|
1344
|
+
const err = new DahuaPlayerError({
|
|
1345
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1346
|
+
message: "fullscreen is not supported",
|
|
1347
|
+
userMessage: "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u5168\u5C4F"
|
|
1348
|
+
});
|
|
1349
|
+
safeOnError(err);
|
|
1350
|
+
throw err;
|
|
1351
|
+
}
|
|
1352
|
+
void req.call(el);
|
|
1353
|
+
},
|
|
1354
|
+
setExitFullScreen: () => {
|
|
1355
|
+
if (destroyed) {
|
|
1356
|
+
const err2 = new DahuaPlayerError({
|
|
1357
|
+
code: "DESTROYED" /* DESTROYED */,
|
|
1358
|
+
message: "destroyed",
|
|
1359
|
+
userMessage: "\u64AD\u653E\u5668\u5DF2\u9500\u6BC1"
|
|
1360
|
+
});
|
|
1361
|
+
safeOnError(err2);
|
|
1362
|
+
throw err2;
|
|
1363
|
+
}
|
|
1364
|
+
if (!adapter) {
|
|
1365
|
+
const err2 = new DahuaPlayerError({
|
|
1366
|
+
code: "SDK_INIT_FAILED" /* SDK_INIT_FAILED */,
|
|
1367
|
+
message: "player not ready",
|
|
1368
|
+
userMessage: "\u64AD\u653E\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7B49\u5F85 ready \u540E\u518D\u8C03\u7528"
|
|
1369
|
+
});
|
|
1370
|
+
safeOnError(err2);
|
|
1371
|
+
throw err2;
|
|
1372
|
+
}
|
|
1373
|
+
try {
|
|
1374
|
+
adapter.setExitFullScreen();
|
|
1375
|
+
return;
|
|
1376
|
+
} catch {
|
|
1377
|
+
}
|
|
1378
|
+
const doc = document;
|
|
1379
|
+
const exit = doc == null ? void 0 : doc.exitFullscreen;
|
|
1380
|
+
if (typeof exit === "function") {
|
|
1381
|
+
void exit.call(doc);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
const err = new DahuaPlayerError({
|
|
1385
|
+
code: "PLAY_FAILED" /* PLAY_FAILED */,
|
|
1386
|
+
message: "exitFullscreen is not supported",
|
|
1387
|
+
userMessage: "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u9000\u51FA\u5168\u5C4F"
|
|
1388
|
+
});
|
|
1389
|
+
safeOnError(err);
|
|
1390
|
+
throw err;
|
|
1391
|
+
},
|
|
1392
|
+
destroy: () => instance.destroy()
|
|
1393
|
+
},
|
|
1394
|
+
/**
|
|
1395
|
+
* 订阅事件(ready/play/pause/error/destroy)。
|
|
1396
|
+
*/
|
|
1397
|
+
on: (event, handler) => {
|
|
1398
|
+
var _a2;
|
|
1399
|
+
const set = (_a2 = listeners.get(event)) != null ? _a2 : /* @__PURE__ */ new Set();
|
|
1400
|
+
set.add(handler);
|
|
1401
|
+
listeners.set(event, set);
|
|
1402
|
+
},
|
|
1403
|
+
/**
|
|
1404
|
+
* 取消订阅事件。
|
|
1405
|
+
*/
|
|
1406
|
+
off: (event, handler) => {
|
|
1407
|
+
const set = listeners.get(event);
|
|
1408
|
+
if (!set) return;
|
|
1409
|
+
set.delete(handler);
|
|
1410
|
+
if (set.size === 0) listeners.delete(event);
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
if (dblClickFullscreen) {
|
|
1414
|
+
const onDblClick = () => {
|
|
1415
|
+
try {
|
|
1416
|
+
const doc = document;
|
|
1417
|
+
if (doc == null ? void 0 : doc.fullscreenElement) {
|
|
1418
|
+
instance.sdk.setExitFullScreen();
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
instance.sdk.setFullScreen();
|
|
1422
|
+
} catch {
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
1425
|
+
try {
|
|
1426
|
+
wrapper.addEventListener("dblclick", onDblClick);
|
|
1427
|
+
} catch {
|
|
1428
|
+
}
|
|
1429
|
+
const originDestroy = instance.destroy;
|
|
1430
|
+
instance.destroy = () => {
|
|
1431
|
+
try {
|
|
1432
|
+
wrapper.removeEventListener("dblclick", onDblClick);
|
|
1433
|
+
} catch {
|
|
1434
|
+
}
|
|
1435
|
+
originDestroy();
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
return instance;
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1442
|
+
0 && (module.exports = {
|
|
1443
|
+
DahuaPlayer,
|
|
1444
|
+
DahuaPlayerError,
|
|
1445
|
+
ErrorCode
|
|
1446
|
+
});
|
|
1447
|
+
//# sourceMappingURL=index.cjs.map
|