@obipascal/player 1.0.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/LICENSE +21 -0
- package/README.md +854 -0
- package/dist/examples/cloudfront-example.d.ts +25 -0
- package/dist/examples/custom-themes.d.ts +124 -0
- package/dist/examples/events-demo.d.ts +52 -0
- package/dist/examples/public-stream-test.d.ts +38 -0
- package/dist/examples/react-examples.d.ts +32 -0
- package/dist/examples/vanilla-js-examples.d.ts +56 -0
- package/dist/index.d.ts +1 -0
- package/dist/src/analytics.d.ts +28 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/player.d.ts +63 -0
- package/dist/src/react.d.ts +48 -0
- package/dist/src/s3-handler.d.ts +95 -0
- package/dist/src/types.d.ts +113 -0
- package/dist/src/ui-controller.d.ts +51 -0
- package/dist/wontum-player.cjs.js +592 -0
- package/dist/wontum-player.esm.js +1626 -0
- package/package.json +57 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WontumPlayer } from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example 1: Basic CloudFront Setup
|
|
5
|
+
*/
|
|
6
|
+
export declare function basicCloudFrontExample(): WontumPlayer;
|
|
7
|
+
/**
|
|
8
|
+
* Example 2: With Error Handling and Retry
|
|
9
|
+
*/
|
|
10
|
+
export declare function cloudFrontWithRetryExample(): WontumPlayer;
|
|
11
|
+
/**
|
|
12
|
+
* Example 3: React Component with CloudFront
|
|
13
|
+
*
|
|
14
|
+
* Note: This is a code example as a string. For actual React usage,
|
|
15
|
+
* copy this to a .tsx file in your project.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ReactCloudFrontPlayerExample = "\nimport React from \"react\"\nimport { WontumPlayerReact } from \"@wontum/player\"\n\nexport function CloudFrontPlayer({ videoUrl, userId }: { videoUrl: string; userId: string }) {\n\t// Sign URL function\n\tasync function signUrl(url: string): Promise<string> {\n\t\tconst response = await fetch(\"/api/cloudfront/sign\", {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tbody: JSON.stringify({ url, userId }),\n\t\t\tcredentials: \"include\",\n\t\t})\n\n\t\tconst data = await response.json()\n\t\treturn data.url\n\t}\n\n\treturn (\n\t\t<WontumPlayerReact\n\t\t\tsrc={videoUrl}\n\t\t\twidth=\"100%\"\n\t\t\theight=\"500px\"\n\t\t\ts3Config={{\n\t\t\t\tsignUrl,\n\t\t\t\tcloudFrontDomains: [\"media.domain.com\", \"cdn.domain.com\"], // Multiple domains\n\t\t\t}}\n\t\t\tanalytics={{\n\t\t\t\tenabled: true,\n\t\t\t\tuserId,\n\t\t\t\tvideoId: videoUrl,\n\t\t\t}}\n\t\t\tonError={(error) => {\n\t\t\t\tconsole.error(\"Player error:\", error)\n\t\t\t\t// Handle signing errors\n\t\t\t\tif (error?.message?.includes(\"sign\")) {\n\t\t\t\t\talert(\"Failed to authenticate video. Please refresh and try again.\")\n\t\t\t\t}\n\t\t\t}}\n\t\t/>\n\t)\n}\n";
|
|
18
|
+
/**
|
|
19
|
+
* Example 4: Backend Implementation (Node.js/Express)
|
|
20
|
+
*/
|
|
21
|
+
export declare const backendExample = "\n// backend/routes/cloudfront.js\nconst express = require('express');\nconst AWS = require('aws-sdk');\nconst router = express.Router();\n\n// Initialize CloudFront signer\nconst cloudFront = new AWS.CloudFront.Signer(\n process.env.CLOUDFRONT_KEY_PAIR_ID,\n process.env.CLOUDFRONT_PRIVATE_KEY\n);\n\n// Middleware to verify user authentication\nfunction requireAuth(req, res, next) {\n if (!req.user) {\n return res.status(401).json({ error: 'Unauthorized' });\n }\n next();\n}\n\n// Middleware to verify user has access to video\nasync function verifyVideoAccess(req, res, next) {\n const { url } = req.body;\n const userId = req.user.id;\n \n // Extract video ID from URL\n const videoId = extractVideoIdFromUrl(url);\n \n // Check database if user has access\n const hasAccess = await checkUserVideoAccess(userId, videoId);\n \n if (!hasAccess) {\n return res.status(403).json({ error: 'Access denied to this video' });\n }\n \n next();\n}\n\n// Sign CloudFront URL endpoint\nrouter.post('/cloudfront/sign', requireAuth, verifyVideoAccess, (req, res) => {\n try {\n const { url } = req.body;\n \n if (!url) {\n return res.status(400).json({ error: 'URL is required' });\n }\n \n // Parse URL to get domain\n const urlObj = new URL(url);\n const domain = urlObj.hostname;\n \n // Create signed cookies\n const policy = JSON.stringify({\n Statement: [{\n Resource: `https://${domain}/*`,\n Condition: {\n DateLessThan: {\n 'AWS:EpochTime': Math.floor(Date.now() / 1000) + 3600 // 1 hour\n }\n }\n }]\n });\n \n const signedCookies = cloudFront.getSignedCookie({\n policy\n });\n \n // Set signed cookies\n const cookieOptions = {\n domain: domain,\n path: '/',\n secure: true,\n httpOnly: true,\n sameSite: 'none',\n maxAge: 3600000 // 1 hour\n };\n \n res.cookie('CloudFront-Policy', signedCookies['CloudFront-Policy'], cookieOptions);\n res.cookie('CloudFront-Signature', signedCookies['CloudFront-Signature'], cookieOptions);\n res.cookie('CloudFront-Key-Pair-Id', signedCookies['CloudFront-Key-Pair-Id'], cookieOptions);\n \n // Return the original URL\n // The cookies will authenticate subsequent requests\n res.json({ url });\n \n } catch (error) {\n console.error('Error signing CloudFront URL:', error);\n res.status(500).json({ error: 'Failed to sign URL' });\n }\n});\n\nmodule.exports = router;\n";
|
|
22
|
+
/**
|
|
23
|
+
* Example 5: Python/Django Backend
|
|
24
|
+
*/
|
|
25
|
+
export declare const pythonBackendExample = "\n# backend/videos/views.py\nfrom django.http import JsonResponse\nfrom django.views.decorators.csrf import csrf_exempt\nfrom django.contrib.auth.decorators import login_required\nimport json\nfrom datetime import datetime, timedelta\nfrom cryptography.hazmat.primitives import hashes, serialization\nfrom cryptography.hazmat.primitives.asymmetric import padding\nimport base64\n\n@csrf_exempt\n@login_required\ndef sign_cloudfront_url(request):\n if request.method != 'POST':\n return JsonResponse({'error': 'Method not allowed'}, status=405)\n \n try:\n data = json.loads(request.body)\n url = data.get('url')\n \n if not url:\n return JsonResponse({'error': 'URL is required'}, status=400)\n \n # Verify user has access to video\n video_id = extract_video_id_from_url(url)\n if not user_has_video_access(request.user, video_id):\n return JsonResponse({'error': 'Access denied'}, status=403)\n \n # Create CloudFront signed cookies\n expiration = datetime.utcnow() + timedelta(hours=1)\n \n policy = {\n \"Statement\": [{\n \"Resource\": f\"https://media.domain.com/*\",\n \"Condition\": {\n \"DateLessThan\": {\n \"AWS:EpochTime\": int(expiration.timestamp())\n }\n }\n }]\n }\n \n # Sign the policy\n signed_cookies = create_signed_cookies(policy)\n \n # Set cookies\n response = JsonResponse({'url': url})\n response.set_cookie(\n 'CloudFront-Policy',\n signed_cookies['CloudFront-Policy'],\n domain='media.domain.com',\n secure=True,\n httponly=True,\n samesite='None',\n max_age=3600\n )\n response.set_cookie(\n 'CloudFront-Signature',\n signed_cookies['CloudFront-Signature'],\n domain='media.domain.com',\n secure=True,\n httponly=True,\n samesite='None',\n max_age=3600\n )\n response.set_cookie(\n 'CloudFront-Key-Pair-Id',\n signed_cookies['CloudFront-Key-Pair-Id'],\n domain='media.domain.com',\n secure=True,\n httponly=True,\n samesite='None',\n max_age=3600\n )\n \n return response\n \n except Exception as e:\n return JsonResponse({'error': str(e)}, status=500)\n";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { WontumPlayer } from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example 1: Netflix-style Dark Theme
|
|
5
|
+
*/
|
|
6
|
+
export declare function netflixTheme(): WontumPlayer;
|
|
7
|
+
/**
|
|
8
|
+
* Example 2: YouTube-style Theme
|
|
9
|
+
*/
|
|
10
|
+
export declare function youtubeTheme(): WontumPlayer;
|
|
11
|
+
/**
|
|
12
|
+
* Example 3: Modern Purple/Pink Theme
|
|
13
|
+
*/
|
|
14
|
+
export declare function modernTheme(): WontumPlayer;
|
|
15
|
+
/**
|
|
16
|
+
* Example 4: Minimal Green Theme
|
|
17
|
+
*/
|
|
18
|
+
export declare function minimalGreenTheme(): WontumPlayer;
|
|
19
|
+
/**
|
|
20
|
+
* Example 5: Bold Cyberpunk Theme
|
|
21
|
+
*/
|
|
22
|
+
export declare function cyberpunkTheme(): WontumPlayer;
|
|
23
|
+
/**
|
|
24
|
+
* Example 6: Soft Pastel Theme
|
|
25
|
+
*/
|
|
26
|
+
export declare function pastelTheme(): WontumPlayer;
|
|
27
|
+
/**
|
|
28
|
+
* Example 7: Education Platform Theme
|
|
29
|
+
*/
|
|
30
|
+
export declare function educationTheme(): WontumPlayer;
|
|
31
|
+
/**
|
|
32
|
+
* React Example with Custom Theme
|
|
33
|
+
*/
|
|
34
|
+
export declare const ReactCustomThemeExample = "\nimport React from 'react';\nimport { WontumPlayerReact } from '@wontum/player';\n\nfunction CustomStyledPlayer() {\n return (\n <WontumPlayerReact\n src=\"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8\"\n theme={{\n primaryColor: '#ff6b6b', // Coral red\n accentColor: '#ee5a6f',\n fontFamily: 'Helvetica, Arial, sans-serif',\n controlsBackground: 'linear-gradient(to top, rgba(0,0,0,0.85), transparent)',\n buttonHoverBg: 'rgba(255, 107, 107, 0.25)',\n progressHeight: '5px',\n borderRadius: '8px'\n }}\n />\n );\n}\n";
|
|
35
|
+
/**
|
|
36
|
+
* All Available Theme Options
|
|
37
|
+
*/
|
|
38
|
+
export declare const ThemeOptions: {
|
|
39
|
+
/**
|
|
40
|
+
* Primary color for progress bar, sliders, etc.
|
|
41
|
+
* Default: '#3b82f6' (blue)
|
|
42
|
+
*/
|
|
43
|
+
primaryColor: string;
|
|
44
|
+
/**
|
|
45
|
+
* Accent color for hover states
|
|
46
|
+
* Default: '#2563eb' (darker blue)
|
|
47
|
+
*/
|
|
48
|
+
accentColor: string;
|
|
49
|
+
/**
|
|
50
|
+
* Font family for all text
|
|
51
|
+
* Default: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
|
|
52
|
+
*/
|
|
53
|
+
fontFamily: string;
|
|
54
|
+
/**
|
|
55
|
+
* Background for controls overlay
|
|
56
|
+
* Can be solid color or gradient
|
|
57
|
+
* Default: 'linear-gradient(to top, rgba(0,0,0,0.8), transparent)'
|
|
58
|
+
*/
|
|
59
|
+
controlsBackground: string;
|
|
60
|
+
/**
|
|
61
|
+
* Button hover background color
|
|
62
|
+
* Default: 'rgba(255, 255, 255, 0.1)'
|
|
63
|
+
*/
|
|
64
|
+
buttonHoverBg: string;
|
|
65
|
+
/**
|
|
66
|
+
* Height of progress bar
|
|
67
|
+
* Default: '6px'
|
|
68
|
+
*/
|
|
69
|
+
progressHeight: string;
|
|
70
|
+
/**
|
|
71
|
+
* Border radius for buttons and progress bar
|
|
72
|
+
* Default: '4px'
|
|
73
|
+
*/
|
|
74
|
+
borderRadius: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Brand Color Presets
|
|
78
|
+
*/
|
|
79
|
+
export declare const BrandPresets: {
|
|
80
|
+
netflix: {
|
|
81
|
+
primary: string;
|
|
82
|
+
accent: string;
|
|
83
|
+
};
|
|
84
|
+
youtube: {
|
|
85
|
+
primary: string;
|
|
86
|
+
accent: string;
|
|
87
|
+
};
|
|
88
|
+
vimeo: {
|
|
89
|
+
primary: string;
|
|
90
|
+
accent: string;
|
|
91
|
+
};
|
|
92
|
+
spotify: {
|
|
93
|
+
primary: string;
|
|
94
|
+
accent: string;
|
|
95
|
+
};
|
|
96
|
+
twitch: {
|
|
97
|
+
primary: string;
|
|
98
|
+
accent: string;
|
|
99
|
+
};
|
|
100
|
+
disney: {
|
|
101
|
+
primary: string;
|
|
102
|
+
accent: string;
|
|
103
|
+
};
|
|
104
|
+
hulu: {
|
|
105
|
+
primary: string;
|
|
106
|
+
accent: string;
|
|
107
|
+
};
|
|
108
|
+
amazon: {
|
|
109
|
+
primary: string;
|
|
110
|
+
accent: string;
|
|
111
|
+
};
|
|
112
|
+
apple: {
|
|
113
|
+
primary: string;
|
|
114
|
+
accent: string;
|
|
115
|
+
};
|
|
116
|
+
hbo: {
|
|
117
|
+
primary: string;
|
|
118
|
+
accent: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Quick Setup Helper
|
|
123
|
+
*/
|
|
124
|
+
export declare function createThemedPlayer(containerId: string, streamUrl: string, brandName: keyof typeof BrandPresets): WontumPlayer;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { WontumPlayer } from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* All available events in Wontum Player (Mux Player compatible)
|
|
5
|
+
*/
|
|
6
|
+
export declare function allEventsDemo(): WontumPlayer;
|
|
7
|
+
/**
|
|
8
|
+
* Event categories breakdown
|
|
9
|
+
*/
|
|
10
|
+
export declare const EventCategories: {
|
|
11
|
+
/**
|
|
12
|
+
* Playback Events - Control and playback state
|
|
13
|
+
*/
|
|
14
|
+
readonly playback: readonly ["play", "pause", "playing", "ended", "timeupdate"];
|
|
15
|
+
/**
|
|
16
|
+
* Seeking Events - User navigation
|
|
17
|
+
*/
|
|
18
|
+
readonly seeking: readonly ["seeking", "seeked"];
|
|
19
|
+
/**
|
|
20
|
+
* Loading Events - Media loading and buffering
|
|
21
|
+
*/
|
|
22
|
+
readonly loading: readonly ["loadstart", "loadeddata", "loadedmetadata", "canplay", "canplaythrough", "progress", "waiting", "durationchange"];
|
|
23
|
+
/**
|
|
24
|
+
* Media State Events - Volume, rate, dimensions
|
|
25
|
+
*/
|
|
26
|
+
readonly mediaState: readonly ["volumechange", "ratechange", "resize"];
|
|
27
|
+
/**
|
|
28
|
+
* Network/Error Events - Network issues and errors
|
|
29
|
+
*/
|
|
30
|
+
readonly network: readonly ["abort", "emptied", "stalled", "suspend", "error"];
|
|
31
|
+
/**
|
|
32
|
+
* Custom Player Events - Wontum Player specific
|
|
33
|
+
*/
|
|
34
|
+
readonly custom: readonly ["qualitychange", "fullscreenchange"];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Minimal event listener example
|
|
38
|
+
*/
|
|
39
|
+
export declare function minimalEventExample(): void;
|
|
40
|
+
/**
|
|
41
|
+
* React example with all events
|
|
42
|
+
*/
|
|
43
|
+
export declare const ReactAllEventsExample = "\nimport React from 'react';\nimport { WontumPlayerReact } from '@wontum/player';\n\nfunction VideoPlayerWithEvents() {\n return (\n <WontumPlayerReact\n src=\"https://media.domain.com/video.m3u8\"\n \n {/* Playback Events */}\n onPlay={(e) => console.log('Play', e)}\n onPause={(e) => console.log('Pause', e)}\n onPlaying={(e) => console.log('Playing', e)}\n onEnded={(e) => console.log('Ended', e)}\n onTimeupdate={(e) => console.log('Time:', e.data.currentTime)}\n \n {/* Seeking */}\n onSeeking={(e) => console.log('Seeking', e)}\n onSeeked={(e) => console.log('Seeked', e)}\n \n {/* Loading Events */}\n onLoadstart={(e) => console.log('Load Start', e)}\n onLoadeddata={(e) => console.log('Loaded Data', e)}\n onLoadedmetadata={(e) => console.log('Metadata', e)}\n onCanplay={(e) => console.log('Can Play', e)}\n onCanplaythrough={(e) => console.log('Can Play Through', e)}\n onProgress={(e) => console.log('Progress', e)}\n onWaiting={(e) => console.log('Buffering', e)}\n onDurationchange={(e) => console.log('Duration', e)}\n \n {/* Media State */}\n onVolumechange={(e) => console.log('Volume', e)}\n onRatechange={(e) => console.log('Rate', e)}\n onResize={(e) => console.log('Resize', e)}\n \n {/* Network/Error */}\n onAbort={(e) => console.log('Abort', e)}\n onEmptied={(e) => console.log('Emptied', e)}\n onStalled={(e) => console.log('Stalled', e)}\n onSuspend={(e) => console.log('Suspend', e)}\n onError={(e) => console.error('Error', e)}\n \n {/* Custom Events */}\n onQualitychange={(e) => console.log('Quality', e)}\n onFullscreenchange={(e) => console.log('Fullscreen', e)}\n />\n );\n}\n";
|
|
44
|
+
/**
|
|
45
|
+
* Compare with Mux Player events
|
|
46
|
+
*/
|
|
47
|
+
export declare const MuxPlayerCompatibility: {
|
|
48
|
+
muxPlayerEvents: string[];
|
|
49
|
+
wontumExtensions: string[];
|
|
50
|
+
allSupported: boolean;
|
|
51
|
+
totalEvents: number;
|
|
52
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { WontumPlayer } from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example 1: Basic public stream
|
|
5
|
+
*/
|
|
6
|
+
export declare function basicPublicStream(): WontumPlayer;
|
|
7
|
+
/**
|
|
8
|
+
* Example 2: With event logging
|
|
9
|
+
*/
|
|
10
|
+
export declare function publicStreamWithEvents(): WontumPlayer;
|
|
11
|
+
/**
|
|
12
|
+
* Example 3: Multiple quality levels
|
|
13
|
+
*/
|
|
14
|
+
export declare function adaptiveStreamTest(): WontumPlayer;
|
|
15
|
+
/**
|
|
16
|
+
* Public HLS Test Streams
|
|
17
|
+
*/
|
|
18
|
+
export declare const PUBLIC_TEST_STREAMS: {
|
|
19
|
+
appleBasic: string;
|
|
20
|
+
apple4K: string;
|
|
21
|
+
muxDemo: string;
|
|
22
|
+
bigBuckBunny: string;
|
|
23
|
+
tearsOfSteel: string;
|
|
24
|
+
sintel: string;
|
|
25
|
+
multiBitrate: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Quick test function - just paste into console
|
|
29
|
+
*/
|
|
30
|
+
export declare function quickTest(streamUrl?: string): WontumPlayer;
|
|
31
|
+
/**
|
|
32
|
+
* HTML Example for quick testing
|
|
33
|
+
*/
|
|
34
|
+
export declare const htmlExample = "\n<!DOCTYPE html>\n<html>\n<head>\n <title>Wontum Player Test</title>\n <style>\n body { \n margin: 0; \n padding: 20px; \n font-family: Arial, sans-serif; \n background: #1a1a1a;\n color: white;\n }\n #player { \n width: 100%; \n max-width: 1200px; \n height: 600px; \n background: #000;\n margin: 20px auto;\n }\n .info {\n max-width: 1200px;\n margin: 0 auto;\n padding: 20px;\n }\n </style>\n</head>\n<body>\n <div class=\"info\">\n <h1>\uD83C\uDFAC Wontum Player Test</h1>\n <p>Testing with public HLS stream (no authentication required)</p>\n </div>\n \n <div id=\"player\"></div>\n\n <script type=\"module\">\n import { WontumPlayer } from './dist/index.js';\n \n const player = new WontumPlayer({\n src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',\n container: '#player',\n autoplay: true,\n controls: true,\n analytics: {\n enabled: true\n }\n });\n\n // Log events\n player.on('loadedmetadata', (e) => {\n console.log('Duration:', e.data.duration);\n });\n \n player.on('play', () => console.log('Playing!'));\n player.on('pause', () => console.log('Paused'));\n player.on('error', (e) => console.error('Error:', e.data));\n \n // Make player available in console\n window.player = player;\n </script>\n</body>\n</html>\n";
|
|
35
|
+
/**
|
|
36
|
+
* React example with public stream
|
|
37
|
+
*/
|
|
38
|
+
export declare const reactPublicStreamExample = "\nimport React from 'react';\nimport { WontumPlayerReact } from '@wontum/player';\n\nfunction App() {\n return (\n <div style={{ width: '100%', height: '600px', background: '#000' }}>\n <WontumPlayerReact\n src=\"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8\"\n autoplay\n onLoadedmetadata={(e) => console.log('Duration:', e.data.duration)}\n onPlay={() => console.log('Playing!')}\n onError={(e) => console.error('Error:', e.data)}\n />\n </div>\n );\n}\n\nexport default App;\n";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example 1: Basic React Player
|
|
3
|
+
*/
|
|
4
|
+
export declare function BasicPlayer(): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
/**
|
|
6
|
+
* Example 2: Player with Event Handlers
|
|
7
|
+
*/
|
|
8
|
+
export declare function PlayerWithEvents(): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
/**
|
|
10
|
+
* Example 3: Custom Controls with useWontumPlayer Hook
|
|
11
|
+
*/
|
|
12
|
+
export declare function CustomControls(): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function S3Player(): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* Example 5: Player with Analytics
|
|
16
|
+
*/
|
|
17
|
+
export declare function AnalyticsPlayer({ videoId, userId }: {
|
|
18
|
+
videoId: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
/**
|
|
22
|
+
* Example 6: Playlist Player
|
|
23
|
+
*/
|
|
24
|
+
export declare function PlaylistPlayer(): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
/**
|
|
26
|
+
* Example 7: Player with Custom Theme
|
|
27
|
+
*/
|
|
28
|
+
export declare function ThemedPlayer(): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
/**
|
|
30
|
+
* Example 8: Responsive Player
|
|
31
|
+
*/
|
|
32
|
+
export declare function ResponsivePlayer(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { WontumPlayer } from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example 1: Basic Player Setup
|
|
5
|
+
*/
|
|
6
|
+
declare function basicPlayerExample(): WontumPlayer;
|
|
7
|
+
/**
|
|
8
|
+
* Example 2: Player with Event Listeners
|
|
9
|
+
*/
|
|
10
|
+
declare function playerWithEventsExample(): WontumPlayer;
|
|
11
|
+
/**
|
|
12
|
+
* Example 3: Programmatic Control
|
|
13
|
+
*/
|
|
14
|
+
declare function programmaticControlExample(): WontumPlayer;
|
|
15
|
+
/**
|
|
16
|
+
* Example 4: S3 Integration
|
|
17
|
+
* Note: Install AWS SDK with: npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner
|
|
18
|
+
*/
|
|
19
|
+
declare function s3IntegrationExample(): Promise<WontumPlayer>;
|
|
20
|
+
/**
|
|
21
|
+
* Example 5: Backend Presigned URL Generation
|
|
22
|
+
*/
|
|
23
|
+
declare function backendPresignedUrlExample(): Promise<WontumPlayer>;
|
|
24
|
+
/**
|
|
25
|
+
* Example 6: Analytics Integration
|
|
26
|
+
*/
|
|
27
|
+
declare function analyticsExample(): WontumPlayer;
|
|
28
|
+
/**
|
|
29
|
+
* Example 7: Quality Selection
|
|
30
|
+
*/
|
|
31
|
+
declare function qualitySelectionExample(): WontumPlayer;
|
|
32
|
+
/**
|
|
33
|
+
* Example 8: Multiple Players on One Page
|
|
34
|
+
*/
|
|
35
|
+
declare function multiplePlayersExample(): WontumPlayer[];
|
|
36
|
+
/**
|
|
37
|
+
* Example 9: Custom HLS Configuration
|
|
38
|
+
*/
|
|
39
|
+
declare function customHlsConfigExample(): WontumPlayer;
|
|
40
|
+
/**
|
|
41
|
+
* Example 10: Playlist with Auto-advance
|
|
42
|
+
*/
|
|
43
|
+
declare function playlistExample(): {
|
|
44
|
+
next: () => void;
|
|
45
|
+
previous: () => void;
|
|
46
|
+
goto: (index: number) => void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Example 11: Save and Resume Playback Position
|
|
50
|
+
*/
|
|
51
|
+
declare function saveResumeExample(): WontumPlayer;
|
|
52
|
+
/**
|
|
53
|
+
* Example 12: Picture-in-Picture
|
|
54
|
+
*/
|
|
55
|
+
declare function pictureInPictureExample(): Promise<WontumPlayer>;
|
|
56
|
+
export { basicPlayerExample, playerWithEventsExample, programmaticControlExample, s3IntegrationExample, backendPresignedUrlExample, analyticsExample, qualitySelectionExample, multiplePlayersExample, customHlsConfigExample, playlistExample, saveResumeExample, pictureInPictureExample, };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/index'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AnalyticsConfig, AnalyticsEvent } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Analytics - Tracks player events and quality metrics
|
|
5
|
+
*/
|
|
6
|
+
export declare class Analytics {
|
|
7
|
+
private config;
|
|
8
|
+
private sessionId;
|
|
9
|
+
private events;
|
|
10
|
+
private sessionStartTime;
|
|
11
|
+
private playbackStartTime;
|
|
12
|
+
private totalPlayTime;
|
|
13
|
+
private totalBufferTime;
|
|
14
|
+
private bufferStartTime;
|
|
15
|
+
private rebufferCount;
|
|
16
|
+
private seekCount;
|
|
17
|
+
constructor(config?: AnalyticsConfig);
|
|
18
|
+
trackEvent(eventType: string, data?: Record<string, any>): void;
|
|
19
|
+
private updateMetrics;
|
|
20
|
+
private getQoEMetrics;
|
|
21
|
+
private getSessionData;
|
|
22
|
+
private getConnectionInfo;
|
|
23
|
+
private sendEvent;
|
|
24
|
+
private generateSessionId;
|
|
25
|
+
getEvents(): AnalyticsEvent[];
|
|
26
|
+
getMetrics(): Record<string, any>;
|
|
27
|
+
destroy(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { WontumPlayer } from './player';
|
|
2
|
+
export { Analytics } from './analytics';
|
|
3
|
+
export { S3Handler } from './s3-handler';
|
|
4
|
+
export { UIController } from './ui-controller';
|
|
5
|
+
export { WontumPlayerReact, useWontumPlayer, WontumPlayerProvider, useWontumPlayerContext } from './react';
|
|
6
|
+
export type { WontumPlayerConfig, PlayerTheme, S3Config, AnalyticsConfig, PlayerState, PlayerEvent, PlayerEventType, AnalyticsEvent, QualityLevel } from './types';
|
|
7
|
+
export type { WontumPlayerReactProps } from './react';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { WontumPlayerConfig, PlayerState, PlayerEvent, PlayerEventType } from './types';
|
|
2
|
+
import { Analytics } from './analytics';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WontumPlayer - A modern HLS video player for educational platforms
|
|
6
|
+
*/
|
|
7
|
+
export declare class WontumPlayer {
|
|
8
|
+
private container;
|
|
9
|
+
private videoElement;
|
|
10
|
+
private hls;
|
|
11
|
+
private config;
|
|
12
|
+
private eventListeners;
|
|
13
|
+
analytics: Analytics;
|
|
14
|
+
private s3Handler;
|
|
15
|
+
private uiController;
|
|
16
|
+
private state;
|
|
17
|
+
constructor(config: WontumPlayerConfig);
|
|
18
|
+
private addSubtitleTracks;
|
|
19
|
+
private createVideoElement;
|
|
20
|
+
private setupVideoListeners;
|
|
21
|
+
private loadSource;
|
|
22
|
+
private extractQualities;
|
|
23
|
+
private handleHlsError;
|
|
24
|
+
private getAnalyticsData;
|
|
25
|
+
play(): Promise<void>;
|
|
26
|
+
pause(): void;
|
|
27
|
+
seek(time: number): void;
|
|
28
|
+
skipForward(seconds?: number): void;
|
|
29
|
+
skipBackward(seconds?: number): void;
|
|
30
|
+
setVolume(volume: number): void;
|
|
31
|
+
mute(): void;
|
|
32
|
+
unmute(): void;
|
|
33
|
+
setPlaybackRate(rate: number): void;
|
|
34
|
+
setQuality(qualityIndex: number): void;
|
|
35
|
+
enterFullscreen(): void;
|
|
36
|
+
exitFullscreen(): void;
|
|
37
|
+
getState(): PlayerState;
|
|
38
|
+
getVideoElement(): HTMLVideoElement;
|
|
39
|
+
/**
|
|
40
|
+
* Enable subtitles for a specific track
|
|
41
|
+
*/
|
|
42
|
+
enableSubtitles(trackIndex: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Disable all subtitles
|
|
45
|
+
*/
|
|
46
|
+
disableSubtitles(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Toggle subtitles on/off
|
|
49
|
+
*/
|
|
50
|
+
toggleSubtitles(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get available subtitle tracks
|
|
53
|
+
*/
|
|
54
|
+
getSubtitleTracks(): TextTrack[];
|
|
55
|
+
/**
|
|
56
|
+
* Check if subtitles are currently enabled
|
|
57
|
+
*/
|
|
58
|
+
areSubtitlesEnabled(): boolean;
|
|
59
|
+
on(eventType: PlayerEventType, callback: (event: PlayerEvent) => void): void;
|
|
60
|
+
off(eventType: PlayerEventType, callback: (event: PlayerEvent) => void): void;
|
|
61
|
+
private emit;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { WontumPlayer } from './player';
|
|
3
|
+
import { WontumPlayerConfig, PlayerState } from './types';
|
|
4
|
+
|
|
5
|
+
export interface WontumPlayerReactProps extends Omit<WontumPlayerConfig, "container"> {
|
|
6
|
+
/** Callback when player is ready */
|
|
7
|
+
onReady?: (player: WontumPlayer) => void;
|
|
8
|
+
/** Callback for player events */
|
|
9
|
+
onPlay?: () => void;
|
|
10
|
+
onPause?: () => void;
|
|
11
|
+
onEnded?: () => void;
|
|
12
|
+
onTimeUpdate?: (currentTime: number) => void;
|
|
13
|
+
onVolumeChange?: (volume: number, muted: boolean) => void;
|
|
14
|
+
onError?: (error: any) => void;
|
|
15
|
+
/** Container style */
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
/** Container className */
|
|
18
|
+
className?: string;
|
|
19
|
+
/** Width of player */
|
|
20
|
+
width?: string | number;
|
|
21
|
+
/** Height of player */
|
|
22
|
+
height?: string | number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* WontumPlayerReact - React component wrapper for WontumPlayer
|
|
26
|
+
*/
|
|
27
|
+
export declare const WontumPlayerReact: React.FC<WontumPlayerReactProps>;
|
|
28
|
+
/**
|
|
29
|
+
* useWontumPlayer - React hook for imperative player control
|
|
30
|
+
*/
|
|
31
|
+
export declare const useWontumPlayer: (config: Omit<WontumPlayerConfig, "container">) => {
|
|
32
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
33
|
+
player: WontumPlayer | null;
|
|
34
|
+
state: PlayerState | null;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* WontumPlayerProvider - Context provider for player instance
|
|
38
|
+
*/
|
|
39
|
+
interface WontumPlayerContextValue {
|
|
40
|
+
player: WontumPlayer | null;
|
|
41
|
+
state: PlayerState | null;
|
|
42
|
+
}
|
|
43
|
+
export declare const WontumPlayerProvider: React.FC<{
|
|
44
|
+
player: WontumPlayer;
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
}>;
|
|
47
|
+
export declare const useWontumPlayerContext: () => WontumPlayerContextValue;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { S3Config } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* S3Handler - Manages S3/CloudFront URLs and signed cookie authentication
|
|
5
|
+
*/
|
|
6
|
+
export declare class S3Handler {
|
|
7
|
+
private config;
|
|
8
|
+
private urlCache;
|
|
9
|
+
private signedUrls;
|
|
10
|
+
constructor(config?: S3Config);
|
|
11
|
+
/**
|
|
12
|
+
* Process a URL - sign with CloudFront cookies or generate presigned URL for S3
|
|
13
|
+
*/
|
|
14
|
+
processUrl(url: string): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Check if URL is a CloudFront URL that needs signing
|
|
17
|
+
*/
|
|
18
|
+
private isCloudFrontUrl;
|
|
19
|
+
/**
|
|
20
|
+
* Check if URL is an S3 URL
|
|
21
|
+
*/
|
|
22
|
+
private isS3Url;
|
|
23
|
+
/**
|
|
24
|
+
* Sign CloudFront URL by calling the signing endpoint
|
|
25
|
+
* The endpoint should set signed cookies and return the URL
|
|
26
|
+
*/
|
|
27
|
+
private signCloudFrontUrl;
|
|
28
|
+
/**
|
|
29
|
+
* Extract S3 key from URL
|
|
30
|
+
*/
|
|
31
|
+
private extractS3Key;
|
|
32
|
+
/**
|
|
33
|
+
* Get presigned URL from cache or generate new one
|
|
34
|
+
*/
|
|
35
|
+
private getPresignedUrl;
|
|
36
|
+
/**
|
|
37
|
+
* Helper to construct S3 URL from bucket and key
|
|
38
|
+
*/
|
|
39
|
+
static constructS3Url(bucket: string, key: string, region?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Helper to parse S3 URI (s3://bucket/key)
|
|
42
|
+
*/
|
|
43
|
+
static parseS3Uri(uri: string): {
|
|
44
|
+
bucket: string;
|
|
45
|
+
key: string;
|
|
46
|
+
} | null;
|
|
47
|
+
/**
|
|
48
|
+
* Clear URL cache and signed URLs
|
|
49
|
+
*/
|
|
50
|
+
clearCache(): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Example CloudFront signed cookie implementation:
|
|
54
|
+
*
|
|
55
|
+
* async function signUrl(url: string): Promise<string> {
|
|
56
|
+
* const response = await fetch('/api/cloudfront/sign', {
|
|
57
|
+
* method: 'POST',
|
|
58
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
* body: JSON.stringify({ url }),
|
|
60
|
+
* credentials: 'include' // Important: include cookies in request
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const data = await response.json();
|
|
64
|
+
* // Backend sets CloudFront signed cookies in response
|
|
65
|
+
* // and returns the original URL
|
|
66
|
+
* return data.url;
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* const player = new WontumPlayer({
|
|
70
|
+
* src: 'https://media.domain.com/path/to/video/index.m3u8',
|
|
71
|
+
* container: '#player',
|
|
72
|
+
* s3Config: {
|
|
73
|
+
* signUrl,
|
|
74
|
+
* cloudFrontDomains: ['media.domain.com']
|
|
75
|
+
* }
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* ---
|
|
79
|
+
*
|
|
80
|
+
* Legacy S3 presigned URL example:
|
|
81
|
+
*
|
|
82
|
+
* import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
83
|
+
* import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
84
|
+
*
|
|
85
|
+
* const s3Client = new S3Client({ region: 'us-east-1' });
|
|
86
|
+
*
|
|
87
|
+
* async function getPresignedUrl(key: string): Promise<string> {
|
|
88
|
+
* const command = new GetObjectCommand({
|
|
89
|
+
* Bucket: 'your-bucket-name',
|
|
90
|
+
* Key: key,
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* return getSignedUrl(s3Client, command, { expiresIn: 3600 });
|
|
94
|
+
* }
|
|
95
|
+
*/
|