import React, { useState, useEffect } from 'react'; import { useCrossDeviceSync, usePlaybackSync } from '../hooks/useCrossDeviceSync'; import { useCacheIntelligence } from '../hooks/useCacheIntelligence'; import { CrossDeviceSyncIndicator } from './CrossDeviceSyncIndicator'; export const CrossDeviceSyncDemo: React.FC = () => { const { syncState, connectedDevices, isEnabled, enable, disable } = useCrossDeviceSync(); const { syncCurrentTrack, syncPlayingState, syncQueue, syncVolumeChange } = usePlaybackSync(); const { intelligence, topRecommendations, recordSongPlay, getStats } = useCacheIntelligence(); const [demoTrack, setDemoTrack] = useState('demo-track-1'); const [isPlaying, setIsPlaying] = useState(false); const [volume, setVolume] = useState(0.8); // Simulate playback state changes const handlePlayPause = () => { const newPlayingState = !isPlaying; setIsPlaying(newPlayingState); // Sync the state across devices syncPlayingState(newPlayingState); if (newPlayingState) { syncCurrentTrack(demoTrack, 0); } }; const handleTrackChange = (trackId: string) => { setDemoTrack(trackId); syncCurrentTrack(trackId, 0); // Record song access for cache intelligence recordSongPlay(trackId); }; const handleVolumeChange = (newVolume: number) => { setVolume(newVolume); syncVolumeChange(newVolume); }; const handleQueueUpdate = () => { const mockQueue = [ { Id: 'track-1', Name: 'Song 1', Artist: 'Artist 1' }, { Id: 'track-2', Name: 'Song 2', Artist: 'Artist 2' }, { Id: 'track-3', Name: 'Song 3', Artist: 'Artist 3' } ] as any[]; syncQueue(mockQueue); }; const stats = getStats(); return (
Enabled: {isEnabled ? 'Yes' : 'No'}
Connected Devices: {connectedDevices.length}
Current Track: {syncState.currentTrack || 'None'}
Is Playing: {syncState.isPlaying ? 'Yes' : 'No'}
Queue Length: {syncState.queue.length}
Cache Hints: {syncState.cacheHints.length}
Device Type: {intelligence.deviceType}
Frequently Played: {intelligence.frequentlyPlayed.length}
Recently Accessed: {intelligence.recentlyAccessed.length}
Cache Hit Rate: {(intelligence.cacheHitRate * 100).toFixed(1)}%
Total Priorities: {stats.totalPriorities}
Average Priority: {stats.averagePriority.toFixed(1)}
Cross-Device Hints: {stats.crossDeviceHints}