@therealtinhtute/baroiplayer 1.0.2 → 1.0.4

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.
@@ -57,7 +57,13 @@ export const useIntelligentPreloading = (
57
57
  lastInteraction: Date.now(),
58
58
  });
59
59
 
60
- const networkInfoRef = useRef<NetworkInformation | null>(null);
60
+ // Network Information API (if available)
61
+ const networkInfoRef = useRef<{
62
+ effectiveType?: string;
63
+ downlink?: number;
64
+ rtt?: number;
65
+ saveData?: boolean;
66
+ } | null>(null);
61
67
  const preloadedItemsRef = useRef<Set<string>>(new Set());
62
68
  const preloadQueueRef = useRef<Array<{ source: MediaSource; priority: number }>>([]);
63
69
 
@@ -89,7 +95,7 @@ export const useIntelligentPreloading = (
89
95
 
90
96
  const network = networkInfoRef.current;
91
97
  return {
92
- type: network.type,
98
+ type: network.effectiveType || '4g', // Use effectiveType as the primary type indicator
93
99
  downlink: network.downlink || 10,
94
100
  effectiveType: network.effectiveType || '4g',
95
101
  saveData: network.saveData || false,
@@ -156,8 +162,9 @@ export const useIntelligentPreloading = (
156
162
 
157
163
  // Additional heuristics
158
164
  if (shouldPreload) {
159
- // Prioritize HLS and adaptive streaming
160
- if (source.type === 'hls' || source.type === 'm3u8') {
165
+ // Prioritize HLS and adaptive streaming (check URL extension)
166
+ const sourceUrl = source.src.toLowerCase();
167
+ if (sourceUrl.includes('.m3u8') || sourceUrl.includes('hls')) {
161
168
  priority = priority === 'low' ? 'medium' : 'high';
162
169
  }
163
170
 
@@ -168,7 +175,8 @@ export const useIntelligentPreloading = (
168
175
  }
169
176
 
170
177
  // Consider content type (video gets higher priority than audio)
171
- if (source.type === 'mp4' || source.type === 'webm') {
178
+ if (source.type?.includes('mp4') || source.type?.includes('webm') ||
179
+ sourceUrl.includes('.mp4') || sourceUrl.includes('.webm')) {
172
180
  priority = priority === 'low' ? 'medium' : priority;
173
181
  }
174
182
  }
@@ -184,23 +192,20 @@ export const useIntelligentPreloading = (
184
192
  link.rel = 'preload';
185
193
  link.href = source.src;
186
194
 
187
- // Determine the correct 'as' attribute
188
- switch (source.type) {
189
- case 'hls':
190
- case 'm3u8':
191
- link.as = 'fetch';
192
- break;
193
- case 'mp4':
194
- case 'webm':
195
- link.as = 'video';
196
- break;
197
- case 'mp3':
198
- case 'wav':
199
- case 'ogg':
200
- link.as = 'audio';
201
- break;
202
- default:
203
- link.as = 'fetch';
195
+ // Determine the correct 'as' attribute based on URL or MIME type
196
+ const sourceUrl = source.src.toLowerCase();
197
+ const mimeType = source.type?.toLowerCase() || '';
198
+
199
+ if (sourceUrl.includes('.m3u8') || sourceUrl.includes('hls')) {
200
+ link.as = 'fetch';
201
+ } else if (mimeType.includes('mp4') || mimeType.includes('webm') ||
202
+ sourceUrl.includes('.mp4') || sourceUrl.includes('.webm')) {
203
+ link.as = 'video';
204
+ } else if (mimeType.includes('mp3') || mimeType.includes('wav') || mimeType.includes('ogg') ||
205
+ sourceUrl.includes('.mp3') || sourceUrl.includes('.wav') || sourceUrl.includes('.ogg')) {
206
+ link.as = 'audio';
207
+ } else {
208
+ link.as = 'fetch';
204
209
  }
205
210
 
206
211
  link.crossOrigin = 'anonymous';
@@ -295,8 +295,6 @@ export function useMediaPlayer(options: UseMediaPlayerOptions) {
295
295
  toggle,
296
296
  seek,
297
297
  setVolume: setVolumeControl,
298
- mute,
299
- unmute,
300
298
  toggleMute,
301
299
  enterFullscreen,
302
300
  exitFullscreen,
@@ -16,10 +16,10 @@ export function useMemoryOptimization(options: {
16
16
  monitorMemory = true
17
17
  } = options
18
18
 
19
- const cleanupTimeoutRef = useRef<NodeJS.Timeout>()
19
+ const cleanupTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined)
20
20
  const observersRef = useRef<Set<MutationObserver>>(new Set())
21
21
  const eventListenersRef = useRef<Map<Element, Array<{ event: string; handler: EventListener }>>>(new Map())
22
- const intervalRefs = useRef<Set<NodeJS.Timeout>>(new Set())
22
+ const intervalRefs = useRef<Set<ReturnType<typeof setInterval>>>(new Set()) // Use proper timer type
23
23
  const animationFrameRefs = useRef<Set<number>>(new Set())
24
24
 
25
25
  // Get current memory usage
@@ -67,20 +67,20 @@ export function useMemoryOptimization(options: {
67
67
  }
68
68
 
69
69
  checkMemory()
70
- const interval = setInterval(checkMemory, cleanupInterval)
71
- intervalRefs.current.add(interval)
70
+ const intervalId: ReturnType<typeof setInterval> = setInterval(checkMemory, cleanupInterval)
71
+ intervalRefs.current.add(intervalId)
72
72
 
73
73
  return () => {
74
- clearInterval(interval)
75
- intervalRefs.current.delete(interval)
74
+ clearInterval(intervalId as any)
75
+ intervalRefs.current.delete(intervalId)
76
76
  }
77
77
  }, [monitorMemory, getMemoryUsage, maxMemoryUsage, enableGC, cleanupInterval])
78
78
 
79
79
  // Cleanup function
80
80
  const performCleanup = useCallback(() => {
81
- // Clear all timeouts
82
- intervalRefs.current.forEach(timeout => {
83
- clearTimeout(timeout)
81
+ // Clear all intervals
82
+ intervalRefs.current.forEach(intervalId => {
83
+ clearInterval(intervalId as any)
84
84
  })
85
85
  intervalRefs.current.clear()
86
86
 
@@ -141,29 +141,29 @@ export function useMemoryOptimization(options: {
141
141
  }, [])
142
142
 
143
143
  // Safe interval management
144
- const setInterval = useCallback((callback: () => void, delay: number) => {
144
+ const safeSetInterval = useCallback((callback: () => void, delay: number) => {
145
145
  const timeoutId = setInterval(callback, delay)
146
146
  intervalRefs.current.add(timeoutId)
147
147
 
148
148
  return () => {
149
- clearInterval(timeoutId)
149
+ clearInterval(timeoutId as any)
150
150
  intervalRefs.current.delete(timeoutId)
151
151
  }
152
152
  }, [])
153
153
 
154
154
  // Safe timeout management
155
- const setTimeout = useCallback((callback: () => void, delay: number) => {
155
+ const safeSetTimeout = useCallback((callback: () => void, delay: number) => {
156
156
  const timeoutId = setTimeout(callback, delay)
157
157
  intervalRefs.current.add(timeoutId)
158
158
 
159
159
  return () => {
160
- clearTimeout(timeoutId)
160
+ clearTimeout(timeoutId as any)
161
161
  intervalRefs.current.delete(timeoutId)
162
162
  }
163
163
  }, [])
164
164
 
165
165
  // Safe animation frame management
166
- const requestAnimationFrame = useCallback((callback: FrameRequestCallback) => {
166
+ const safeRequestAnimationFrame = useCallback((callback: FrameRequestCallback) => {
167
167
  const frameId = requestAnimationFrame(callback)
168
168
  animationFrameRefs.current.add(frameId)
169
169
 
@@ -200,9 +200,9 @@ export function useMemoryOptimization(options: {
200
200
 
201
201
  // Safe API functions
202
202
  addEventListener,
203
- setInterval,
204
- setTimeout,
205
- requestAnimationFrame,
203
+ setInterval: safeSetInterval,
204
+ setTimeout: safeSetTimeout,
205
+ requestAnimationFrame: safeRequestAnimationFrame,
206
206
  addObserver,
207
207
 
208
208
  // Utilities
@@ -227,7 +227,7 @@ export function useMediaResourceCleanup(mediaRef: React.RefObject<HTMLVideoEleme
227
227
 
228
228
  // Stop media playback
229
229
  if (!media.paused) {
230
- _media.pause()
230
+ media.pause()
231
231
  }
232
232
 
233
233
  // Clear source
@@ -284,7 +284,7 @@ export function usePerformanceMonitoring() {
284
284
 
285
285
  const frameCountRef = useRef(0)
286
286
  const lastFrameTimeRef = useRef(performance.now())
287
- const longTaskObserverRef = useRef<PerformanceObserver>()
287
+ const longTaskObserverRef = useRef<PerformanceObserver | undefined>(undefined)
288
288
 
289
289
  // FPS monitoring
290
290
  useEffect(() => {
@@ -133,10 +133,11 @@ export { useEnhancedMediaPlayer } from "./hooks/use-enhanced-media-player"
133
133
  // Performance Monitoring
134
134
  export {
135
135
  PerformanceMonitor,
136
- PerformanceMetrics,
137
136
  usePerformanceMonitor as usePerformanceMonitoring
138
137
  } from "./core/performance"
139
138
 
139
+ export type { PerformanceMetrics } from "./core/performance"
140
+
140
141
  // Media Resource Preloader
141
142
  export { MediaResourcePreloader } from "./components/ui/media-resource-preloader"
142
143