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 (

Cross-Device Sync Demo

{/* Sync Status */}

Sync Status

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}

{/* Playback Controls */}

Playback Controls

handleVolumeChange(parseFloat(e.target.value))} style={{ marginLeft: '8px' }} /> {Math.round(volume * 100)}%
{/* Cache Intelligence */}

Cache Intelligence

Device Intelligence

Device Type: {intelligence.deviceType}

Frequently Played: {intelligence.frequentlyPlayed.length}

Recently Accessed: {intelligence.recentlyAccessed.length}

Cache Hit Rate: {(intelligence.cacheHitRate * 100).toFixed(1)}%

Statistics

Total Priorities: {stats.totalPriorities}

Average Priority: {stats.averagePriority.toFixed(1)}

Cross-Device Hints: {stats.crossDeviceHints}

Top Cache Recommendations

{topRecommendations.length > 0 ? ( topRecommendations.slice(0, 10).map((songId, index) => (
{index + 1}. {songId}
)) ) : (
No recommendations yet
)}
{/* Connected Devices */} {connectedDevices.length > 0 && (

Connected Devices

{connectedDevices.map(device => (
{device.name} ({device.type})
{device.isActive ? 'Active' : 'Inactive'}
))}
)}
); };