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