@motionmesh/player 1.0.1
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/README.md +30 -0
- package/dist/index-BMmYcKXX.d.cts +13 -0
- package/dist/index-BMmYcKXX.d.ts +13 -0
- package/dist/index.cjs +77 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +77 -0
- package/dist/react/index.cjs +76 -0
- package/dist/react/index.d.cts +2 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +76 -0
- package/dist/server/index.cjs +2 -0
- package/dist/server/index.d.cts +6 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +2 -0
- package/package.json +121 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @motionmesh/player
|
|
2
|
+
|
|
3
|
+
A drop-in React video player built on Vidstack, natively optimized for Motionmesh's HLS streams and ABR (Adaptive Bitrate) delivery.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @motionmesh/player
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
import { MotionmeshPlayer } from "@motionmesh/player/react";
|
|
15
|
+
|
|
16
|
+
export default function VideoPage() {
|
|
17
|
+
// Pass the signed playback URL obtained from the Motionmesh SDK
|
|
18
|
+
return (
|
|
19
|
+
<div style={{ maxWidth: '800px', margin: '0 auto' }}>
|
|
20
|
+
<MotionmeshPlayer src="https://api.motionmesh.com/v1/videos/vid_123/hls/master.m3u8" />
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The player automatically handles resolution switching based on bandwidth, chapter markers, and caption tracks provided by the Motionmesh pipeline.
|
|
27
|
+
|
|
28
|
+
## Documentation
|
|
29
|
+
|
|
30
|
+
For full configuration options and styling details, visit the [Motionmesh Documentation](https://motionmesh.com/docs) and the [main repository](https://github.com/sanjeev0303/motionmesh).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
type MotionmeshPlayerProps = {
|
|
4
|
+
videoTrackingId: string;
|
|
5
|
+
autoPlay?: boolean;
|
|
6
|
+
playsInline?: boolean;
|
|
7
|
+
onReady?: () => void;
|
|
8
|
+
onError?: () => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
declare function MotionmeshPlayer({ videoTrackingId, autoPlay, playsInline, onReady, onError, }: MotionmeshPlayerProps): react.JSX.Element;
|
|
12
|
+
|
|
13
|
+
export { MotionmeshPlayer as M, type MotionmeshPlayerProps as a };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
type MotionmeshPlayerProps = {
|
|
4
|
+
videoTrackingId: string;
|
|
5
|
+
autoPlay?: boolean;
|
|
6
|
+
playsInline?: boolean;
|
|
7
|
+
onReady?: () => void;
|
|
8
|
+
onError?: () => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
declare function MotionmeshPlayer({ videoTrackingId, autoPlay, playsInline, onReady, onError, }: MotionmeshPlayerProps): react.JSX.Element;
|
|
12
|
+
|
|
13
|
+
export { MotionmeshPlayer as M, type MotionmeshPlayerProps as a };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';var react=require('react'),react$1=require('@vidstack/react'),_default=require('@vidstack/react/player/layouts/default');require('@vidstack/react/player/styles/default/theme.css'),require('@vidstack/react/player/styles/default/layouts/video.css');var jsxRuntime=require('react/jsx-runtime');function A(){return jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-icon lucide-play",children:jsxRuntime.jsx("path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"})})}function D(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-pause-icon lucide-pause",children:[jsxRuntime.jsx("rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}),jsxRuntime.jsx("rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"})]})}function J(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-icon lucide-captions",children:[jsxRuntime.jsx("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M7 15h4M15 15h2M7 11h2M13 11h4"})]})}function q(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-off-icon lucide-captions-off",children:[jsxRuntime.jsx("path",{d:"M10.5 5H19a2 2 0 0 1 2 2v8.5"}),jsxRuntime.jsx("path",{d:"M17 11h-.5"}),jsxRuntime.jsx("path",{d:"M19 19H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"}),jsxRuntime.jsx("path",{d:"M7 11h4"}),jsxRuntime.jsx("path",{d:"M7 15h2.5"})]})}function K(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture2-icon lucide-picture-in-picture-2",children:[jsxRuntime.jsx("path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4"}),jsxRuntime.jsx("rect",{width:"10",height:"7",x:"12",y:"13",rx:"2"})]})}function G(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture-icon lucide-picture-in-picture",children:[jsxRuntime.jsx("path",{d:"M2 10h6V4"}),jsxRuntime.jsx("path",{d:"m2 4 6 6"}),jsxRuntime.jsx("path",{d:"M21 10V7a2 2 0 0 0-2-2h-7"}),jsxRuntime.jsx("path",{d:"M3 14v2a2 2 0 0 0 2 2h3"}),jsxRuntime.jsx("rect",{x:"12",y:"14",width:"10",height:"7",rx:"1"})]})}function Z(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-settings-icon lucide-settings",children:[jsxRuntime.jsx("path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Q(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-forward-icon lucide-skip-forward",children:[jsxRuntime.jsx("path",{d:"M21 4v16"}),jsxRuntime.jsx("path",{d:"M6.029 4.285A2 2 0 0 0 3 6v12a2 2 0 0 0 3.029 1.715l9.997-5.998a2 2 0 0 0 .003-3.432z"})]})}function X(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-back-icon lucide-skip-back",children:[jsxRuntime.jsx("path",{d:"M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z"}),jsxRuntime.jsx("path",{d:"M3 20V4"})]})}function Y(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-maximize-icon lucide-maximize",children:[jsxRuntime.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),jsxRuntime.jsx("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),jsxRuntime.jsx("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),jsxRuntime.jsx("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]})}function tt(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-minimize-icon lucide-minimize",children:[jsxRuntime.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),jsxRuntime.jsx("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),jsxRuntime.jsx("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),jsxRuntime.jsx("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function et(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume-off-icon lucide-volume-off",children:[jsxRuntime.jsx("path",{d:"M16 9a5 5 0 0 1 .95 2.293"}),jsxRuntime.jsx("path",{d:"M19.364 5.636a9 9 0 0 1 1.889 9.96"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"}),jsxRuntime.jsx("path",{d:"m7 7-.587.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298V11"}),jsxRuntime.jsx("path",{d:"M9.828 4.172A.686.686 0 0 1 11 4.657v.686"})]})}function V(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume2-icon lucide-volume-2",children:[jsxRuntime.jsx("path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}),jsxRuntime.jsx("path",{d:"M16 9a5 5 0 0 1 0 6"}),jsxRuntime.jsx("path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"})]})}function N(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-off-icon lucide-play-off",children:[jsxRuntime.jsx("path",{d:"m10.215 4.56 9.79 5.71a2 2 0 0 1 .003 3.458l-.393.23"}),jsxRuntime.jsx("path",{d:"m16.042 16.042-8.034 4.686A2 2 0 0 1 5 19V5"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"})]})}function ot(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-octagon-pause-icon lucide-octagon-pause",children:[jsxRuntime.jsx("path",{d:"M10 15V9"}),jsxRuntime.jsx("path",{d:"M14 15V9"}),jsxRuntime.jsx("path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z"})]})}function rt(e){return e?/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e):false}function nt(e){return e?!!(e.startsWith("mot_live_")||e.startsWith("mot_test_")):false}var L=null,U="vmx:user-country",yt=10080*60*1e3;async function at(){if(L)return L;if(typeof window<"u")try{let e=localStorage.getItem(U);if(e){let r=JSON.parse(e);if(r.expiresAt>Date.now())return L=r.value,L;localStorage.removeItem(U);}}catch{localStorage.removeItem(U);}try{let e=await fetch("https://ipapi.co/country/");if(!e.ok)throw new Error("Failed to fetch country");let r=(await e.text()).trim();if(L=r,typeof window<"u"){let d={value:r,expiresAt:Date.now()+yt};localStorage.setItem(U,JSON.stringify(d));}return L}catch(e){return console.error("Error fetching user country:",e),null}}function bt(){if(typeof document>"u")return;let e=document.createElement("style");e.textContent=`
|
|
2
|
+
[data-media-player][data-layout="video"] .vds-captions {
|
|
3
|
+
bottom: 1% !important;
|
|
4
|
+
transition: bottom 0.2s ease;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[data-media-player][data-layout="video"][data-hover] .vds-captions,
|
|
8
|
+
[data-media-player][data-layout="video"][data-controls] .vds-captions {
|
|
9
|
+
bottom: 8% !important;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-media-player][data-layout="video"] .vds-captions [data-part="cue"] {
|
|
13
|
+
display: inline-block;
|
|
14
|
+
background: var(--vmx-caption-bg, rgba(15, 23, 42, 0.75)) !important; /* Signal Ink */
|
|
15
|
+
color: var(--vmx-caption-color, #fff) !important;
|
|
16
|
+
font-size: var(--vmx-caption-size, 18px) !important;
|
|
17
|
+
font-weight: 500 !important;
|
|
18
|
+
line-height: 1.45 !important;
|
|
19
|
+
padding: 0.18em 0.5em !important;
|
|
20
|
+
border-radius: 4px !important;
|
|
21
|
+
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85) !important;
|
|
22
|
+
backdrop-filter: blur(8px);
|
|
23
|
+
-webkit-backdrop-filter: blur(8px);
|
|
24
|
+
box-decoration-break: clone;
|
|
25
|
+
-webkit-box-decoration-break: clone;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Player slider customization */
|
|
29
|
+
[data-media-player][data-layout="video"] {
|
|
30
|
+
--media-brand: var(--vmx-primary, #06b6d4); /* Mesh Cyan */
|
|
31
|
+
--media-slider-track-fill-bg: var(--vmx-primary, #06b6d4);
|
|
32
|
+
--media-slider-track-progress-bg: rgba(245, 158, 11, 0.35); /* Tally Amber */
|
|
33
|
+
--media-slider-track-bg: rgba(255, 255, 255, 0.18);
|
|
34
|
+
--media-slider-thumb-bg: #fff;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[data-media-player][data-layout="video"] .vds-time-slider {
|
|
38
|
+
--slider-track-height: 4px;
|
|
39
|
+
--slider-track-border-radius: 999px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[data-media-player][data-layout="video"] .vds-slider-track {
|
|
43
|
+
background: var(--media-slider-track-bg) !important;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[data-media-player][data-layout="video"] .vds-slider-track-fill {
|
|
47
|
+
background: var(--media-slider-track-bg) !important;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
[data-media-player][data-layout="video"] .vds-slider-track-progress {
|
|
51
|
+
background: var(--media-slider-track-progress-bg) !important;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-progress{
|
|
55
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-chapter .vds-slider-progress{
|
|
59
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@keyframes motionmesh-spin {
|
|
63
|
+
to { transform: rotate(360deg); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.motionmesh-loader {
|
|
67
|
+
width: 40px;
|
|
68
|
+
height: 40px;
|
|
69
|
+
border: 3px solid rgba(225, 29, 72, 0.2);
|
|
70
|
+
border-top-color: var(--vmx-primary, #3b82f6);
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
animation: motionmesh-spin 0.8s linear infinite;
|
|
73
|
+
}
|
|
74
|
+
`,document.head.appendChild(e);}var ct={..._default.defaultLayoutIcons,PlayButton:{Play:A,Pause:D,Replay:A},MuteButton:{Mute:et,VolumeHigh:V,VolumeLow:V},FullscreenButton:{Enter:Y,Exit:tt},SeekButton:{Backward:X,Forward:Q},Menu:{..._default.defaultLayoutIcons.Menu,Settings:Z},PIPButton:{Enter:K,Exit:G},CaptionButton:{On:J,Off:q}};function Mt(e){try{let r=new URL(e),d=r.searchParams.get("token"),u=r.searchParams.get("expires"),n=r.searchParams.get("token_path");if(d&&u&&n)return `token=${encodeURIComponent(d)}&expires=${encodeURIComponent(u)}&token_path=${encodeURIComponent(n)}`}catch{}return ""}function Lt(e,r){let[d,u]=react.useState(null);return react.useEffect(()=>{if(!e)return;let n=null,s=false;async function a(){let y=await fetch(e);if(!y.ok)throw new Error("Failed to load thumbnail vtt");let g=await y.text(),v=new URL(e),P=g.replace(/^(?!WEBVTT|NOTE|\s*$|\d{2}:\d{2}:\d{2})\s*(.+)$/gm,m=>{let[c,p=""]=m.trim().split("#"),h=new URL(c,v);return new URLSearchParams(r).forEach((x,b)=>h.searchParams.set(b,x)),`${h.toString()}${p?`#${p}`:""}`});n=URL.createObjectURL(new Blob([P],{type:"text/vtt"})),s||u(n);}return a().catch(console.error),()=>{s=true,n&&URL.revokeObjectURL(n);}},[e,r]),d}function Pt(e){return `WEBVTT
|
|
75
|
+
|
|
76
|
+
`+e.replace(/\r+/g,"").replace(/^\d+\n/gm,"").replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g,"$1.$2")}function It(e){let[r,d]=react.useState(null);return react.useEffect(()=>{if(!e)return;let u=false,n=null;async function s(){let a=await fetch(e);if(!a.ok)throw new Error("Failed to load subtitles");let y=await a.text(),g=Pt(y),v=new Blob([g],{type:"text/vtt"});n=URL.createObjectURL(v),u||d(n);}return s().catch(console.error),()=>{u=true,n&&URL.revokeObjectURL(n);}},[e]),r}function Ct({videoTrackingId:e,autoPlay:r,playsInline:d,onReady:u,onError:n}){let s=react.useRef(null),[a,y]=react.useState(),[g,v]=react.useState(false),[P,m]=react.useState(null),c=react.useRef(false),p=react.useRef(false),h=react.useRef(0),w="vmx_view_",x=720*60*60*1e3;react.useEffect(()=>{async function o(){try{let i=await at();m(i);}catch(i){console.error("Failed to initialize user country:",i);}}o();},[]),react.useEffect(()=>{if(c.current=false,p.current=false,!!e)try{let o=`${w}${e}`,i=localStorage.getItem(o);if(!i){c.current=!0;return}let f=Number(i);if(!Number.isFinite(f)){localStorage.removeItem(o),c.current=!0;return}Date.now()-f>=x&&(localStorage.removeItem(o),c.current=!0);}catch{c.current=false;}},[e]);let b=async()=>{if(!g){v(true);try{let o=await fetch(`/api/motionmesh/player?videoTrackingId=${e}`,{method:"POST",headers:{Accept:"application/json"}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let i=await o.json();y(i);}catch(o){console.error(o);}finally{v(false);}}};react.useEffect(()=>{bt(),e&&b();},[e]);let k=a?.playerSettings??{},j=k?.primaryColor??"#06b6d4",E=k?.fontFamily,O=k?.captions?.fontColor??"#ffffff",_=k?.captions?.backgroundColor??"rgba(15, 23, 42, 0.75)",B=Number(k?.captions?.fontSize??"18"),T=k?.playButton?.present,ut=react.useMemo(()=>{let o={"--vmx-primary":j,"--vmx-caption-color":O,"--vmx-caption-bg":_,"--vmx-caption-size":`${Number.isFinite(B)?B:18}px`};return typeof E=="string"&&E.trim()&&(o.fontFamily=E),o},[j,O,_,B,E]),pt=react.useMemo(()=>T==="minimal"?_default.defaultLayoutIcons:T==="block"?{...ct,PlayButton:{Play:N,Pause:ot,Replay:N}}:ct,[T]),I=async(o,i)=>{if(a?.analyticsToken)try{if(await fetch("/api/motionmesh/player?kind=event",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({event:o,currentTime:i,token:a.analyticsToken,geo:P||void 0,isUnique:c.current&&!p.current&&i>=3})}),c.current&&!p.current&&i>=3){p.current=!0;try{let f=`${w}${e}`;localStorage.setItem(f,Date.now().toString());}catch{}}}catch(f){console.error("Failed to send analytics event",f);}},F=a?.playlistUrl||"",W=Mt(F),ht=a?.subtitleUrl||void 0,z=It(ht),mt=a?.timelineSpritesUrl||"",ft=Lt(mt,W),gt=a?.vtt&&URL.createObjectURL(new Blob([a?.vtt],{type:"text/vtt"}));return g&&!a?jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center w-full h-full bg-black text-white gap-4",children:jsxRuntime.jsx("div",{className:"motionmesh-loader"})}):!a&&!g?jsxRuntime.jsx("div",{className:"flex items-center justify-center w-full h-full bg-black text-white",children:"Error loading video."}):jsxRuntime.jsxs(react$1.MediaPlayer,{ref:s,title:"Motionmesh Player",playsInline:d??true,autoPlay:r??false,src:F,style:ut,onCanPlay:u,onError:n,onPlay:()=>{let o=s?.current?.currentTime||0;I("play",o),h.current=o;},onPause:()=>{I("pause",s.current?.currentTime||0);},onEnded:()=>{I("ended",s.current?.currentTime||0);},onSeeked:()=>{I("seek",s.current?.currentTime||0);},onTimeUpdate:o=>{let i=o.currentTime;i-h.current>=15&&(I("heartbeat",i),h.current=i);},onProviderChange:o=>{o?.type==="hls"&&(o.config={abrEwmaDefaultEstimate:5e6,startLevel:-1,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetry:2,maxMaxBufferLength:30,progressive:true,xhrSetup:(i,f)=>{if(!f.includes("token=")){let H=f?.includes("?")?"&":"?";i.open("GET",`${f}${H}${W}`,true);}}});},children:[jsxRuntime.jsxs(react$1.MediaProvider,{children:[jsxRuntime.jsx(react$1.Track,{src:gt,kind:"chapters",label:"Chapters",default:true}),z&&jsxRuntime.jsx(react$1.Track,{src:z,kind:"subtitles",label:"English",lang:"en",default:true}),jsxRuntime.jsx(react$1.Captions,{className:"vds-captions"})]}),jsxRuntime.jsx(_default.DefaultVideoLayout,{thumbnails:ft,icons:pt,slots:{googleCastButton:null,chaptersMenu:null}})]})}var dt=()=>({baseUrl:process.env.MOTIONMESH_BASE_URL||"https://motionmesh.co.in/api/v1"});async function St({request:e,apiKey:r}){try{if(!r)return Response.json({error:"Motionmesh apiKey is required"},{status:401});if(!(rt(r)||nt(r)))return Response.json({error:"Invalid API Key"},{status:401});let n={Authorization:`Bearer ${r}`},{baseUrl:s}=dt(),{searchParams:a}=new URL(e.url),y=a.get("kind");if(y==="settings"){if((a.get("action")??"get")==="update"){let h=await e.json().catch(()=>null);if(!h||typeof h!="object")return Response.json({error:"Invalid settings payload"},{status:400});let w=await fetch(`${s}/player/settings`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...n},body:JSON.stringify(h)}),x=await w.json().catch(()=>null);return Response.json(x??{error:"Upstream error"},{status:w.status})}let c=await fetch(`${s}/player/settings`,{headers:{Accept:"application/json",...n}}),p=await c.json().catch(()=>null);return Response.json(p??{error:"Upstream error"},{status:c.status})}if(y==="event"){let m=await e.json().catch(()=>null);if(!m?.token||!m?.event||typeof m?.currentTime!="number")return Response.json({error:"token, event and currentTime are required"},{status:400});let c="",p="";try{[c,p]=atob(m.token).split(":");}catch{return Response.json({error:"invalid token"},{status:400})}let h={account_id:c,video_id:p,event_type:m.event,timestamp:new Date().toISOString(),country:m.geo||""},w=e.headers.get("user-agent")??"",x=e.headers.get("x-forwarded-for")??"";console.log("FETCHING:",`${s}/analytics/collect`);let b=await fetch(`${s}/analytics/collect`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...n,"user-agent":w,"x-forwarded-for":x},body:JSON.stringify(h)}),k=await b.json().catch(()=>null);return Response.json(k??{success:b.ok},{status:b.status})}let g=a.get("videoTrackingId");if(!g)return Response.json({error:"videoTrackingId is required"},{status:400});let v=await fetch(`${s}/videos/${g}/playback`,{headers:n}),P=await v.json().catch(()=>null);return Response.json(P??{error:"Upstream error"},{status:v.status})}catch(d){let u=d?.message||"An unexpected error occurred";return Response.json({error:u},{status:500})}}
|
|
77
|
+
exports.MotionmeshPlayer=Ct;exports.handleProcessRequest=St;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {useRef,useState,useEffect,useMemo}from'react';import {MediaPlayer,MediaProvider,Track,Captions}from'@vidstack/react';import {defaultLayoutIcons,DefaultVideoLayout}from'@vidstack/react/player/layouts/default';import'@vidstack/react/player/styles/default/theme.css';import'@vidstack/react/player/styles/default/layouts/video.css';import {jsx,jsxs}from'react/jsx-runtime';function A(){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-icon lucide-play",children:jsx("path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"})})}function D(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-pause-icon lucide-pause",children:[jsx("rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}),jsx("rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"})]})}function J(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-icon lucide-captions",children:[jsx("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2"}),jsx("path",{d:"M7 15h4M15 15h2M7 11h2M13 11h4"})]})}function q(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-off-icon lucide-captions-off",children:[jsx("path",{d:"M10.5 5H19a2 2 0 0 1 2 2v8.5"}),jsx("path",{d:"M17 11h-.5"}),jsx("path",{d:"M19 19H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2"}),jsx("path",{d:"m2 2 20 20"}),jsx("path",{d:"M7 11h4"}),jsx("path",{d:"M7 15h2.5"})]})}function K(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture2-icon lucide-picture-in-picture-2",children:[jsx("path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4"}),jsx("rect",{width:"10",height:"7",x:"12",y:"13",rx:"2"})]})}function G(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture-icon lucide-picture-in-picture",children:[jsx("path",{d:"M2 10h6V4"}),jsx("path",{d:"m2 4 6 6"}),jsx("path",{d:"M21 10V7a2 2 0 0 0-2-2h-7"}),jsx("path",{d:"M3 14v2a2 2 0 0 0 2 2h3"}),jsx("rect",{x:"12",y:"14",width:"10",height:"7",rx:"1"})]})}function Z(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-settings-icon lucide-settings",children:[jsx("path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}),jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Q(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-forward-icon lucide-skip-forward",children:[jsx("path",{d:"M21 4v16"}),jsx("path",{d:"M6.029 4.285A2 2 0 0 0 3 6v12a2 2 0 0 0 3.029 1.715l9.997-5.998a2 2 0 0 0 .003-3.432z"})]})}function X(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-back-icon lucide-skip-back",children:[jsx("path",{d:"M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z"}),jsx("path",{d:"M3 20V4"})]})}function Y(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-maximize-icon lucide-maximize",children:[jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),jsx("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),jsx("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),jsx("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]})}function tt(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-minimize-icon lucide-minimize",children:[jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),jsx("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),jsx("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),jsx("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function et(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume-off-icon lucide-volume-off",children:[jsx("path",{d:"M16 9a5 5 0 0 1 .95 2.293"}),jsx("path",{d:"M19.364 5.636a9 9 0 0 1 1.889 9.96"}),jsx("path",{d:"m2 2 20 20"}),jsx("path",{d:"m7 7-.587.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298V11"}),jsx("path",{d:"M9.828 4.172A.686.686 0 0 1 11 4.657v.686"})]})}function V(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume2-icon lucide-volume-2",children:[jsx("path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}),jsx("path",{d:"M16 9a5 5 0 0 1 0 6"}),jsx("path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"})]})}function N(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-off-icon lucide-play-off",children:[jsx("path",{d:"m10.215 4.56 9.79 5.71a2 2 0 0 1 .003 3.458l-.393.23"}),jsx("path",{d:"m16.042 16.042-8.034 4.686A2 2 0 0 1 5 19V5"}),jsx("path",{d:"m2 2 20 20"})]})}function ot(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-octagon-pause-icon lucide-octagon-pause",children:[jsx("path",{d:"M10 15V9"}),jsx("path",{d:"M14 15V9"}),jsx("path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z"})]})}function rt(e){return e?/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e):false}function nt(e){return e?!!(e.startsWith("mot_live_")||e.startsWith("mot_test_")):false}var L=null,U="vmx:user-country",yt=10080*60*1e3;async function at(){if(L)return L;if(typeof window<"u")try{let e=localStorage.getItem(U);if(e){let r=JSON.parse(e);if(r.expiresAt>Date.now())return L=r.value,L;localStorage.removeItem(U);}}catch{localStorage.removeItem(U);}try{let e=await fetch("https://ipapi.co/country/");if(!e.ok)throw new Error("Failed to fetch country");let r=(await e.text()).trim();if(L=r,typeof window<"u"){let d={value:r,expiresAt:Date.now()+yt};localStorage.setItem(U,JSON.stringify(d));}return L}catch(e){return console.error("Error fetching user country:",e),null}}function bt(){if(typeof document>"u")return;let e=document.createElement("style");e.textContent=`
|
|
2
|
+
[data-media-player][data-layout="video"] .vds-captions {
|
|
3
|
+
bottom: 1% !important;
|
|
4
|
+
transition: bottom 0.2s ease;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[data-media-player][data-layout="video"][data-hover] .vds-captions,
|
|
8
|
+
[data-media-player][data-layout="video"][data-controls] .vds-captions {
|
|
9
|
+
bottom: 8% !important;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-media-player][data-layout="video"] .vds-captions [data-part="cue"] {
|
|
13
|
+
display: inline-block;
|
|
14
|
+
background: var(--vmx-caption-bg, rgba(15, 23, 42, 0.75)) !important; /* Signal Ink */
|
|
15
|
+
color: var(--vmx-caption-color, #fff) !important;
|
|
16
|
+
font-size: var(--vmx-caption-size, 18px) !important;
|
|
17
|
+
font-weight: 500 !important;
|
|
18
|
+
line-height: 1.45 !important;
|
|
19
|
+
padding: 0.18em 0.5em !important;
|
|
20
|
+
border-radius: 4px !important;
|
|
21
|
+
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85) !important;
|
|
22
|
+
backdrop-filter: blur(8px);
|
|
23
|
+
-webkit-backdrop-filter: blur(8px);
|
|
24
|
+
box-decoration-break: clone;
|
|
25
|
+
-webkit-box-decoration-break: clone;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Player slider customization */
|
|
29
|
+
[data-media-player][data-layout="video"] {
|
|
30
|
+
--media-brand: var(--vmx-primary, #06b6d4); /* Mesh Cyan */
|
|
31
|
+
--media-slider-track-fill-bg: var(--vmx-primary, #06b6d4);
|
|
32
|
+
--media-slider-track-progress-bg: rgba(245, 158, 11, 0.35); /* Tally Amber */
|
|
33
|
+
--media-slider-track-bg: rgba(255, 255, 255, 0.18);
|
|
34
|
+
--media-slider-thumb-bg: #fff;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[data-media-player][data-layout="video"] .vds-time-slider {
|
|
38
|
+
--slider-track-height: 4px;
|
|
39
|
+
--slider-track-border-radius: 999px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[data-media-player][data-layout="video"] .vds-slider-track {
|
|
43
|
+
background: var(--media-slider-track-bg) !important;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[data-media-player][data-layout="video"] .vds-slider-track-fill {
|
|
47
|
+
background: var(--media-slider-track-bg) !important;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
[data-media-player][data-layout="video"] .vds-slider-track-progress {
|
|
51
|
+
background: var(--media-slider-track-progress-bg) !important;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-progress{
|
|
55
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-chapter .vds-slider-progress{
|
|
59
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@keyframes motionmesh-spin {
|
|
63
|
+
to { transform: rotate(360deg); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.motionmesh-loader {
|
|
67
|
+
width: 40px;
|
|
68
|
+
height: 40px;
|
|
69
|
+
border: 3px solid rgba(225, 29, 72, 0.2);
|
|
70
|
+
border-top-color: var(--vmx-primary, #3b82f6);
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
animation: motionmesh-spin 0.8s linear infinite;
|
|
73
|
+
}
|
|
74
|
+
`,document.head.appendChild(e);}var ct={...defaultLayoutIcons,PlayButton:{Play:A,Pause:D,Replay:A},MuteButton:{Mute:et,VolumeHigh:V,VolumeLow:V},FullscreenButton:{Enter:Y,Exit:tt},SeekButton:{Backward:X,Forward:Q},Menu:{...defaultLayoutIcons.Menu,Settings:Z},PIPButton:{Enter:K,Exit:G},CaptionButton:{On:J,Off:q}};function Mt(e){try{let r=new URL(e),d=r.searchParams.get("token"),u=r.searchParams.get("expires"),n=r.searchParams.get("token_path");if(d&&u&&n)return `token=${encodeURIComponent(d)}&expires=${encodeURIComponent(u)}&token_path=${encodeURIComponent(n)}`}catch{}return ""}function Lt(e,r){let[d,u]=useState(null);return useEffect(()=>{if(!e)return;let n=null,s=false;async function a(){let y=await fetch(e);if(!y.ok)throw new Error("Failed to load thumbnail vtt");let g=await y.text(),v=new URL(e),P=g.replace(/^(?!WEBVTT|NOTE|\s*$|\d{2}:\d{2}:\d{2})\s*(.+)$/gm,m=>{let[c,p=""]=m.trim().split("#"),h=new URL(c,v);return new URLSearchParams(r).forEach((x,b)=>h.searchParams.set(b,x)),`${h.toString()}${p?`#${p}`:""}`});n=URL.createObjectURL(new Blob([P],{type:"text/vtt"})),s||u(n);}return a().catch(console.error),()=>{s=true,n&&URL.revokeObjectURL(n);}},[e,r]),d}function Pt(e){return `WEBVTT
|
|
75
|
+
|
|
76
|
+
`+e.replace(/\r+/g,"").replace(/^\d+\n/gm,"").replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g,"$1.$2")}function It(e){let[r,d]=useState(null);return useEffect(()=>{if(!e)return;let u=false,n=null;async function s(){let a=await fetch(e);if(!a.ok)throw new Error("Failed to load subtitles");let y=await a.text(),g=Pt(y),v=new Blob([g],{type:"text/vtt"});n=URL.createObjectURL(v),u||d(n);}return s().catch(console.error),()=>{u=true,n&&URL.revokeObjectURL(n);}},[e]),r}function Ct({videoTrackingId:e,autoPlay:r,playsInline:d,onReady:u,onError:n}){let s=useRef(null),[a,y]=useState(),[g,v]=useState(false),[P,m]=useState(null),c=useRef(false),p=useRef(false),h=useRef(0),w="vmx_view_",x=720*60*60*1e3;useEffect(()=>{async function o(){try{let i=await at();m(i);}catch(i){console.error("Failed to initialize user country:",i);}}o();},[]),useEffect(()=>{if(c.current=false,p.current=false,!!e)try{let o=`${w}${e}`,i=localStorage.getItem(o);if(!i){c.current=!0;return}let f=Number(i);if(!Number.isFinite(f)){localStorage.removeItem(o),c.current=!0;return}Date.now()-f>=x&&(localStorage.removeItem(o),c.current=!0);}catch{c.current=false;}},[e]);let b=async()=>{if(!g){v(true);try{let o=await fetch(`/api/motionmesh/player?videoTrackingId=${e}`,{method:"POST",headers:{Accept:"application/json"}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let i=await o.json();y(i);}catch(o){console.error(o);}finally{v(false);}}};useEffect(()=>{bt(),e&&b();},[e]);let k=a?.playerSettings??{},j=k?.primaryColor??"#06b6d4",E=k?.fontFamily,O=k?.captions?.fontColor??"#ffffff",_=k?.captions?.backgroundColor??"rgba(15, 23, 42, 0.75)",B=Number(k?.captions?.fontSize??"18"),T=k?.playButton?.present,ut=useMemo(()=>{let o={"--vmx-primary":j,"--vmx-caption-color":O,"--vmx-caption-bg":_,"--vmx-caption-size":`${Number.isFinite(B)?B:18}px`};return typeof E=="string"&&E.trim()&&(o.fontFamily=E),o},[j,O,_,B,E]),pt=useMemo(()=>T==="minimal"?defaultLayoutIcons:T==="block"?{...ct,PlayButton:{Play:N,Pause:ot,Replay:N}}:ct,[T]),I=async(o,i)=>{if(a?.analyticsToken)try{if(await fetch("/api/motionmesh/player?kind=event",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({event:o,currentTime:i,token:a.analyticsToken,geo:P||void 0,isUnique:c.current&&!p.current&&i>=3})}),c.current&&!p.current&&i>=3){p.current=!0;try{let f=`${w}${e}`;localStorage.setItem(f,Date.now().toString());}catch{}}}catch(f){console.error("Failed to send analytics event",f);}},F=a?.playlistUrl||"",W=Mt(F),ht=a?.subtitleUrl||void 0,z=It(ht),mt=a?.timelineSpritesUrl||"",ft=Lt(mt,W),gt=a?.vtt&&URL.createObjectURL(new Blob([a?.vtt],{type:"text/vtt"}));return g&&!a?jsx("div",{className:"flex flex-col items-center justify-center w-full h-full bg-black text-white gap-4",children:jsx("div",{className:"motionmesh-loader"})}):!a&&!g?jsx("div",{className:"flex items-center justify-center w-full h-full bg-black text-white",children:"Error loading video."}):jsxs(MediaPlayer,{ref:s,title:"Motionmesh Player",playsInline:d??true,autoPlay:r??false,src:F,style:ut,onCanPlay:u,onError:n,onPlay:()=>{let o=s?.current?.currentTime||0;I("play",o),h.current=o;},onPause:()=>{I("pause",s.current?.currentTime||0);},onEnded:()=>{I("ended",s.current?.currentTime||0);},onSeeked:()=>{I("seek",s.current?.currentTime||0);},onTimeUpdate:o=>{let i=o.currentTime;i-h.current>=15&&(I("heartbeat",i),h.current=i);},onProviderChange:o=>{o?.type==="hls"&&(o.config={abrEwmaDefaultEstimate:5e6,startLevel:-1,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetry:2,maxMaxBufferLength:30,progressive:true,xhrSetup:(i,f)=>{if(!f.includes("token=")){let H=f?.includes("?")?"&":"?";i.open("GET",`${f}${H}${W}`,true);}}});},children:[jsxs(MediaProvider,{children:[jsx(Track,{src:gt,kind:"chapters",label:"Chapters",default:true}),z&&jsx(Track,{src:z,kind:"subtitles",label:"English",lang:"en",default:true}),jsx(Captions,{className:"vds-captions"})]}),jsx(DefaultVideoLayout,{thumbnails:ft,icons:pt,slots:{googleCastButton:null,chaptersMenu:null}})]})}var dt=()=>({baseUrl:process.env.MOTIONMESH_BASE_URL||"https://motionmesh.co.in/api/v1"});async function St({request:e,apiKey:r}){try{if(!r)return Response.json({error:"Motionmesh apiKey is required"},{status:401});if(!(rt(r)||nt(r)))return Response.json({error:"Invalid API Key"},{status:401});let n={Authorization:`Bearer ${r}`},{baseUrl:s}=dt(),{searchParams:a}=new URL(e.url),y=a.get("kind");if(y==="settings"){if((a.get("action")??"get")==="update"){let h=await e.json().catch(()=>null);if(!h||typeof h!="object")return Response.json({error:"Invalid settings payload"},{status:400});let w=await fetch(`${s}/player/settings`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...n},body:JSON.stringify(h)}),x=await w.json().catch(()=>null);return Response.json(x??{error:"Upstream error"},{status:w.status})}let c=await fetch(`${s}/player/settings`,{headers:{Accept:"application/json",...n}}),p=await c.json().catch(()=>null);return Response.json(p??{error:"Upstream error"},{status:c.status})}if(y==="event"){let m=await e.json().catch(()=>null);if(!m?.token||!m?.event||typeof m?.currentTime!="number")return Response.json({error:"token, event and currentTime are required"},{status:400});let c="",p="";try{[c,p]=atob(m.token).split(":");}catch{return Response.json({error:"invalid token"},{status:400})}let h={account_id:c,video_id:p,event_type:m.event,timestamp:new Date().toISOString(),country:m.geo||""},w=e.headers.get("user-agent")??"",x=e.headers.get("x-forwarded-for")??"";console.log("FETCHING:",`${s}/analytics/collect`);let b=await fetch(`${s}/analytics/collect`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...n,"user-agent":w,"x-forwarded-for":x},body:JSON.stringify(h)}),k=await b.json().catch(()=>null);return Response.json(k??{success:b.ok},{status:b.status})}let g=a.get("videoTrackingId");if(!g)return Response.json({error:"videoTrackingId is required"},{status:400});let v=await fetch(`${s}/videos/${g}/playback`,{headers:n}),P=await v.json().catch(()=>null);return Response.json(P??{error:"Upstream error"},{status:v.status})}catch(d){let u=d?.message||"An unexpected error occurred";return Response.json({error:u},{status:500})}}
|
|
77
|
+
export{Ct as MotionmeshPlayer,St as handleProcessRequest};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';var react=require('react'),react$1=require('@vidstack/react'),_default=require('@vidstack/react/player/layouts/default');require('@vidstack/react/player/styles/default/theme.css'),require('@vidstack/react/player/styles/default/layouts/video.css');var jsxRuntime=require('react/jsx-runtime');function j(){return jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-icon lucide-play",children:jsxRuntime.jsx("path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"})})}function H(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-pause-icon lucide-pause",children:[jsxRuntime.jsx("rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}),jsxRuntime.jsx("rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"})]})}function q(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-icon lucide-captions",children:[jsxRuntime.jsx("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M7 15h4M15 15h2M7 11h2M13 11h4"})]})}function J(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-off-icon lucide-captions-off",children:[jsxRuntime.jsx("path",{d:"M10.5 5H19a2 2 0 0 1 2 2v8.5"}),jsxRuntime.jsx("path",{d:"M17 11h-.5"}),jsxRuntime.jsx("path",{d:"M19 19H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"}),jsxRuntime.jsx("path",{d:"M7 11h4"}),jsxRuntime.jsx("path",{d:"M7 15h2.5"})]})}function K(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture2-icon lucide-picture-in-picture-2",children:[jsxRuntime.jsx("path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4"}),jsxRuntime.jsx("rect",{width:"10",height:"7",x:"12",y:"13",rx:"2"})]})}function Z(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture-icon lucide-picture-in-picture",children:[jsxRuntime.jsx("path",{d:"M2 10h6V4"}),jsxRuntime.jsx("path",{d:"m2 4 6 6"}),jsxRuntime.jsx("path",{d:"M21 10V7a2 2 0 0 0-2-2h-7"}),jsxRuntime.jsx("path",{d:"M3 14v2a2 2 0 0 0 2 2h3"}),jsxRuntime.jsx("rect",{x:"12",y:"14",width:"10",height:"7",rx:"1"})]})}function G(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-settings-icon lucide-settings",children:[jsxRuntime.jsx("path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Q(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-forward-icon lucide-skip-forward",children:[jsxRuntime.jsx("path",{d:"M21 4v16"}),jsxRuntime.jsx("path",{d:"M6.029 4.285A2 2 0 0 0 3 6v12a2 2 0 0 0 3.029 1.715l9.997-5.998a2 2 0 0 0 .003-3.432z"})]})}function X(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-back-icon lucide-skip-back",children:[jsxRuntime.jsx("path",{d:"M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z"}),jsxRuntime.jsx("path",{d:"M3 20V4"})]})}function Y(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-maximize-icon lucide-maximize",children:[jsxRuntime.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),jsxRuntime.jsx("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),jsxRuntime.jsx("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),jsxRuntime.jsx("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]})}function tt(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-minimize-icon lucide-minimize",children:[jsxRuntime.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),jsxRuntime.jsx("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),jsxRuntime.jsx("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),jsxRuntime.jsx("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function et(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume-off-icon lucide-volume-off",children:[jsxRuntime.jsx("path",{d:"M16 9a5 5 0 0 1 .95 2.293"}),jsxRuntime.jsx("path",{d:"M19.364 5.636a9 9 0 0 1 1.889 9.96"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"}),jsxRuntime.jsx("path",{d:"m7 7-.587.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298V11"}),jsxRuntime.jsx("path",{d:"M9.828 4.172A.686.686 0 0 1 11 4.657v.686"})]})}function R(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume2-icon lucide-volume-2",children:[jsxRuntime.jsx("path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}),jsxRuntime.jsx("path",{d:"M16 9a5 5 0 0 1 0 6"}),jsxRuntime.jsx("path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"})]})}function A(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-off-icon lucide-play-off",children:[jsxRuntime.jsx("path",{d:"m10.215 4.56 9.79 5.71a2 2 0 0 1 .003 3.458l-.393.23"}),jsxRuntime.jsx("path",{d:"m16.042 16.042-8.034 4.686A2 2 0 0 1 5 19V5"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"})]})}function ot(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-octagon-pause-icon lucide-octagon-pause",children:[jsxRuntime.jsx("path",{d:"M10 15V9"}),jsxRuntime.jsx("path",{d:"M14 15V9"}),jsxRuntime.jsx("path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z"})]})}var k=null,P="vmx:user-country",mt=10080*60*1e3;async function rt(){if(k)return k;if(typeof window<"u")try{let e=localStorage.getItem(P);if(e){let n=JSON.parse(e);if(n.expiresAt>Date.now())return k=n.value,k;localStorage.removeItem(P);}}catch{localStorage.removeItem(P);}try{let e=await fetch("https://ipapi.co/country/");if(!e.ok)throw new Error("Failed to fetch country");let n=(await e.text()).trim();if(k=n,typeof window<"u"){let l={value:n,expiresAt:Date.now()+mt};localStorage.setItem(P,JSON.stringify(l));}return k}catch(e){return console.error("Error fetching user country:",e),null}}function wt(){if(typeof document>"u")return;let e=document.createElement("style");e.textContent=`
|
|
2
|
+
[data-media-player][data-layout="video"] .vds-captions {
|
|
3
|
+
bottom: 1% !important;
|
|
4
|
+
transition: bottom 0.2s ease;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[data-media-player][data-layout="video"][data-hover] .vds-captions,
|
|
8
|
+
[data-media-player][data-layout="video"][data-controls] .vds-captions {
|
|
9
|
+
bottom: 8% !important;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-media-player][data-layout="video"] .vds-captions [data-part="cue"] {
|
|
13
|
+
display: inline-block;
|
|
14
|
+
background: var(--vmx-caption-bg, rgba(15, 23, 42, 0.75)) !important; /* Signal Ink */
|
|
15
|
+
color: var(--vmx-caption-color, #fff) !important;
|
|
16
|
+
font-size: var(--vmx-caption-size, 18px) !important;
|
|
17
|
+
font-weight: 500 !important;
|
|
18
|
+
line-height: 1.45 !important;
|
|
19
|
+
padding: 0.18em 0.5em !important;
|
|
20
|
+
border-radius: 4px !important;
|
|
21
|
+
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85) !important;
|
|
22
|
+
backdrop-filter: blur(8px);
|
|
23
|
+
-webkit-backdrop-filter: blur(8px);
|
|
24
|
+
box-decoration-break: clone;
|
|
25
|
+
-webkit-box-decoration-break: clone;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Player slider customization */
|
|
29
|
+
[data-media-player][data-layout="video"] {
|
|
30
|
+
--media-brand: var(--vmx-primary, #06b6d4); /* Mesh Cyan */
|
|
31
|
+
--media-slider-track-fill-bg: var(--vmx-primary, #06b6d4);
|
|
32
|
+
--media-slider-track-progress-bg: rgba(245, 158, 11, 0.35); /* Tally Amber */
|
|
33
|
+
--media-slider-track-bg: rgba(255, 255, 255, 0.18);
|
|
34
|
+
--media-slider-thumb-bg: #fff;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[data-media-player][data-layout="video"] .vds-time-slider {
|
|
38
|
+
--slider-track-height: 4px;
|
|
39
|
+
--slider-track-border-radius: 999px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[data-media-player][data-layout="video"] .vds-slider-track {
|
|
43
|
+
background: var(--media-slider-track-bg) !important;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[data-media-player][data-layout="video"] .vds-slider-track-fill {
|
|
47
|
+
background: var(--media-slider-track-bg) !important;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
[data-media-player][data-layout="video"] .vds-slider-track-progress {
|
|
51
|
+
background: var(--media-slider-track-progress-bg) !important;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-progress{
|
|
55
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-chapter .vds-slider-progress{
|
|
59
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@keyframes motionmesh-spin {
|
|
63
|
+
to { transform: rotate(360deg); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.motionmesh-loader {
|
|
67
|
+
width: 40px;
|
|
68
|
+
height: 40px;
|
|
69
|
+
border: 3px solid rgba(225, 29, 72, 0.2);
|
|
70
|
+
border-top-color: var(--vmx-primary, #3b82f6);
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
animation: motionmesh-spin 0.8s linear infinite;
|
|
73
|
+
}
|
|
74
|
+
`,document.head.appendChild(e);}var at={..._default.defaultLayoutIcons,PlayButton:{Play:j,Pause:H,Replay:j},MuteButton:{Mute:et,VolumeHigh:R,VolumeLow:R},FullscreenButton:{Enter:Y,Exit:tt},SeekButton:{Backward:X,Forward:Q},Menu:{..._default.defaultLayoutIcons.Menu,Settings:G},PIPButton:{Enter:K,Exit:Z},CaptionButton:{On:q,Off:J}};function kt(e){try{let n=new URL(e),l=n.searchParams.get("token"),d=n.searchParams.get("expires"),a=n.searchParams.get("token_path");if(l&&d&&a)return `token=${encodeURIComponent(l)}&expires=${encodeURIComponent(d)}&token_path=${encodeURIComponent(a)}`}catch{}return ""}function xt(e,n){let[l,d]=react.useState(null);return react.useEffect(()=>{if(!e)return;let a=null,u=false;async function i(){let g=await fetch(e);if(!g.ok)throw new Error("Failed to load thumbnail vtt");let h=await g.text(),v=new URL(e),I=h.replace(/^(?!WEBVTT|NOTE|\s*$|\d{2}:\d{2}:\d{2})\s*(.+)$/gm,S=>{let[p,m=""]=S.trim().split("#"),y=new URL(p,v);return new URLSearchParams(n).forEach((E,U)=>y.searchParams.set(U,E)),`${y.toString()}${m?`#${m}`:""}`});a=URL.createObjectURL(new Blob([I],{type:"text/vtt"})),u||d(a);}return i().catch(console.error),()=>{u=true,a&&URL.revokeObjectURL(a);}},[e,n]),l}function bt(e){return `WEBVTT
|
|
75
|
+
|
|
76
|
+
`+e.replace(/\r+/g,"").replace(/^\d+\n/gm,"").replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g,"$1.$2")}function Mt(e){let[n,l]=react.useState(null);return react.useEffect(()=>{if(!e)return;let d=false,a=null;async function u(){let i=await fetch(e);if(!i.ok)throw new Error("Failed to load subtitles");let g=await i.text(),h=bt(g),v=new Blob([h],{type:"text/vtt"});a=URL.createObjectURL(v),d||l(a);}return u().catch(console.error),()=>{d=true,a&&URL.revokeObjectURL(a);}},[e]),n}function Rt({videoTrackingId:e,autoPlay:n,playsInline:l,onReady:d,onError:a}){let u=react.useRef(null),[i,g]=react.useState(),[h,v]=react.useState(false),[I,S]=react.useState(null),p=react.useRef(false),m=react.useRef(false),y=react.useRef(0),B="vmx_view_",E=720*60*60*1e3;react.useEffect(()=>{async function o(){try{let r=await rt();S(r);}catch(r){console.error("Failed to initialize user country:",r);}}o();},[]),react.useEffect(()=>{if(p.current=false,m.current=false,!!e)try{let o=`${B}${e}`,r=localStorage.getItem(o);if(!r){p.current=!0;return}let c=Number(r);if(!Number.isFinite(c)){localStorage.removeItem(o),p.current=!0;return}Date.now()-c>=E&&(localStorage.removeItem(o),p.current=!0);}catch{p.current=false;}},[e]);let U=async()=>{if(!h){v(true);try{let o=await fetch(`/api/motionmesh/player?videoTrackingId=${e}`,{method:"POST",headers:{Accept:"application/json"}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let r=await o.json();g(r);}catch(o){console.error(o);}finally{v(false);}}};react.useEffect(()=>{wt(),e&&U();},[e]);let w=i?.playerSettings??{},W=w?.primaryColor??"#06b6d4",L=w?.fontFamily,$=w?.captions?.fontColor??"#ffffff",_=w?.captions?.backgroundColor??"rgba(15, 23, 42, 0.75)",V=Number(w?.captions?.fontSize??"18"),N=w?.playButton?.present,ct=react.useMemo(()=>{let o={"--vmx-primary":W,"--vmx-caption-color":$,"--vmx-caption-bg":_,"--vmx-caption-size":`${Number.isFinite(V)?V:18}px`};return typeof L=="string"&&L.trim()&&(o.fontFamily=L),o},[W,$,_,V,L]),lt=react.useMemo(()=>N==="minimal"?_default.defaultLayoutIcons:N==="block"?{...at,PlayButton:{Play:A,Pause:ot,Replay:A}}:at,[N]),x=async(o,r)=>{if(i?.analyticsToken)try{if(await fetch("/api/motionmesh/player?kind=event",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({event:o,currentTime:r,token:i.analyticsToken,geo:I||void 0,isUnique:p.current&&!m.current&&r>=3})}),p.current&&!m.current&&r>=3){m.current=!0;try{let c=`${B}${e}`;localStorage.setItem(c,Date.now().toString());}catch{}}}catch(c){console.error("Failed to send analytics event",c);}},z=i?.playlistUrl||"",F=kt(z),ut=i?.subtitleUrl||void 0,O=Mt(ut),dt=i?.timelineSpritesUrl||"",pt=xt(dt,F),ht=i?.vtt&&URL.createObjectURL(new Blob([i?.vtt],{type:"text/vtt"}));return h&&!i?jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center w-full h-full bg-black text-white gap-4",children:jsxRuntime.jsx("div",{className:"motionmesh-loader"})}):!i&&!h?jsxRuntime.jsx("div",{className:"flex items-center justify-center w-full h-full bg-black text-white",children:"Error loading video."}):jsxRuntime.jsxs(react$1.MediaPlayer,{ref:u,title:"Motionmesh Player",playsInline:l??true,autoPlay:n??false,src:z,style:ct,onCanPlay:d,onError:a,onPlay:()=>{let o=u?.current?.currentTime||0;x("play",o),y.current=o;},onPause:()=>{x("pause",u.current?.currentTime||0);},onEnded:()=>{x("ended",u.current?.currentTime||0);},onSeeked:()=>{x("seek",u.current?.currentTime||0);},onTimeUpdate:o=>{let r=o.currentTime;r-y.current>=15&&(x("heartbeat",r),y.current=r);},onProviderChange:o=>{o?.type==="hls"&&(o.config={abrEwmaDefaultEstimate:5e6,startLevel:-1,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetry:2,maxMaxBufferLength:30,progressive:true,xhrSetup:(r,c)=>{if(!c.includes("token=")){let D=c?.includes("?")?"&":"?";r.open("GET",`${c}${D}${F}`,true);}}});},children:[jsxRuntime.jsxs(react$1.MediaProvider,{children:[jsxRuntime.jsx(react$1.Track,{src:ht,kind:"chapters",label:"Chapters",default:true}),O&&jsxRuntime.jsx(react$1.Track,{src:O,kind:"subtitles",label:"English",lang:"en",default:true}),jsxRuntime.jsx(react$1.Captions,{className:"vds-captions"})]}),jsxRuntime.jsx(_default.DefaultVideoLayout,{thumbnails:pt,icons:lt,slots:{googleCastButton:null,chaptersMenu:null}})]})}exports.MotionmeshPlayer=Rt;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {useRef,useState,useEffect,useMemo}from'react';import {MediaPlayer,MediaProvider,Track,Captions}from'@vidstack/react';import {defaultLayoutIcons,DefaultVideoLayout}from'@vidstack/react/player/layouts/default';import'@vidstack/react/player/styles/default/theme.css';import'@vidstack/react/player/styles/default/layouts/video.css';import {jsx,jsxs}from'react/jsx-runtime';function j(){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-icon lucide-play",children:jsx("path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"})})}function H(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-pause-icon lucide-pause",children:[jsx("rect",{x:"14",y:"3",width:"5",height:"18",rx:"1"}),jsx("rect",{x:"5",y:"3",width:"5",height:"18",rx:"1"})]})}function q(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-icon lucide-captions",children:[jsx("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2"}),jsx("path",{d:"M7 15h4M15 15h2M7 11h2M13 11h4"})]})}function J(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"26",height:"26",viewBox:"0 0 26 26",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-captions-off-icon lucide-captions-off",children:[jsx("path",{d:"M10.5 5H19a2 2 0 0 1 2 2v8.5"}),jsx("path",{d:"M17 11h-.5"}),jsx("path",{d:"M19 19H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2"}),jsx("path",{d:"m2 2 20 20"}),jsx("path",{d:"M7 11h4"}),jsx("path",{d:"M7 15h2.5"})]})}function K(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture2-icon lucide-picture-in-picture-2",children:[jsx("path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4"}),jsx("rect",{width:"10",height:"7",x:"12",y:"13",rx:"2"})]})}function Z(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-picture-in-picture-icon lucide-picture-in-picture",children:[jsx("path",{d:"M2 10h6V4"}),jsx("path",{d:"m2 4 6 6"}),jsx("path",{d:"M21 10V7a2 2 0 0 0-2-2h-7"}),jsx("path",{d:"M3 14v2a2 2 0 0 0 2 2h3"}),jsx("rect",{x:"12",y:"14",width:"10",height:"7",rx:"1"})]})}function G(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-settings-icon lucide-settings",children:[jsx("path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}),jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Q(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-forward-icon lucide-skip-forward",children:[jsx("path",{d:"M21 4v16"}),jsx("path",{d:"M6.029 4.285A2 2 0 0 0 3 6v12a2 2 0 0 0 3.029 1.715l9.997-5.998a2 2 0 0 0 .003-3.432z"})]})}function X(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-skip-back-icon lucide-skip-back",children:[jsx("path",{d:"M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z"}),jsx("path",{d:"M3 20V4"})]})}function Y(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-maximize-icon lucide-maximize",children:[jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),jsx("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),jsx("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),jsx("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]})}function tt(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-minimize-icon lucide-minimize",children:[jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),jsx("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),jsx("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),jsx("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function et(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume-off-icon lucide-volume-off",children:[jsx("path",{d:"M16 9a5 5 0 0 1 .95 2.293"}),jsx("path",{d:"M19.364 5.636a9 9 0 0 1 1.889 9.96"}),jsx("path",{d:"m2 2 20 20"}),jsx("path",{d:"m7 7-.587.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298V11"}),jsx("path",{d:"M9.828 4.172A.686.686 0 0 1 11 4.657v.686"})]})}function R(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-volume2-icon lucide-volume-2",children:[jsx("path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"}),jsx("path",{d:"M16 9a5 5 0 0 1 0 6"}),jsx("path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728"})]})}function A(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-off-icon lucide-play-off",children:[jsx("path",{d:"m10.215 4.56 9.79 5.71a2 2 0 0 1 .003 3.458l-.393.23"}),jsx("path",{d:"m16.042 16.042-8.034 4.686A2 2 0 0 1 5 19V5"}),jsx("path",{d:"m2 2 20 20"})]})}function ot(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-octagon-pause-icon lucide-octagon-pause",children:[jsx("path",{d:"M10 15V9"}),jsx("path",{d:"M14 15V9"}),jsx("path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z"})]})}var k=null,P="vmx:user-country",mt=10080*60*1e3;async function rt(){if(k)return k;if(typeof window<"u")try{let e=localStorage.getItem(P);if(e){let n=JSON.parse(e);if(n.expiresAt>Date.now())return k=n.value,k;localStorage.removeItem(P);}}catch{localStorage.removeItem(P);}try{let e=await fetch("https://ipapi.co/country/");if(!e.ok)throw new Error("Failed to fetch country");let n=(await e.text()).trim();if(k=n,typeof window<"u"){let l={value:n,expiresAt:Date.now()+mt};localStorage.setItem(P,JSON.stringify(l));}return k}catch(e){return console.error("Error fetching user country:",e),null}}function wt(){if(typeof document>"u")return;let e=document.createElement("style");e.textContent=`
|
|
2
|
+
[data-media-player][data-layout="video"] .vds-captions {
|
|
3
|
+
bottom: 1% !important;
|
|
4
|
+
transition: bottom 0.2s ease;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[data-media-player][data-layout="video"][data-hover] .vds-captions,
|
|
8
|
+
[data-media-player][data-layout="video"][data-controls] .vds-captions {
|
|
9
|
+
bottom: 8% !important;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-media-player][data-layout="video"] .vds-captions [data-part="cue"] {
|
|
13
|
+
display: inline-block;
|
|
14
|
+
background: var(--vmx-caption-bg, rgba(15, 23, 42, 0.75)) !important; /* Signal Ink */
|
|
15
|
+
color: var(--vmx-caption-color, #fff) !important;
|
|
16
|
+
font-size: var(--vmx-caption-size, 18px) !important;
|
|
17
|
+
font-weight: 500 !important;
|
|
18
|
+
line-height: 1.45 !important;
|
|
19
|
+
padding: 0.18em 0.5em !important;
|
|
20
|
+
border-radius: 4px !important;
|
|
21
|
+
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85) !important;
|
|
22
|
+
backdrop-filter: blur(8px);
|
|
23
|
+
-webkit-backdrop-filter: blur(8px);
|
|
24
|
+
box-decoration-break: clone;
|
|
25
|
+
-webkit-box-decoration-break: clone;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Player slider customization */
|
|
29
|
+
[data-media-player][data-layout="video"] {
|
|
30
|
+
--media-brand: var(--vmx-primary, #06b6d4); /* Mesh Cyan */
|
|
31
|
+
--media-slider-track-fill-bg: var(--vmx-primary, #06b6d4);
|
|
32
|
+
--media-slider-track-progress-bg: rgba(245, 158, 11, 0.35); /* Tally Amber */
|
|
33
|
+
--media-slider-track-bg: rgba(255, 255, 255, 0.18);
|
|
34
|
+
--media-slider-thumb-bg: #fff;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
[data-media-player][data-layout="video"] .vds-time-slider {
|
|
38
|
+
--slider-track-height: 4px;
|
|
39
|
+
--slider-track-border-radius: 999px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[data-media-player][data-layout="video"] .vds-slider-track {
|
|
43
|
+
background: var(--media-slider-track-bg) !important;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[data-media-player][data-layout="video"] .vds-slider-track-fill {
|
|
47
|
+
background: var(--media-slider-track-bg) !important;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
[data-media-player][data-layout="video"] .vds-slider-track-progress {
|
|
51
|
+
background: var(--media-slider-track-progress-bg) !important;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-progress{
|
|
55
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[data-media-player][data-layout="video"].vds-time-slider .vds-slider-chapter .vds-slider-progress{
|
|
59
|
+
background-color: var(--vmx-buffered, rgba(255, 255, 255, 0.22)) !important
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@keyframes motionmesh-spin {
|
|
63
|
+
to { transform: rotate(360deg); }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.motionmesh-loader {
|
|
67
|
+
width: 40px;
|
|
68
|
+
height: 40px;
|
|
69
|
+
border: 3px solid rgba(225, 29, 72, 0.2);
|
|
70
|
+
border-top-color: var(--vmx-primary, #3b82f6);
|
|
71
|
+
border-radius: 50%;
|
|
72
|
+
animation: motionmesh-spin 0.8s linear infinite;
|
|
73
|
+
}
|
|
74
|
+
`,document.head.appendChild(e);}var at={...defaultLayoutIcons,PlayButton:{Play:j,Pause:H,Replay:j},MuteButton:{Mute:et,VolumeHigh:R,VolumeLow:R},FullscreenButton:{Enter:Y,Exit:tt},SeekButton:{Backward:X,Forward:Q},Menu:{...defaultLayoutIcons.Menu,Settings:G},PIPButton:{Enter:K,Exit:Z},CaptionButton:{On:q,Off:J}};function kt(e){try{let n=new URL(e),l=n.searchParams.get("token"),d=n.searchParams.get("expires"),a=n.searchParams.get("token_path");if(l&&d&&a)return `token=${encodeURIComponent(l)}&expires=${encodeURIComponent(d)}&token_path=${encodeURIComponent(a)}`}catch{}return ""}function xt(e,n){let[l,d]=useState(null);return useEffect(()=>{if(!e)return;let a=null,u=false;async function i(){let g=await fetch(e);if(!g.ok)throw new Error("Failed to load thumbnail vtt");let h=await g.text(),v=new URL(e),I=h.replace(/^(?!WEBVTT|NOTE|\s*$|\d{2}:\d{2}:\d{2})\s*(.+)$/gm,S=>{let[p,m=""]=S.trim().split("#"),y=new URL(p,v);return new URLSearchParams(n).forEach((E,U)=>y.searchParams.set(U,E)),`${y.toString()}${m?`#${m}`:""}`});a=URL.createObjectURL(new Blob([I],{type:"text/vtt"})),u||d(a);}return i().catch(console.error),()=>{u=true,a&&URL.revokeObjectURL(a);}},[e,n]),l}function bt(e){return `WEBVTT
|
|
75
|
+
|
|
76
|
+
`+e.replace(/\r+/g,"").replace(/^\d+\n/gm,"").replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g,"$1.$2")}function Mt(e){let[n,l]=useState(null);return useEffect(()=>{if(!e)return;let d=false,a=null;async function u(){let i=await fetch(e);if(!i.ok)throw new Error("Failed to load subtitles");let g=await i.text(),h=bt(g),v=new Blob([h],{type:"text/vtt"});a=URL.createObjectURL(v),d||l(a);}return u().catch(console.error),()=>{d=true,a&&URL.revokeObjectURL(a);}},[e]),n}function Rt({videoTrackingId:e,autoPlay:n,playsInline:l,onReady:d,onError:a}){let u=useRef(null),[i,g]=useState(),[h,v]=useState(false),[I,S]=useState(null),p=useRef(false),m=useRef(false),y=useRef(0),B="vmx_view_",E=720*60*60*1e3;useEffect(()=>{async function o(){try{let r=await rt();S(r);}catch(r){console.error("Failed to initialize user country:",r);}}o();},[]),useEffect(()=>{if(p.current=false,m.current=false,!!e)try{let o=`${B}${e}`,r=localStorage.getItem(o);if(!r){p.current=!0;return}let c=Number(r);if(!Number.isFinite(c)){localStorage.removeItem(o),p.current=!0;return}Date.now()-c>=E&&(localStorage.removeItem(o),p.current=!0);}catch{p.current=false;}},[e]);let U=async()=>{if(!h){v(true);try{let o=await fetch(`/api/motionmesh/player?videoTrackingId=${e}`,{method:"POST",headers:{Accept:"application/json"}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let r=await o.json();g(r);}catch(o){console.error(o);}finally{v(false);}}};useEffect(()=>{wt(),e&&U();},[e]);let w=i?.playerSettings??{},W=w?.primaryColor??"#06b6d4",L=w?.fontFamily,$=w?.captions?.fontColor??"#ffffff",_=w?.captions?.backgroundColor??"rgba(15, 23, 42, 0.75)",V=Number(w?.captions?.fontSize??"18"),N=w?.playButton?.present,ct=useMemo(()=>{let o={"--vmx-primary":W,"--vmx-caption-color":$,"--vmx-caption-bg":_,"--vmx-caption-size":`${Number.isFinite(V)?V:18}px`};return typeof L=="string"&&L.trim()&&(o.fontFamily=L),o},[W,$,_,V,L]),lt=useMemo(()=>N==="minimal"?defaultLayoutIcons:N==="block"?{...at,PlayButton:{Play:A,Pause:ot,Replay:A}}:at,[N]),x=async(o,r)=>{if(i?.analyticsToken)try{if(await fetch("/api/motionmesh/player?kind=event",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({event:o,currentTime:r,token:i.analyticsToken,geo:I||void 0,isUnique:p.current&&!m.current&&r>=3})}),p.current&&!m.current&&r>=3){m.current=!0;try{let c=`${B}${e}`;localStorage.setItem(c,Date.now().toString());}catch{}}}catch(c){console.error("Failed to send analytics event",c);}},z=i?.playlistUrl||"",F=kt(z),ut=i?.subtitleUrl||void 0,O=Mt(ut),dt=i?.timelineSpritesUrl||"",pt=xt(dt,F),ht=i?.vtt&&URL.createObjectURL(new Blob([i?.vtt],{type:"text/vtt"}));return h&&!i?jsx("div",{className:"flex flex-col items-center justify-center w-full h-full bg-black text-white gap-4",children:jsx("div",{className:"motionmesh-loader"})}):!i&&!h?jsx("div",{className:"flex items-center justify-center w-full h-full bg-black text-white",children:"Error loading video."}):jsxs(MediaPlayer,{ref:u,title:"Motionmesh Player",playsInline:l??true,autoPlay:n??false,src:z,style:ct,onCanPlay:d,onError:a,onPlay:()=>{let o=u?.current?.currentTime||0;x("play",o),y.current=o;},onPause:()=>{x("pause",u.current?.currentTime||0);},onEnded:()=>{x("ended",u.current?.currentTime||0);},onSeeked:()=>{x("seek",u.current?.currentTime||0);},onTimeUpdate:o=>{let r=o.currentTime;r-y.current>=15&&(x("heartbeat",r),y.current=r);},onProviderChange:o=>{o?.type==="hls"&&(o.config={abrEwmaDefaultEstimate:5e6,startLevel:-1,levelLoadingMaxRetry:2,manifestLoadingMaxRetry:2,fragLoadingMaxRetry:2,maxMaxBufferLength:30,progressive:true,xhrSetup:(r,c)=>{if(!c.includes("token=")){let D=c?.includes("?")?"&":"?";r.open("GET",`${c}${D}${F}`,true);}}});},children:[jsxs(MediaProvider,{children:[jsx(Track,{src:ht,kind:"chapters",label:"Chapters",default:true}),O&&jsx(Track,{src:O,kind:"subtitles",label:"English",lang:"en",default:true}),jsx(Captions,{className:"vds-captions"})]}),jsx(DefaultVideoLayout,{thumbnails:pt,icons:lt,slots:{googleCastButton:null,chaptersMenu:null}})]})}export{Rt as MotionmeshPlayer};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var m=()=>({baseUrl:process.env.MOTIONMESH_BASE_URL||"https://motionmesh.co.in/api/v1"});function v(t){return t?/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(t):false}function w(t){return t?!!(t.startsWith("mot_live_")||t.startsWith("mot_test_")):false}async function b({request:t,apiKey:s}){try{if(!s)return Response.json({error:"Motionmesh apiKey is required"},{status:401});if(!(v(s)||w(s)))return Response.json({error:"Invalid API Key"},{status:401});let a={Authorization:`Bearer ${s}`},{baseUrl:r}=m(),{searchParams:u}=new URL(t.url),g=u.get("kind");if(g==="settings"){if((u.get("action")??"get")==="update"){let o=await t.json().catch(()=>null);if(!o||typeof o!="object")return Response.json({error:"Invalid settings payload"},{status:400});let c=await fetch(`${r}/player/settings`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...a},body:JSON.stringify(o)}),l=await c.json().catch(()=>null);return Response.json(l??{error:"Upstream error"},{status:c.status})}let n=await fetch(`${r}/player/settings`,{headers:{Accept:"application/json",...a}}),i=await n.json().catch(()=>null);return Response.json(i??{error:"Upstream error"},{status:n.status})}if(g==="event"){let e=await t.json().catch(()=>null);if(!e?.token||!e?.event||typeof e?.currentTime!="number")return Response.json({error:"token, event and currentTime are required"},{status:400});let n="",i="";try{[n,i]=atob(e.token).split(":");}catch{return Response.json({error:"invalid token"},{status:400})}let o={account_id:n,video_id:i,event_type:e.event,timestamp:new Date().toISOString(),country:e.geo||""},c=t.headers.get("user-agent")??"",l=t.headers.get("x-forwarded-for")??"";console.log("FETCHING:",`${r}/analytics/collect`);let d=await fetch(`${r}/analytics/collect`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...a,"user-agent":c,"x-forwarded-for":l},body:JSON.stringify(o)}),S=await d.json().catch(()=>null);return Response.json(S??{success:d.ok},{status:d.status})}let y=u.get("videoTrackingId");if(!y)return Response.json({error:"videoTrackingId is required"},{status:400});let h=await fetch(`${r}/videos/${y}/playback`,{headers:a}),j=await h.json().catch(()=>null);return Response.json(j??{error:"Upstream error"},{status:h.status})}catch(p){let f=p?.message||"An unexpected error occurred";return Response.json({error:f},{status:500})}}
|
|
2
|
+
exports.handleProcessRequest=b;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var m=()=>({baseUrl:process.env.MOTIONMESH_BASE_URL||"https://motionmesh.co.in/api/v1"});function v(t){return t?/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(t):false}function w(t){return t?!!(t.startsWith("mot_live_")||t.startsWith("mot_test_")):false}async function b({request:t,apiKey:s}){try{if(!s)return Response.json({error:"Motionmesh apiKey is required"},{status:401});if(!(v(s)||w(s)))return Response.json({error:"Invalid API Key"},{status:401});let a={Authorization:`Bearer ${s}`},{baseUrl:r}=m(),{searchParams:u}=new URL(t.url),g=u.get("kind");if(g==="settings"){if((u.get("action")??"get")==="update"){let o=await t.json().catch(()=>null);if(!o||typeof o!="object")return Response.json({error:"Invalid settings payload"},{status:400});let c=await fetch(`${r}/player/settings`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...a},body:JSON.stringify(o)}),l=await c.json().catch(()=>null);return Response.json(l??{error:"Upstream error"},{status:c.status})}let n=await fetch(`${r}/player/settings`,{headers:{Accept:"application/json",...a}}),i=await n.json().catch(()=>null);return Response.json(i??{error:"Upstream error"},{status:n.status})}if(g==="event"){let e=await t.json().catch(()=>null);if(!e?.token||!e?.event||typeof e?.currentTime!="number")return Response.json({error:"token, event and currentTime are required"},{status:400});let n="",i="";try{[n,i]=atob(e.token).split(":");}catch{return Response.json({error:"invalid token"},{status:400})}let o={account_id:n,video_id:i,event_type:e.event,timestamp:new Date().toISOString(),country:e.geo||""},c=t.headers.get("user-agent")??"",l=t.headers.get("x-forwarded-for")??"";console.log("FETCHING:",`${r}/analytics/collect`);let d=await fetch(`${r}/analytics/collect`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...a,"user-agent":c,"x-forwarded-for":l},body:JSON.stringify(o)}),S=await d.json().catch(()=>null);return Response.json(S??{success:d.ok},{status:d.status})}let y=u.get("videoTrackingId");if(!y)return Response.json({error:"videoTrackingId is required"},{status:400});let h=await fetch(`${r}/videos/${y}/playback`,{headers:a}),j=await h.json().catch(()=>null);return Response.json(j??{error:"Upstream error"},{status:h.status})}catch(p){let f=p?.message||"An unexpected error occurred";return Response.json({error:f},{status:500})}}
|
|
2
|
+
export{b as handleProcessRequest};
|
package/package.json
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@motionmesh/player",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React video player component for Motionmesh, built on Vidstack",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "sanjeev0303",
|
|
7
|
+
"type": "module",
|
|
8
|
+
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"default": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
"./react": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/react/index.d.ts",
|
|
32
|
+
"default": "./dist/react/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/react/index.d.cts",
|
|
36
|
+
"default": "./dist/react/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
"./server": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/server/index.d.ts",
|
|
43
|
+
"default": "./dist/server/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/server/index.d.cts",
|
|
47
|
+
"default": "./dist/server/index.cjs"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
"sideEffects": true,
|
|
53
|
+
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"clean": "rm -rf dist",
|
|
63
|
+
"pack:dry-run": "npm pack --dry-run",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
"keywords": [
|
|
69
|
+
"video",
|
|
70
|
+
"video-player",
|
|
71
|
+
"hls",
|
|
72
|
+
"vidstack",
|
|
73
|
+
"motionmesh",
|
|
74
|
+
"streaming"
|
|
75
|
+
],
|
|
76
|
+
|
|
77
|
+
"homepage": "https://github.com/sanjeev0303/motionmesh#readme",
|
|
78
|
+
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/sanjeev0303/motionmesh/issues"
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
"repository": {
|
|
84
|
+
"type": "git",
|
|
85
|
+
"url": "git+https://github.com/sanjeev0303/motionmesh.git",
|
|
86
|
+
"directory": "sdk/js/packages/player"
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": ">=18"
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
"peerDependencies": {
|
|
94
|
+
"react": ">=18",
|
|
95
|
+
"react-dom": ">=18"
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
"peerDependenciesMeta": {
|
|
99
|
+
"react": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"react-dom": {
|
|
103
|
+
"optional": true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
"devDependencies": {
|
|
108
|
+
"@types/node": "^25.3.3",
|
|
109
|
+
"@types/react": "^19.2.14",
|
|
110
|
+
"tsup": "^8.5.1",
|
|
111
|
+
"tsx": "^4.21.0",
|
|
112
|
+
"typescript": "^5.9.3"
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
"dependencies": {
|
|
116
|
+
"@vidstack/react": "^1.12.13",
|
|
117
|
+
"hls.js": "^1.6.16",
|
|
118
|
+
"media-icons": "^1.1.5",
|
|
119
|
+
"vidstack": "^1.12.13"
|
|
120
|
+
}
|
|
121
|
+
}
|