@guardvideo/player-sdk 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Hls from 'hls.js';
2
- import React, { forwardRef, useRef, useState, useEffect, useImperativeHandle, useCallback } from 'react';
2
+ import React, { forwardRef, useRef, useState, useEffect, useCallback, useImperativeHandle } from 'react';
3
3
 
4
4
  var PlayerState;
5
5
  (function (PlayerState) {
@@ -12,14 +12,44 @@ var PlayerState;
12
12
  PlayerState["ERROR"] = "error";
13
13
  })(PlayerState || (PlayerState = {}));
14
14
 
15
+ const DEFAULT_BRANDING = {
16
+ name: 'GuardVideo',
17
+ url: 'https://guardvid.com',
18
+ logoUrl: '',
19
+ accentColor: '#44c09b',
20
+ };
21
+ const DEFAULT_SECURITY = {
22
+ disableRightClick: false,
23
+ disableSelection: true,
24
+ disableDrag: true,
25
+ enableWatermark: false,
26
+ watermarkText: '',
27
+ disablePiP: false,
28
+ disableScreenCapture: false,
29
+ blockDevTools: false,
30
+ maxPlaybackRate: 2,
31
+ allowedDomains: [],
32
+ };
15
33
  class GuardVideoPlayer {
16
34
  constructor(videoElement, videoId, config) {
17
35
  this.videoId = videoId;
36
+ this.container = null;
18
37
  this.hls = null;
19
38
  this.state = PlayerState.IDLE;
20
39
  this.embedToken = null;
21
40
  this.currentQuality = null;
41
+ this.ctxMenu = null;
42
+ this.ctxStyleTag = null;
43
+ this.watermarkEl = null;
44
+ this.watermarkObserver = null;
45
+ this._onCtx = this.handleContextMenu.bind(this);
46
+ this._onDocClick = this.hideContextMenu.bind(this);
47
+ this._onKeyDown = this.handleKeyDown.bind(this);
48
+ this._onRateChange = this.enforceMaxRate.bind(this);
49
+ this._onSelectStart = (e) => e.preventDefault();
50
+ this._onDragStart = (e) => e.preventDefault();
22
51
  this.videoElement = videoElement;
52
+ this.container = videoElement.parentElement;
23
53
  this.config = {
24
54
  embedTokenEndpoint: config.embedTokenEndpoint,
25
55
  apiBaseUrl: config.apiBaseUrl || '',
@@ -29,12 +59,21 @@ class GuardVideoPlayer {
29
59
  className: config.className || '',
30
60
  style: config.style || {},
31
61
  hlsConfig: config.hlsConfig || {},
62
+ branding: { ...DEFAULT_BRANDING, ...config.branding },
63
+ contextMenuItems: config.contextMenuItems || [],
64
+ security: { ...DEFAULT_SECURITY, ...config.security },
65
+ viewerName: config.viewerName || '',
66
+ viewerEmail: config.viewerEmail || '',
67
+ forensicWatermark: config.forensicWatermark !== false,
32
68
  onReady: config.onReady || (() => { }),
33
69
  onError: config.onError || (() => { }),
34
70
  onQualityChange: config.onQualityChange || (() => { }),
35
71
  onStateChange: config.onStateChange || (() => { }),
36
72
  };
37
73
  this.log('Initializing GuardVideo Player', { videoId, config });
74
+ if (!this.checkAllowedDomain())
75
+ return;
76
+ this.applySecurity();
38
77
  this.initialize();
39
78
  }
40
79
  log(message, data) {
@@ -52,12 +91,321 @@ class GuardVideoPlayer {
52
91
  this.log(`State changed to: ${newState}`);
53
92
  }
54
93
  }
94
+ checkAllowedDomain() {
95
+ const domains = this.config.security.allowedDomains;
96
+ if (!domains || domains.length === 0)
97
+ return true;
98
+ const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
99
+ const allowed = domains.some((d) => currentOrigin === d || currentOrigin.endsWith(`.${d.replace(/^https?:\/\//, '')}`));
100
+ if (!allowed) {
101
+ this.handleError({
102
+ code: 'DOMAIN_NOT_ALLOWED',
103
+ message: `This player is not authorized to run on ${currentOrigin}`,
104
+ fatal: true,
105
+ });
106
+ return false;
107
+ }
108
+ return true;
109
+ }
110
+ applySecurity() {
111
+ const sec = this.config.security;
112
+ const target = this.container || this.videoElement;
113
+ target.addEventListener('contextmenu', this._onCtx);
114
+ document.addEventListener('click', this._onDocClick);
115
+ if (sec.disableSelection) {
116
+ target.addEventListener('selectstart', this._onSelectStart);
117
+ target.style.userSelect = 'none';
118
+ target.style.webkitUserSelect = 'none';
119
+ }
120
+ if (sec.disableDrag) {
121
+ this.videoElement.addEventListener('dragstart', this._onDragStart);
122
+ this.videoElement.draggable = false;
123
+ }
124
+ if (sec.disablePiP) {
125
+ this.videoElement.disablePictureInPicture = true;
126
+ }
127
+ if (sec.disableScreenCapture) {
128
+ if ('mediaKeys' in this.videoElement && typeof navigator.requestMediaKeySystemAccess === 'function') {
129
+ this.log('Screen-capture protection: EME hint applied');
130
+ }
131
+ target.style.setProperty('-webkit-app-region', 'no-drag');
132
+ }
133
+ if (sec.blockDevTools) {
134
+ document.addEventListener('keydown', this._onKeyDown);
135
+ }
136
+ if (sec.maxPlaybackRate) {
137
+ this.videoElement.addEventListener('ratechange', this._onRateChange);
138
+ }
139
+ if (sec.enableWatermark && sec.watermarkText && this.container) {
140
+ this.createWatermark(sec.watermarkText);
141
+ }
142
+ this.injectProtectiveStyles();
143
+ }
144
+ handleContextMenu(e) {
145
+ e.preventDefault();
146
+ e.stopPropagation();
147
+ const sec = this.config.security;
148
+ if (sec.disableRightClick)
149
+ return;
150
+ const me = e;
151
+ this.showContextMenu(me.clientX, me.clientY);
152
+ }
153
+ showContextMenu(x, y) {
154
+ this.hideContextMenu();
155
+ const branding = this.config.branding;
156
+ const extraItems = this.config.contextMenuItems;
157
+ const menu = document.createElement('div');
158
+ menu.className = 'gv-ctx-menu';
159
+ menu.setAttribute('role', 'menu');
160
+ const header = document.createElement('a');
161
+ header.className = 'gv-ctx-header';
162
+ header.href = branding.url;
163
+ header.target = '_blank';
164
+ header.rel = 'noopener noreferrer';
165
+ header.setAttribute('role', 'menuitem');
166
+ if (branding.logoUrl) {
167
+ const logo = document.createElement('img');
168
+ logo.src = branding.logoUrl;
169
+ logo.alt = branding.name;
170
+ logo.className = 'gv-ctx-logo';
171
+ logo.width = 20;
172
+ logo.height = 20;
173
+ header.appendChild(logo);
174
+ }
175
+ else {
176
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
177
+ svg.setAttribute('width', '18');
178
+ svg.setAttribute('height', '18');
179
+ svg.setAttribute('viewBox', '0 0 24 24');
180
+ svg.setAttribute('fill', 'none');
181
+ svg.setAttribute('stroke', branding.accentColor);
182
+ svg.setAttribute('stroke-width', '2');
183
+ svg.setAttribute('stroke-linecap', 'round');
184
+ svg.setAttribute('stroke-linejoin', 'round');
185
+ svg.innerHTML = '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>';
186
+ header.appendChild(svg);
187
+ }
188
+ const nameSpan = document.createElement('span');
189
+ nameSpan.className = 'gv-ctx-brand-name';
190
+ nameSpan.textContent = branding.name;
191
+ header.appendChild(nameSpan);
192
+ const tagSpan = document.createElement('span');
193
+ tagSpan.className = 'gv-ctx-tag';
194
+ tagSpan.textContent = 'Secure Video Player';
195
+ header.appendChild(tagSpan);
196
+ menu.appendChild(header);
197
+ if (extraItems.length > 0) {
198
+ extraItems.forEach((item) => {
199
+ if (item.separator) {
200
+ const sep = document.createElement('div');
201
+ sep.className = 'gv-ctx-sep';
202
+ menu.appendChild(sep);
203
+ }
204
+ const row = document.createElement('div');
205
+ row.className = 'gv-ctx-item';
206
+ row.setAttribute('role', 'menuitem');
207
+ row.tabIndex = 0;
208
+ if (item.icon) {
209
+ const ico = document.createElement('img');
210
+ ico.src = item.icon;
211
+ ico.width = 14;
212
+ ico.height = 14;
213
+ ico.className = 'gv-ctx-item-icon';
214
+ row.appendChild(ico);
215
+ }
216
+ const label = document.createElement('span');
217
+ label.textContent = item.label;
218
+ row.appendChild(label);
219
+ row.addEventListener('click', (ev) => {
220
+ ev.stopPropagation();
221
+ this.hideContextMenu();
222
+ if (item.onClick) {
223
+ item.onClick();
224
+ }
225
+ else if (item.href) {
226
+ window.open(item.href, '_blank', 'noopener,noreferrer');
227
+ }
228
+ });
229
+ menu.appendChild(row);
230
+ });
231
+ }
232
+ const sep = document.createElement('div');
233
+ sep.className = 'gv-ctx-sep';
234
+ menu.appendChild(sep);
235
+ const version = document.createElement('div');
236
+ version.className = 'gv-ctx-version';
237
+ version.textContent = `${branding.name} Player v1.0`;
238
+ menu.appendChild(version);
239
+ document.body.appendChild(menu);
240
+ const rect = menu.getBoundingClientRect();
241
+ const vw = window.innerWidth;
242
+ const vh = window.innerHeight;
243
+ menu.style.left = `${x + rect.width > vw ? vw - rect.width - 8 : x}px`;
244
+ menu.style.top = `${y + rect.height > vh ? vh - rect.height - 8 : y}px`;
245
+ this.ctxMenu = menu;
246
+ }
247
+ hideContextMenu() {
248
+ if (this.ctxMenu) {
249
+ this.ctxMenu.remove();
250
+ this.ctxMenu = null;
251
+ }
252
+ }
253
+ injectProtectiveStyles() {
254
+ if (this.ctxStyleTag)
255
+ return;
256
+ const branding = this.config.branding;
257
+ const accent = branding.accentColor;
258
+ const css = `
259
+ /* GuardVideo branded context menu */
260
+ .gv-ctx-menu {
261
+ position: fixed;
262
+ z-index: 2147483647;
263
+ min-width: 220px;
264
+ background: rgba(18, 18, 22, 0.96);
265
+ backdrop-filter: blur(12px);
266
+ -webkit-backdrop-filter: blur(12px);
267
+ border: 1px solid rgba(255,255,255,0.08);
268
+ border-radius: 10px;
269
+ padding: 6px 0;
270
+ box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.04);
271
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
272
+ font-size: 13px;
273
+ color: #e4e4e7;
274
+ user-select: none;
275
+ animation: gv-ctx-in 0.12s ease-out;
276
+ }
277
+ @keyframes gv-ctx-in {
278
+ from { opacity: 0; transform: scale(0.96); }
279
+ to { opacity: 1; transform: scale(1); }
280
+ }
281
+
282
+ .gv-ctx-header {
283
+ display: flex;
284
+ align-items: center;
285
+ gap: 8px;
286
+ padding: 8px 14px 8px 12px;
287
+ text-decoration: none;
288
+ color: inherit;
289
+ transition: background 0.15s;
290
+ border-radius: 6px 6px 0 0;
291
+ }
292
+ .gv-ctx-header:hover { background: rgba(255,255,255,0.06); }
293
+
294
+ .gv-ctx-logo { border-radius: 4px; }
295
+
296
+ .gv-ctx-brand-name {
297
+ font-weight: 600;
298
+ color: ${accent};
299
+ white-space: nowrap;
300
+ }
301
+
302
+ .gv-ctx-tag {
303
+ margin-left: auto;
304
+ font-size: 10px;
305
+ color: rgba(255,255,255,0.35);
306
+ white-space: nowrap;
307
+ }
308
+
309
+ .gv-ctx-sep {
310
+ height: 1px;
311
+ margin: 4px 10px;
312
+ background: rgba(255,255,255,0.07);
313
+ }
314
+
315
+ .gv-ctx-item {
316
+ display: flex;
317
+ align-items: center;
318
+ gap: 8px;
319
+ padding: 7px 14px 7px 12px;
320
+ cursor: pointer;
321
+ transition: background 0.15s;
322
+ }
323
+ .gv-ctx-item:hover { background: rgba(255,255,255,0.06); }
324
+ .gv-ctx-item-icon { border-radius: 2px; }
325
+
326
+ .gv-ctx-version {
327
+ padding: 4px 14px 6px 12px;
328
+ font-size: 10px;
329
+ color: rgba(255,255,255,0.25);
330
+ }
331
+
332
+ /* Watermark overlay */
333
+ .gv-watermark {
334
+ position: absolute;
335
+ inset: 0;
336
+ pointer-events: none;
337
+ overflow: hidden;
338
+ z-index: 10;
339
+ }
340
+ .gv-watermark-text {
341
+ position: absolute;
342
+ white-space: nowrap;
343
+ font-size: 14px;
344
+ font-family: monospace;
345
+ color: rgba(255,255,255,0.07);
346
+ transform: rotate(-30deg);
347
+ user-select: none;
348
+ pointer-events: none;
349
+ }
350
+ `;
351
+ const tag = document.createElement('style');
352
+ tag.setAttribute('data-guardvideo', 'player-styles');
353
+ tag.textContent = css;
354
+ document.head.appendChild(tag);
355
+ this.ctxStyleTag = tag;
356
+ }
357
+ createWatermark(text) {
358
+ if (!this.container)
359
+ return;
360
+ const overlay = document.createElement('div');
361
+ overlay.className = 'gv-watermark';
362
+ for (let row = 0; row < 5; row++) {
363
+ for (let col = 0; col < 4; col++) {
364
+ const span = document.createElement('span');
365
+ span.className = 'gv-watermark-text';
366
+ span.textContent = text;
367
+ span.style.left = `${col * 28 + (row % 2) * 14}%`;
368
+ span.style.top = `${row * 22}%`;
369
+ overlay.appendChild(span);
370
+ }
371
+ }
372
+ this.container.style.position = 'relative';
373
+ this.container.appendChild(overlay);
374
+ this.watermarkEl = overlay;
375
+ this.watermarkObserver = new MutationObserver(() => {
376
+ if (this.container && this.watermarkEl && !this.container.contains(this.watermarkEl)) {
377
+ this.container.appendChild(this.watermarkEl);
378
+ }
379
+ });
380
+ this.watermarkObserver.observe(this.container, { childList: true, subtree: false });
381
+ }
382
+ handleKeyDown(e) {
383
+ if (e.key === 'F12') {
384
+ e.preventDefault();
385
+ return;
386
+ }
387
+ if (e.ctrlKey && e.shiftKey && ['I', 'J', 'C'].includes(e.key.toUpperCase())) {
388
+ e.preventDefault();
389
+ return;
390
+ }
391
+ if (e.ctrlKey && e.key.toUpperCase() === 'U') {
392
+ e.preventDefault();
393
+ }
394
+ }
395
+ enforceMaxRate() {
396
+ const max = this.config.security.maxPlaybackRate;
397
+ if (this.videoElement.playbackRate > max) {
398
+ this.videoElement.playbackRate = max;
399
+ this.log(`Playback rate clamped to ${max}`);
400
+ }
401
+ }
55
402
  async initialize() {
56
403
  try {
57
404
  this.setState(PlayerState.LOADING);
58
405
  this.embedToken = await this.fetchEmbedToken();
59
406
  this.log('Embed token received', this.embedToken);
60
407
  await this.initializePlayer();
408
+ await this.fetchAndApplyWatermark();
61
409
  }
62
410
  catch (err) {
63
411
  this.handleError({
@@ -68,6 +416,35 @@ class GuardVideoPlayer {
68
416
  });
69
417
  }
70
418
  }
419
+ async fetchAndApplyWatermark() {
420
+ if (!this.embedToken || !this.config.apiBaseUrl)
421
+ return;
422
+ try {
423
+ const tokenId = this.embedToken.tokenId;
424
+ const url = `${this.config.apiBaseUrl}/videos/stream/${this.videoId}/viewer-config?token=${encodeURIComponent(tokenId)}`;
425
+ const resp = await fetch(url, { credentials: 'omit' });
426
+ if (!resp.ok) {
427
+ this.log('viewer-config fetch failed, falling back to SDK config', resp.status);
428
+ const sec = this.config.security;
429
+ if (sec.enableWatermark && sec.watermarkText && this.container) {
430
+ this.createWatermark(sec.watermarkText);
431
+ }
432
+ return;
433
+ }
434
+ const cfg = await resp.json();
435
+ this.log('Watermark config from server:', cfg);
436
+ if (cfg.enableWatermark && cfg.watermarkText && this.container) {
437
+ this.createWatermark(cfg.watermarkText);
438
+ }
439
+ }
440
+ catch (err) {
441
+ this.log('fetchAndApplyWatermark error (non-fatal):', err);
442
+ const sec = this.config.security;
443
+ if (sec.enableWatermark && sec.watermarkText && this.container) {
444
+ this.createWatermark(sec.watermarkText);
445
+ }
446
+ }
447
+ }
71
448
  async fetchEmbedToken() {
72
449
  const url = `${this.config.embedTokenEndpoint}/${this.videoId}`;
73
450
  this.log('Fetching embed token from', url);
@@ -80,6 +457,9 @@ class GuardVideoPlayer {
80
457
  allowedDomain: window.location.origin,
81
458
  expiresInMinutes: 120,
82
459
  maxViews: null,
460
+ ...(this.config.viewerName ? { viewerName: this.config.viewerName } : {}),
461
+ ...(this.config.viewerEmail ? { viewerEmail: this.config.viewerEmail } : {}),
462
+ forensicWatermark: this.config.forensicWatermark,
83
463
  }),
84
464
  });
85
465
  if (!response.ok) {
@@ -256,6 +636,17 @@ class GuardVideoPlayer {
256
636
  }
257
637
  destroy() {
258
638
  this.log('Destroying player');
639
+ const target = this.container || this.videoElement;
640
+ target.removeEventListener('contextmenu', this._onCtx);
641
+ target.removeEventListener('selectstart', this._onSelectStart);
642
+ this.videoElement.removeEventListener('dragstart', this._onDragStart);
643
+ this.videoElement.removeEventListener('ratechange', this._onRateChange);
644
+ document.removeEventListener('click', this._onDocClick);
645
+ document.removeEventListener('keydown', this._onKeyDown);
646
+ this.hideContextMenu();
647
+ this.watermarkObserver?.disconnect();
648
+ this.watermarkEl?.remove();
649
+ this.ctxStyleTag?.remove();
259
650
  if (this.hls) {
260
651
  this.hls.destroy();
261
652
  this.hls = null;
@@ -266,12 +657,446 @@ class GuardVideoPlayer {
266
657
  }
267
658
  }
268
659
 
660
+ function formatTime(seconds) {
661
+ if (!isFinite(seconds) || isNaN(seconds))
662
+ return '0:00';
663
+ const h = Math.floor(seconds / 3600);
664
+ const m = Math.floor((seconds % 3600) / 60);
665
+ const s = Math.floor(seconds % 60);
666
+ const mm = String(m).padStart(h > 0 ? 2 : 1, '0');
667
+ const ss = String(s).padStart(2, '0');
668
+ return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
669
+ }
670
+ const PlayIcon = () => (React.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor" },
671
+ React.createElement("polygon", { points: "5,3 19,12 5,21" })));
672
+ const PauseIcon = () => (React.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor" },
673
+ React.createElement("rect", { x: "6", y: "4", width: "4", height: "16", rx: "1" }),
674
+ React.createElement("rect", { x: "14", y: "4", width: "4", height: "16", rx: "1" })));
675
+ const ReplayIcon = () => (React.createElement("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor" },
676
+ React.createElement("path", { d: "M12 5V1L7 6l5 5V7c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z" })));
677
+ const VolumeHighIcon = () => (React.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor" },
678
+ React.createElement("path", { d: "M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z" })));
679
+ const VolumeMuteIcon = () => (React.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor" },
680
+ React.createElement("path", { d: "M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z" })));
681
+ const FullscreenIcon = () => (React.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor" },
682
+ React.createElement("path", { d: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" })));
683
+ const ExitFullscreenIcon = () => (React.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor" },
684
+ React.createElement("path", { d: "M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" })));
685
+ const SettingsIcon = () => (React.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor" },
686
+ React.createElement("path", { d: "M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z" })));
687
+ const ShieldIcon = ({ color }) => (React.createElement("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" },
688
+ React.createElement("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" })));
689
+ let _stylesInjected = false;
690
+ function injectPlayerStyles(accentColor) {
691
+ if (_stylesInjected)
692
+ return;
693
+ _stylesInjected = true;
694
+ const css = `
695
+ /* ── GuardVideo Custom Player ─────────────────────────────── */
696
+ .gvp-root {
697
+ position: relative;
698
+ background: #000;
699
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
700
+ border-radius: 10px;
701
+ overflow: hidden;
702
+ -webkit-user-select: none;
703
+ user-select: none;
704
+ outline: none;
705
+ }
706
+ .gvp-root:focus-visible { box-shadow: 0 0 0 3px ${accentColor}66; }
707
+
708
+ .gvp-video {
709
+ display: block;
710
+ width: 100%;
711
+ height: 100%;
712
+ object-fit: contain;
713
+ border-radius: 10px;
714
+ }
715
+
716
+ /* ── Loading spinner ─────────────────────────────────────── */
717
+ .gvp-spinner {
718
+ position: absolute;
719
+ inset: 0;
720
+ display: flex;
721
+ align-items: center;
722
+ justify-content: center;
723
+ pointer-events: none;
724
+ background: rgba(0,0,0,0.55);
725
+ border-radius: 10px;
726
+ }
727
+ .gvp-spinner-ring {
728
+ width: 48px;
729
+ height: 48px;
730
+ border: 3px solid rgba(255,255,255,0.15);
731
+ border-top-color: ${accentColor};
732
+ border-radius: 50%;
733
+ animation: gvp-spin 0.8s linear infinite;
734
+ }
735
+ @keyframes gvp-spin { to { transform: rotate(360deg); } }
736
+
737
+ /* ── Big centre play button (initial state) ───────────────── */
738
+ .gvp-center-play {
739
+ position: absolute;
740
+ inset: 0;
741
+ display: flex;
742
+ align-items: center;
743
+ justify-content: center;
744
+ cursor: pointer;
745
+ background: rgba(0,0,0,0.3);
746
+ transition: background 0.2s;
747
+ border-radius: 10px;
748
+ }
749
+ .gvp-center-play:hover { background: rgba(0,0,0,0.45); }
750
+ .gvp-center-play-btn {
751
+ width: 72px;
752
+ height: 72px;
753
+ background: rgba(255,255,255,0.12);
754
+ backdrop-filter: blur(8px);
755
+ border-radius: 50%;
756
+ display: flex;
757
+ align-items: center;
758
+ justify-content: center;
759
+ border: 2px solid rgba(255,255,255,0.25);
760
+ transition: background 0.2s, transform 0.15s;
761
+ color: #fff;
762
+ }
763
+ .gvp-center-play:hover .gvp-center-play-btn {
764
+ background: ${accentColor}cc;
765
+ transform: scale(1.08);
766
+ }
767
+
768
+ /* ── Click-to-toggle overlay ─────────────────────────────── */
769
+ .gvp-click-area {
770
+ position: absolute;
771
+ inset: 0;
772
+ cursor: pointer;
773
+ z-index: 1;
774
+ }
775
+
776
+ /* ── Ripple effect on click ──────────────────────────────── */
777
+ .gvp-ripple {
778
+ position: absolute;
779
+ border-radius: 50%;
780
+ transform: scale(0);
781
+ background: rgba(255,255,255,0.25);
782
+ animation: gvp-ripple-anim 0.5s ease-out forwards;
783
+ pointer-events: none;
784
+ z-index: 2;
785
+ }
786
+ @keyframes gvp-ripple-anim { to { transform: scale(4); opacity: 0; } }
787
+
788
+ /* ── Controls bar ────────────────────────────────────────── */
789
+ .gvp-controls {
790
+ position: absolute;
791
+ bottom: 0;
792
+ left: 0;
793
+ right: 0;
794
+ z-index: 10;
795
+ background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
796
+ padding: 36px 14px 10px;
797
+ transition: opacity 0.3s, transform 0.3s;
798
+ border-radius: 0 0 10px 10px;
799
+ }
800
+ .gvp-controls-hidden {
801
+ opacity: 0;
802
+ transform: translateY(6px);
803
+ pointer-events: none;
804
+ }
805
+
806
+ /* ── Progress / seek bar ─────────────────────────────────── */
807
+ .gvp-seek-row {
808
+ display: flex;
809
+ align-items: center;
810
+ gap: 8px;
811
+ margin-bottom: 6px;
812
+ }
813
+ .gvp-seek-wrap {
814
+ flex: 1;
815
+ position: relative;
816
+ height: 4px;
817
+ cursor: pointer;
818
+ padding: 8px 0;
819
+ margin: -8px 0;
820
+ box-sizing: content-box;
821
+ }
822
+ .gvp-seek-track {
823
+ height: 4px;
824
+ background: rgba(255,255,255,0.2);
825
+ border-radius: 4px;
826
+ position: relative;
827
+ overflow: hidden;
828
+ transition: height 0.15s;
829
+ }
830
+ .gvp-seek-wrap:hover .gvp-seek-track { height: 6px; }
831
+ .gvp-seek-buffered {
832
+ position: absolute;
833
+ left: 0;
834
+ top: 0;
835
+ height: 100%;
836
+ background: rgba(255,255,255,0.35);
837
+ border-radius: 4px;
838
+ pointer-events: none;
839
+ }
840
+ .gvp-seek-progress {
841
+ position: absolute;
842
+ left: 0;
843
+ top: 0;
844
+ height: 100%;
845
+ background: ${accentColor};
846
+ border-radius: 4px;
847
+ pointer-events: none;
848
+ transition: width 0.1s linear;
849
+ }
850
+ .gvp-seek-thumb {
851
+ position: absolute;
852
+ top: 50%;
853
+ transform: translate(-50%, -50%);
854
+ width: 13px;
855
+ height: 13px;
856
+ background: #fff;
857
+ border-radius: 50%;
858
+ box-shadow: 0 1px 4px rgba(0,0,0,0.5);
859
+ pointer-events: none;
860
+ opacity: 0;
861
+ transition: opacity 0.15s;
862
+ }
863
+ .gvp-seek-wrap:hover .gvp-seek-thumb { opacity: 1; }
864
+
865
+ /* ── Time tooltip ─────────────────────────────────────────── */
866
+ .gvp-seek-tooltip {
867
+ position: absolute;
868
+ bottom: 24px;
869
+ transform: translateX(-50%);
870
+ background: rgba(0,0,0,0.8);
871
+ color: #fff;
872
+ font-size: 11px;
873
+ font-weight: 500;
874
+ padding: 3px 7px;
875
+ border-radius: 4px;
876
+ pointer-events: none;
877
+ white-space: nowrap;
878
+ opacity: 0;
879
+ transition: opacity 0.1s;
880
+ }
881
+ .gvp-seek-wrap:hover .gvp-seek-tooltip { opacity: 1; }
882
+
883
+ /* ── Bottom control row ───────────────────────────────────── */
884
+ .gvp-btn-row {
885
+ display: flex;
886
+ align-items: center;
887
+ gap: 4px;
888
+ }
889
+ .gvp-btn {
890
+ background: none;
891
+ border: none;
892
+ color: #fff;
893
+ cursor: pointer;
894
+ padding: 5px;
895
+ border-radius: 6px;
896
+ display: flex;
897
+ align-items: center;
898
+ justify-content: center;
899
+ transition: background 0.15s, color 0.15s;
900
+ flex-shrink: 0;
901
+ }
902
+ .gvp-btn:hover { background: rgba(255,255,255,0.12); color: ${accentColor}; }
903
+ .gvp-btn:active { background: rgba(255,255,255,0.2); }
904
+
905
+ /* ── Volume section ──────────────────────────────────────── */
906
+ .gvp-volume-wrap {
907
+ display: flex;
908
+ align-items: center;
909
+ gap: 5px;
910
+ }
911
+ .gvp-volume-slider {
912
+ -webkit-appearance: none;
913
+ width: 70px;
914
+ height: 4px;
915
+ background: rgba(255,255,255,0.25);
916
+ border-radius: 4px;
917
+ outline: none;
918
+ cursor: pointer;
919
+ accent-color: ${accentColor};
920
+ transition: width 0.2s;
921
+ }
922
+ .gvp-volume-slider::-webkit-slider-thumb {
923
+ -webkit-appearance: none;
924
+ width: 12px; height: 12px;
925
+ border-radius: 50%;
926
+ background: #fff;
927
+ cursor: pointer;
928
+ box-shadow: 0 1px 3px rgba(0,0,0,0.4);
929
+ }
930
+ .gvp-volume-slider::-moz-range-thumb {
931
+ width: 12px; height: 12px;
932
+ border-radius: 50%;
933
+ background: #fff;
934
+ cursor: pointer;
935
+ border: none;
936
+ }
937
+
938
+ /* ── Time display ─────────────────────────────────────────── */
939
+ .gvp-time {
940
+ font-size: 12px;
941
+ color: rgba(255,255,255,0.85);
942
+ font-variant-numeric: tabular-nums;
943
+ white-space: nowrap;
944
+ letter-spacing: 0.02em;
945
+ }
946
+
947
+ /* ── Spacer ──────────────────────────────────────────────── */
948
+ .gvp-spacer { flex: 1; }
949
+
950
+ /* ── Quality / Settings menu ──────────────────────────────── */
951
+ .gvp-menu-wrap {
952
+ position: relative;
953
+ }
954
+ .gvp-menu {
955
+ position: absolute;
956
+ bottom: calc(100% + 8px);
957
+ right: 0;
958
+ background: rgba(18,18,22,0.95);
959
+ backdrop-filter: blur(12px);
960
+ -webkit-backdrop-filter: blur(12px);
961
+ border: 1px solid rgba(255,255,255,0.08);
962
+ border-radius: 8px;
963
+ min-width: 140px;
964
+ overflow: hidden;
965
+ box-shadow: 0 8px 24px rgba(0,0,0,0.5);
966
+ animation: gvp-menu-in 0.1s ease-out;
967
+ z-index: 20;
968
+ }
969
+ @keyframes gvp-menu-in { from { opacity:0; transform: scale(0.95) translateY(4px); } to { opacity:1; transform: scale(1) translateY(0); } }
970
+ .gvp-menu-title {
971
+ font-size: 10px;
972
+ font-weight: 600;
973
+ text-transform: uppercase;
974
+ letter-spacing: 0.08em;
975
+ color: rgba(255,255,255,0.4);
976
+ padding: 8px 12px 4px;
977
+ }
978
+ .gvp-menu-item {
979
+ display: flex;
980
+ align-items: center;
981
+ justify-content: space-between;
982
+ padding: 7px 12px;
983
+ font-size: 13px;
984
+ color: rgba(255,255,255,0.85);
985
+ cursor: pointer;
986
+ transition: background 0.12s;
987
+ gap: 10px;
988
+ }
989
+ .gvp-menu-item:hover { background: rgba(255,255,255,0.07); }
990
+ .gvp-menu-item-active { color: ${accentColor}; font-weight: 600; }
991
+ .gvp-menu-check { font-size: 14px; color: ${accentColor}; }
992
+ .gvp-menu-sep { height: 1px; background: rgba(255,255,255,0.07); margin: 3px 0; }
993
+
994
+ /* ── Error overlay ────────────────────────────────────────── */
995
+ .gvp-error {
996
+ position: absolute;
997
+ inset: 0;
998
+ display: flex;
999
+ flex-direction: column;
1000
+ align-items: center;
1001
+ justify-content: center;
1002
+ background: rgba(0,0,0,0.8);
1003
+ color: #fff;
1004
+ gap: 10px;
1005
+ padding: 24px;
1006
+ border-radius: 10px;
1007
+ text-align: center;
1008
+ }
1009
+ .gvp-error-icon { font-size: 36px; }
1010
+ .gvp-error-code { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; color: #f87171; text-transform: uppercase; }
1011
+ .gvp-error-msg { font-size: 14px; color: rgba(255,255,255,0.7); max-width: 320px; line-height: 1.5; }
1012
+
1013
+ /* ── Secure badge ─────────────────────────────────────────── */
1014
+ .gvp-badge {
1015
+ position: absolute;
1016
+ top: 10px;
1017
+ right: 12px;
1018
+ display: flex;
1019
+ align-items: center;
1020
+ gap: 5px;
1021
+ background: rgba(0,0,0,0.55);
1022
+ backdrop-filter: blur(6px);
1023
+ border-radius: 20px;
1024
+ padding: 3px 9px 3px 7px;
1025
+ font-size: 10px;
1026
+ font-weight: 600;
1027
+ color: ${accentColor};
1028
+ pointer-events: none;
1029
+ z-index: 5;
1030
+ letter-spacing: 0.04em;
1031
+ transition: opacity 0.3s;
1032
+ }
1033
+ .gvp-badge-hidden { opacity: 0; }
1034
+
1035
+ /* ── Forensic watermark strip ─────────────────────────────── */
1036
+ .gvp-watermark {
1037
+ position: absolute;
1038
+ inset: 0;
1039
+ pointer-events: none;
1040
+ overflow: hidden;
1041
+ z-index: 6;
1042
+ }
1043
+ .gvp-watermark-text {
1044
+ position: absolute;
1045
+ white-space: nowrap;
1046
+ font-size: 13px;
1047
+ font-family: monospace;
1048
+ color: rgba(255,255,255,0.065);
1049
+ transform: rotate(-28deg);
1050
+ user-select: none;
1051
+ pointer-events: none;
1052
+ letter-spacing: 0.05em;
1053
+ }
1054
+
1055
+ /* ── Playback rate menu ────────────────────────────────────── */
1056
+ .gvp-rate-label {
1057
+ font-size: 11px;
1058
+ font-weight: 700;
1059
+ color: rgba(255,255,255,0.7);
1060
+ min-width: 28px;
1061
+ text-align: center;
1062
+ cursor: pointer;
1063
+ padding: 5px 4px;
1064
+ border-radius: 4px;
1065
+ transition: background 0.12s;
1066
+ flex-shrink: 0;
1067
+ }
1068
+ .gvp-rate-label:hover { background: rgba(255,255,255,0.1); }
1069
+ `;
1070
+ const tag = document.createElement('style');
1071
+ tag.setAttribute('data-guardvideo', 'player-ui-styles');
1072
+ tag.textContent = css;
1073
+ document.head.appendChild(tag);
1074
+ }
269
1075
  const GuardVideoPlayerComponent = forwardRef((props, ref) => {
270
- const { videoId, width = '100%', height = 'auto', embedTokenEndpoint, apiBaseUrl, debug = false, autoplay = false, controls = true, className = '', style = {}, hlsConfig, onReady, onError, onQualityChange, onStateChange, onTimeUpdate, onEnded, } = props;
1076
+ const { videoId, width = '100%', height = 'auto', embedTokenEndpoint, apiBaseUrl, debug = false, autoplay = false, className = '', style = {}, hlsConfig, branding, contextMenuItems, security, viewerName, viewerEmail, forensicWatermark = true, onReady, onError, onQualityChange, onStateChange, onTimeUpdate: onTimeUpdateProp, onEnded, } = props;
1077
+ const accentColor = branding?.accentColor ?? '#44c09b';
1078
+ const brandName = branding?.name ?? 'GuardVideo';
1079
+ const containerRef = useRef(null);
271
1080
  const videoRef = useRef(null);
272
1081
  const playerRef = useRef(null);
1082
+ const seekRef = useRef(null);
1083
+ const hideTimer = useRef(null);
1084
+ const [playerState, setPlayerState] = useState(PlayerState.IDLE);
1085
+ const [currentTime, setCurrentTime] = useState(0);
1086
+ const [duration, setDuration] = useState(0);
1087
+ const [buffered, setBuffered] = useState(0);
1088
+ const [volume, setVolume] = useState(1);
1089
+ const [muted, setMuted] = useState(false);
1090
+ const [showControls, setShowControls] = useState(true);
1091
+ const [isFullscreen, setIsFullscreen] = useState(false);
1092
+ const [showMenu, setShowMenu] = useState(null);
1093
+ const [qualityLevels, setQualityLevels] = useState([]);
1094
+ const [currentQualityIdx, setCurrentQualityIdx] = useState(-1);
1095
+ const [playbackRate, setPlaybackRate] = useState(1);
1096
+ const [seekTooltip, setSeekTooltip] = useState(null);
273
1097
  const [error, setError] = useState(null);
274
- const [currentState, setCurrentState] = useState(PlayerState.IDLE);
1098
+ const [watermarkText, setWatermarkText] = useState(null);
1099
+ useEffect(() => { injectPlayerStyles(accentColor); }, [accentColor]);
275
1100
  useEffect(() => {
276
1101
  if (!videoRef.current || playerRef.current)
277
1102
  return;
@@ -280,12 +1105,22 @@ const GuardVideoPlayerComponent = forwardRef((props, ref) => {
280
1105
  apiBaseUrl,
281
1106
  debug,
282
1107
  autoplay,
283
- controls,
284
- className,
285
- style,
1108
+ controls: false,
1109
+ className: '',
1110
+ style: {},
286
1111
  hlsConfig,
1112
+ branding,
1113
+ contextMenuItems,
1114
+ security,
1115
+ viewerName,
1116
+ viewerEmail,
1117
+ forensicWatermark,
287
1118
  onReady: () => {
288
1119
  onReady?.();
1120
+ setTimeout(() => {
1121
+ const levels = player.getQualityLevels();
1122
+ setQualityLevels(levels);
1123
+ }, 100);
289
1124
  },
290
1125
  onError: (err) => {
291
1126
  setError(err);
@@ -293,9 +1128,11 @@ const GuardVideoPlayerComponent = forwardRef((props, ref) => {
293
1128
  },
294
1129
  onQualityChange: (quality) => {
295
1130
  onQualityChange?.(quality);
1131
+ const idx = player.getQualityLevels().findIndex(l => l.name === quality);
1132
+ setCurrentQualityIdx(idx);
296
1133
  },
297
1134
  onStateChange: (state) => {
298
- setCurrentState(state);
1135
+ setPlayerState(state);
299
1136
  onStateChange?.(state);
300
1137
  },
301
1138
  });
@@ -309,75 +1146,274 @@ const GuardVideoPlayerComponent = forwardRef((props, ref) => {
309
1146
  const video = videoRef.current;
310
1147
  if (!video)
311
1148
  return;
312
- const handleTimeUpdate = () => {
313
- if (onTimeUpdate) {
314
- onTimeUpdate(video.currentTime);
1149
+ const onTimeUpdate = () => {
1150
+ setCurrentTime(video.currentTime);
1151
+ onTimeUpdateProp?.(video.currentTime);
1152
+ };
1153
+ const onDuration = () => setDuration(video.duration || 0);
1154
+ const onProgress = () => {
1155
+ if (video.buffered.length > 0) {
1156
+ setBuffered(video.buffered.end(video.buffered.length - 1));
315
1157
  }
316
1158
  };
317
- const handleEnded = () => {
1159
+ const onVolumeChange = () => {
1160
+ setVolume(video.volume);
1161
+ setMuted(video.muted);
1162
+ };
1163
+ const onEnded_ = () => {
318
1164
  onEnded?.();
1165
+ setShowControls(true);
319
1166
  };
320
- video.addEventListener('timeupdate', handleTimeUpdate);
321
- video.addEventListener('ended', handleEnded);
1167
+ const onRateChange = () => setPlaybackRate(video.playbackRate);
1168
+ video.addEventListener('timeupdate', onTimeUpdate);
1169
+ video.addEventListener('loadedmetadata', onDuration);
1170
+ video.addEventListener('durationchange', onDuration);
1171
+ video.addEventListener('progress', onProgress);
1172
+ video.addEventListener('volumechange', onVolumeChange);
1173
+ video.addEventListener('ended', onEnded_);
1174
+ video.addEventListener('ratechange', onRateChange);
322
1175
  return () => {
323
- video.removeEventListener('timeupdate', handleTimeUpdate);
324
- video.removeEventListener('ended', handleEnded);
1176
+ video.removeEventListener('timeupdate', onTimeUpdate);
1177
+ video.removeEventListener('loadedmetadata', onDuration);
1178
+ video.removeEventListener('durationchange', onDuration);
1179
+ video.removeEventListener('progress', onProgress);
1180
+ video.removeEventListener('volumechange', onVolumeChange);
1181
+ video.removeEventListener('ended', onEnded_);
1182
+ video.removeEventListener('ratechange', onRateChange);
1183
+ };
1184
+ }, [onEnded, onTimeUpdateProp]);
1185
+ useEffect(() => {
1186
+ if (!forensicWatermark)
1187
+ return;
1188
+ const t = setTimeout(() => {
1189
+ const email = viewerEmail || viewerName || '';
1190
+ if (email)
1191
+ setWatermarkText(email);
1192
+ }, 1500);
1193
+ return () => clearTimeout(t);
1194
+ }, [forensicWatermark, viewerEmail, viewerName]);
1195
+ const resetHideTimer = useCallback(() => {
1196
+ setShowControls(true);
1197
+ if (hideTimer.current)
1198
+ clearTimeout(hideTimer.current);
1199
+ hideTimer.current = setTimeout(() => {
1200
+ if (playerState === PlayerState.PLAYING)
1201
+ setShowControls(false);
1202
+ }, 2800);
1203
+ }, [playerState]);
1204
+ useEffect(() => {
1205
+ if (playerState !== PlayerState.PLAYING) {
1206
+ setShowControls(true);
1207
+ if (hideTimer.current)
1208
+ clearTimeout(hideTimer.current);
1209
+ }
1210
+ else {
1211
+ resetHideTimer();
1212
+ }
1213
+ return () => { if (hideTimer.current)
1214
+ clearTimeout(hideTimer.current); };
1215
+ }, [playerState, resetHideTimer]);
1216
+ useEffect(() => {
1217
+ const onFsChange = () => setIsFullscreen(!!document.fullscreenElement);
1218
+ document.addEventListener('fullscreenchange', onFsChange);
1219
+ return () => document.removeEventListener('fullscreenchange', onFsChange);
1220
+ }, []);
1221
+ useEffect(() => {
1222
+ const onKey = (e) => {
1223
+ if (!containerRef.current?.contains(document.activeElement) &&
1224
+ document.activeElement !== containerRef.current)
1225
+ return;
1226
+ switch (e.code) {
1227
+ case 'Space':
1228
+ case 'KeyK':
1229
+ e.preventDefault();
1230
+ togglePlay();
1231
+ break;
1232
+ case 'ArrowLeft':
1233
+ e.preventDefault();
1234
+ playerRef.current?.seek(Math.max(0, (videoRef.current?.currentTime || 0) - 5));
1235
+ break;
1236
+ case 'ArrowRight':
1237
+ e.preventDefault();
1238
+ playerRef.current?.seek(Math.min(duration, (videoRef.current?.currentTime || 0) + 5));
1239
+ break;
1240
+ case 'ArrowUp':
1241
+ e.preventDefault();
1242
+ setVolume_(Math.min(1, volume + 0.1));
1243
+ break;
1244
+ case 'ArrowDown':
1245
+ e.preventDefault();
1246
+ setVolume_(Math.max(0, volume - 0.1));
1247
+ break;
1248
+ case 'KeyM':
1249
+ e.preventDefault();
1250
+ toggleMute();
1251
+ break;
1252
+ case 'KeyF':
1253
+ e.preventDefault();
1254
+ toggleFullscreen();
1255
+ break;
1256
+ }
325
1257
  };
326
- }, [onTimeUpdate, onEnded]);
1258
+ document.addEventListener('keydown', onKey);
1259
+ return () => document.removeEventListener('keydown', onKey);
1260
+ }, [duration, volume]);
327
1261
  useImperativeHandle(ref, () => ({
328
1262
  play: () => playerRef.current?.play() || Promise.resolve(),
329
1263
  pause: () => playerRef.current?.pause(),
330
1264
  getCurrentTime: () => playerRef.current?.getCurrentTime() || 0,
331
- seek: (time) => playerRef.current?.seek(time),
1265
+ seek: (t) => playerRef.current?.seek(t),
332
1266
  getDuration: () => playerRef.current?.getDuration() || 0,
333
1267
  getVolume: () => playerRef.current?.getVolume() || 1,
334
- setVolume: (volume) => playerRef.current?.setVolume(volume),
1268
+ setVolume: (v) => playerRef.current?.setVolume(v),
335
1269
  getQualityLevels: () => playerRef.current?.getQualityLevels() || [],
336
1270
  getCurrentQuality: () => playerRef.current?.getCurrentQuality() || null,
337
- setQuality: (levelIndex) => playerRef.current?.setQuality(levelIndex),
1271
+ setQuality: (i) => playerRef.current?.setQuality(i),
338
1272
  getState: () => playerRef.current?.getState() || PlayerState.IDLE,
339
1273
  destroy: () => playerRef.current?.destroy(),
340
1274
  getVideoElement: () => videoRef.current,
341
1275
  }));
342
- const containerStyle = {
343
- width,
344
- height,
345
- position: 'relative',
346
- backgroundColor: '#000',
347
- ...style,
1276
+ const togglePlay = useCallback(() => {
1277
+ const video = videoRef.current;
1278
+ if (!video)
1279
+ return;
1280
+ if (video.paused || video.ended) {
1281
+ playerRef.current?.play().catch(() => { });
1282
+ }
1283
+ else {
1284
+ playerRef.current?.pause();
1285
+ }
1286
+ resetHideTimer();
1287
+ }, [resetHideTimer]);
1288
+ const setVolume_ = useCallback((v) => {
1289
+ if (!videoRef.current)
1290
+ return;
1291
+ videoRef.current.volume = v;
1292
+ videoRef.current.muted = v === 0;
1293
+ }, []);
1294
+ const toggleMute = useCallback(() => {
1295
+ if (!videoRef.current)
1296
+ return;
1297
+ videoRef.current.muted = !videoRef.current.muted;
1298
+ }, []);
1299
+ const toggleFullscreen = useCallback(() => {
1300
+ const el = containerRef.current;
1301
+ if (!el)
1302
+ return;
1303
+ if (document.fullscreenElement) {
1304
+ document.exitFullscreen().catch(() => { });
1305
+ }
1306
+ else {
1307
+ el.requestFullscreen().catch(() => { });
1308
+ }
1309
+ }, []);
1310
+ const getSeekedTime = (e) => {
1311
+ const rect = seekRef.current.getBoundingClientRect();
1312
+ const clientX = 'touches' in e ? e.touches[0].clientX : e.clientX;
1313
+ const pct = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
1314
+ return pct * duration;
1315
+ };
1316
+ const onSeekClick = (e) => {
1317
+ const t = getSeekedTime(e);
1318
+ playerRef.current?.seek(t);
1319
+ resetHideTimer();
348
1320
  };
349
- const videoStyle = {
350
- width: '100%',
351
- height: '100%',
352
- objectFit: 'contain',
1321
+ const onSeekMouseMove = (e) => {
1322
+ const rect = seekRef.current.getBoundingClientRect();
1323
+ const pct = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
1324
+ setSeekTooltip({ pct, time: formatTime(pct * duration) });
1325
+ };
1326
+ const onSeekMouseLeave = () => setSeekTooltip(null);
1327
+ const addRipple = (e) => {
1328
+ const el = containerRef.current;
1329
+ if (!el)
1330
+ return;
1331
+ const rect = el.getBoundingClientRect();
1332
+ const d = document.createElement('div');
1333
+ d.className = 'gvp-ripple';
1334
+ const size = 60;
1335
+ d.style.cssText = `width:${size}px;height:${size}px;left:${e.clientX - rect.left - size / 2}px;top:${e.clientY - rect.top - size / 2}px`;
1336
+ el.appendChild(d);
1337
+ setTimeout(() => d.remove(), 600);
353
1338
  };
354
- return (React.createElement("div", { style: containerStyle, className: className },
355
- React.createElement("video", { ref: videoRef, style: videoStyle, playsInline: true, preload: "metadata" }, "Your browser does not support the video tag."),
356
- currentState === PlayerState.LOADING && (React.createElement("div", { style: {
357
- position: 'absolute',
358
- top: '50%',
359
- left: '50%',
360
- transform: 'translate(-50%, -50%)',
361
- color: 'white',
362
- fontSize: '14px',
363
- } }, "Loading video...")),
364
- error && (React.createElement("div", { style: {
365
- position: 'absolute',
366
- top: '50%',
367
- left: '50%',
368
- transform: 'translate(-50%, -50%)',
369
- color: 'white',
370
- backgroundColor: 'rgba(255, 0, 0, 0.8)',
371
- padding: '10px 20px',
372
- borderRadius: '4px',
373
- fontSize: '14px',
374
- textAlign: 'center',
375
- maxWidth: '80%',
376
- } },
377
- React.createElement("div", { style: { fontWeight: 'bold', marginBottom: '5px' } },
378
- "Error: ",
379
- error.code),
380
- React.createElement("div", null, error.message)))));
1339
+ const progressPct = duration > 0 ? (currentTime / duration) * 100 : 0;
1340
+ const bufferedPct = duration > 0 ? (buffered / duration) * 100 : 0;
1341
+ const isLoading = playerState === PlayerState.LOADING || playerState === PlayerState.BUFFERING;
1342
+ const isIdle = playerState === PlayerState.IDLE;
1343
+ const isPlaying = playerState === PlayerState.PLAYING;
1344
+ const isEnded = videoRef.current?.ended ?? false;
1345
+ const controlsVisible = showControls || !isPlaying;
1346
+ const SPEEDS = [0.5, 0.75, 1, 1.25, 1.5, 2];
1347
+ return (React.createElement("div", { ref: containerRef, className: `gvp-root${className ? ` ${className}` : ''}`, style: { width, height, ...style }, tabIndex: 0, onMouseMove: resetHideTimer, onMouseLeave: () => isPlaying && setShowControls(false), onClick: () => setShowMenu(null) },
1348
+ React.createElement("video", { ref: videoRef, className: "gvp-video", playsInline: true, preload: "metadata" }),
1349
+ React.createElement("div", { className: `gvp-badge${controlsVisible ? '' : ' gvp-badge-hidden'}` },
1350
+ React.createElement(ShieldIcon, { color: accentColor }),
1351
+ brandName),
1352
+ forensicWatermark && watermarkText && (React.createElement("div", { className: "gvp-watermark" }, Array.from({ length: 20 }).map((_, i) => (React.createElement("span", { key: i, className: "gvp-watermark-text", style: {
1353
+ left: `${(i % 4) * 26 + ((Math.floor(i / 4)) % 2) * 13}%`,
1354
+ top: `${Math.floor(i / 4) * 22}%`,
1355
+ } }, watermarkText))))),
1356
+ isLoading && (React.createElement("div", { className: "gvp-spinner" },
1357
+ React.createElement("div", { className: "gvp-spinner-ring" }))),
1358
+ error && (React.createElement("div", { className: "gvp-error" },
1359
+ React.createElement("div", { className: "gvp-error-icon" }, "\u26A0\uFE0F"),
1360
+ React.createElement("div", { className: "gvp-error-code" }, error.code),
1361
+ React.createElement("div", { className: "gvp-error-msg" }, error.message))),
1362
+ (isIdle || isEnded) && !error && !isLoading && (React.createElement("div", { className: "gvp-center-play", onClick: togglePlay },
1363
+ React.createElement("div", { className: "gvp-center-play-btn" }, isEnded ? React.createElement(ReplayIcon, null) : React.createElement(PlayIcon, null)))),
1364
+ !isIdle && !error && (React.createElement("div", { className: "gvp-click-area", onClick: (e) => { addRipple(e); togglePlay(); } })),
1365
+ !error && (React.createElement("div", { className: `gvp-controls${controlsVisible ? '' : ' gvp-controls-hidden'}` },
1366
+ React.createElement("div", { className: "gvp-seek-row" },
1367
+ React.createElement("div", { ref: seekRef, className: "gvp-seek-wrap", onClick: onSeekClick, onMouseMove: onSeekMouseMove, onMouseLeave: onSeekMouseLeave },
1368
+ React.createElement("div", { className: "gvp-seek-track" },
1369
+ React.createElement("div", { className: "gvp-seek-buffered", style: { width: `${bufferedPct}%` } }),
1370
+ React.createElement("div", { className: "gvp-seek-progress", style: { width: `${progressPct}%` } })),
1371
+ React.createElement("div", { className: "gvp-seek-thumb", style: { left: `${progressPct}%` } }),
1372
+ seekTooltip && (React.createElement("div", { className: "gvp-seek-tooltip", style: { left: `${seekTooltip.pct * 100}%` } }, seekTooltip.time)))),
1373
+ React.createElement("div", { className: "gvp-btn-row" },
1374
+ React.createElement("button", { className: "gvp-btn", onClick: togglePlay, title: isPlaying ? 'Pause (k)' : 'Play (k)' }, isEnded ? React.createElement(ReplayIcon, null) : isPlaying ? React.createElement(PauseIcon, null) : React.createElement(PlayIcon, null)),
1375
+ React.createElement("div", { className: "gvp-volume-wrap" },
1376
+ React.createElement("button", { className: "gvp-btn", onClick: toggleMute, title: "Mute (m)" }, muted || volume === 0 ? React.createElement(VolumeMuteIcon, null) : React.createElement(VolumeHighIcon, null)),
1377
+ React.createElement("input", { type: "range", className: "gvp-volume-slider", min: 0, max: 1, step: 0.02, value: muted ? 0 : volume, onChange: (e) => setVolume_(parseFloat(e.target.value)), title: "Volume" })),
1378
+ React.createElement("span", { className: "gvp-time" },
1379
+ formatTime(currentTime),
1380
+ "\u00A0",
1381
+ React.createElement("span", { style: { opacity: 0.45 } }, "/"),
1382
+ "\u00A0",
1383
+ formatTime(duration)),
1384
+ React.createElement("div", { className: "gvp-spacer" }),
1385
+ React.createElement("div", { className: "gvp-menu-wrap" },
1386
+ React.createElement("span", { className: "gvp-rate-label", title: "Playback speed", onClick: (e) => { e.stopPropagation(); setShowMenu(showMenu === 'speed' ? null : 'speed'); } }, playbackRate === 1 ? '1×' : `${playbackRate}×`),
1387
+ showMenu === 'speed' && (React.createElement("div", { className: "gvp-menu", onClick: (e) => e.stopPropagation() },
1388
+ React.createElement("div", { className: "gvp-menu-title" }, "Speed"),
1389
+ SPEEDS.map((r) => (React.createElement("div", { key: r, className: `gvp-menu-item${playbackRate === r ? ' gvp-menu-item-active' : ''}`, onClick: () => {
1390
+ if (videoRef.current)
1391
+ videoRef.current.playbackRate = r;
1392
+ setShowMenu(null);
1393
+ } },
1394
+ r === 1 ? 'Normal' : `${r}×`,
1395
+ playbackRate === r && React.createElement("span", { className: "gvp-menu-check" }, "\u2713"))))))),
1396
+ qualityLevels.length > 0 && (React.createElement("div", { className: "gvp-menu-wrap" },
1397
+ React.createElement("button", { className: "gvp-btn", title: "Quality settings", onClick: (e) => { e.stopPropagation(); setShowMenu(showMenu === 'quality' ? null : 'quality'); } },
1398
+ React.createElement(SettingsIcon, null)),
1399
+ showMenu === 'quality' && (React.createElement("div", { className: "gvp-menu", onClick: (e) => e.stopPropagation() },
1400
+ React.createElement("div", { className: "gvp-menu-title" }, "Quality"),
1401
+ React.createElement("div", { className: `gvp-menu-item${currentQualityIdx === -1 ? ' gvp-menu-item-active' : ''}`, onClick: () => {
1402
+ playerRef.current?.setQuality(-1);
1403
+ setCurrentQualityIdx(-1);
1404
+ setShowMenu(null);
1405
+ } },
1406
+ "Auto",
1407
+ currentQualityIdx === -1 && React.createElement("span", { className: "gvp-menu-check" }, "\u2713")),
1408
+ React.createElement("div", { className: "gvp-menu-sep" }),
1409
+ [...qualityLevels].reverse().map((q) => (React.createElement("div", { key: q.index, className: `gvp-menu-item${currentQualityIdx === q.index ? ' gvp-menu-item-active' : ''}`, onClick: () => {
1410
+ playerRef.current?.setQuality(q.index);
1411
+ setCurrentQualityIdx(q.index);
1412
+ setShowMenu(null);
1413
+ } },
1414
+ q.name,
1415
+ currentQualityIdx === q.index && React.createElement("span", { className: "gvp-menu-check" }, "\u2713")))))))),
1416
+ React.createElement("button", { className: "gvp-btn", onClick: toggleFullscreen, title: "Fullscreen (f)" }, isFullscreen ? React.createElement(ExitFullscreenIcon, null) : React.createElement(FullscreenIcon, null)))))));
381
1417
  });
382
1418
  GuardVideoPlayerComponent.displayName = 'GuardVideoPlayer';
383
1419