Commit Graph

7996 Commits

Author SHA1 Message Date
Nuwan ad12d4030a chore: untrack .claude/settings.local.json from version control
Removed .claude/settings.local.json from git tracking since it's now
in .gitignore. The file will remain on disk but won't be tracked by git.

This completes the setup to keep user-specific Claude Code settings local.
2026-01-23 15:47:20 +05:30
Nuwan d9f697de7b chore: add Claude Code local settings to .gitignore
Added .claude/settings.local.json to .gitignore to prevent user-specific
Claude Code CLI settings from being committed to version control.

These settings contain local paths and session-specific permissions that
are unique to each developer's environment.
2026-01-23 15:46:10 +05:30
Nuwan b5f7f25698 test: add Playwright test infrastructure for session flow verification
Added comprehensive test infrastructure to verify session join flow and
track sync implementation:

Test Configuration:
- playwright.chrome.config.ts: Chrome-specific test configuration
- playwright.verification.config.ts: Verification test settings

Test Documentation:
- IMPLEMENTATION_APPROACH.md: TDD approach for trackSync
- JAM_UI_TESTING_PLAN.md: Overall testing strategy

Test Utilities:
- api-interceptor.ts: Intercepts and logs API calls
- websocket-monitor.ts: Monitors WebSocket messages
- sequence-comparator.ts: Compares API call sequences
- test-helpers.ts: Shared test helper functions

Test Suites:
- e2e/complete-session-flow.spec.ts: Full session flow E2E test
- api-verification/*.spec.ts: API call verification tests
- websocket-verification/ws-connection.spec.ts: WebSocket tests
- capture-session-flow*.spec.ts: Session flow analysis tests

Test Fixtures & Results:
- fixtures/legacy-sequences/: Recorded API call sequences
- test-results/: Test output, comparisons, and analysis

These tests were instrumental in debugging the VU meter issue and
verifying the trackSync implementation.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-23 15:42:35 +05:30
Nuwan 23594959f3 docs: add VU meter fix documentation and test results
Added comprehensive documentation of the VU meter race condition fix:
- VU_METER_FIX_SUMMARY.md: Detailed root cause analysis and solution
- VU_METER_INVESTIGATION.md: Updated with test results

Documents the race condition between trackSync and mixer initialization,
the solution using mixersReady dependency, and testing evidence.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-23 14:57:39 +05:30
Nuwan 5645284511 fix: resolve VU meter race condition by waiting for mixers ready
Fixed issue where VU meters were not lighting up on session join due to
a race condition between mixer initialization and track sync.

## Root Cause
When hasJoined became true, both the mixer initialization effect and the
trackSync effect would fire simultaneously. TrackSync was executing before
mixers were fully organized, causing isReady to still be false when VU
updates started coming in. This resulted in all VU updates being rejected.

## Solution
1. Added mixersReady dependency to trackSync effect in JKSessionScreen
2. TrackSync now waits until mixers are fully initialized before scheduling
   API calls
3. This ensures proper happens-before relationship:
   Session joined → Mixers fetched → organizeMixers → isReady=true → TrackSync

## Changes
- JKSessionScreen.js: Added mixersReady selector and dependency
- useMixerHelper.js: Added minimal logging for isReady state changes
- trackSyncService.js: Changed to accept clientId string instead of jamClient
  - Fixes "Client ID not available" issue by using server.clientId
- trackSyncService.test.js: Updated tests to pass clientId directly

## Testing
Verified VU meters now light up correctly within 1-2 seconds of session join.
TrackSync still executes at 1s, 1.4s, and 6s as expected.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-23 14:55:45 +05:30
Nuwan 68f9eb607b Merge branch 'feature/track-sync-implementation' into session_migration_plan 2026-01-23 13:36:35 +05:30
Nuwan b5850e2aec docs: add VU meter investigation documentation
- Document soft reset process to isolate trackSync impact
- Preserve verification results
- Add testing instructions for VU meter functionality
2026-01-23 13:35:47 +05:30
Nuwan e48048ac4e WIP: Track sync implementation with TDD approach
- Implemented trackSyncService with full test coverage
- Added 13 unit tests (all passing)
- Added 7 integration tests
- Wired up track sync in session join, instrument change, and media actions
- Fixed jamClient.clientID() async call issue
- Fixed hasJoined vs sessionJoined property mismatch

Note: Rails API endpoint PUT /api/sessions/:id/tracks still needs implementation
Note: Investigating VU meter issue that may be unrelated to this feature
2026-01-23 12:28:40 +05:30
Nuwan 4d141c93c0 feat: integrate metronome UI into session screen
Adds metronome display to JKSessionScreen:
- Imports JKSessionMetronome and JKSessionMetronomePlayer
- Redux selector for metronomeTrackMixers
- handleMetronomeClose callback with jamClient.SessionCloseMetronome
- Metronome track section (conditional on metronomeState.isOpen)
- WindowPortal popup for metronome controls

Updates handleMetronomeSelected to call updateMetronomeState
immediately when metronome opens, triggering popup display.

Completes full metronome feature: popup + track display + audio.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 19:05:35 +05:30
Nuwan fc3bbeeafe feat: implement mixer categorization by group_id
Adds useEffect to categorize mixers into track-specific arrays:
- metronomeTrackMixers (group_id: 16)
- backingTrackMixers (group_id: 11)
- jamTrackMixers (group_id: 12)
- recordingTrackMixers (group_id: 13)
- adhocTrackMixers (other types)

Each mixer categorized as {master, personal, mixer} pair.
Dispatches to Redux for component consumption.

Resolves TODO at line 243 about groupMixersByType logic.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 19:05:27 +05:30
Nuwan be3d39bff6 feat: add metronome track display component
Implements JKSessionMetronome track strip for session screen with:
- Metronome icon with fallback
- Horizontal VU meters (SessionTrackVU)
- Vertical volume fader (SessionTrackGain)
- Close button

Follows JKSessionBackingTrack pattern for consistency.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 19:05:19 +05:30
Nuwan fa5f8c97cb feat: add metronome player popup component
Implements JKSessionMetronomePlayer with controls for:
- Tempo slider/input (BPM: 40-300)
- Sound selector (Beep, Click, Kick, Snare, etc.)
- Meter selector (1-12)
- Visual metronome toggle (Cricket)
- Apply and Close buttons

Supports both WindowPortal popup mode and Modal fallback.
Uses jamClient.SessionSetMetronome to apply settings.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 19:05:13 +05:30
Nuwan 4fa9ed17fd fix(05-03): prevent tracks from disappearing when metronome clicked
Fixed critical bug where all tracks (Audio Inputs and Session Mix) disappeared
when user clicked "Open" → "Metronome".

Root cause: useEffect in JKSessionScreen.js depended on entire sessionHelper
object, which got new reference whenever currentSession updated (including when
metronome_open flag changed). This triggered unnecessary onSessionChange() calls
that refetched all mixers, causing race condition where myTracks became empty.

Changes:
1. **JKSessionScreen.js (line 540)**: Changed useEffect dependency from
   `sessionHelper` to `sessionHelper.id()` (primitive value that only changes
   when session ID changes, not on metadata updates)

2. **useMixerHelper.js (lines 63, 388-396, 453-454)**: Added previousMyTracksRef
   to store last known good myTracks. Returns previous value instead of empty
   array when allMixers is temporarily empty during state transitions.

3. **useMixerStore.js (lines 198-201, 213-220, 231)**: Added verification logging
   to confirm onSessionChange is not called unnecessarily. Can be removed after
   testing confirms fix works.

Expected behavior after fix:
-  Tracks DO NOT disappear when metronome clicked
-  onSessionChange only called on initial session join, not on metadata updates
-  Audio Inputs and Session Mix remain visible throughout metronome operations
-  Backing tracks and jam tracks still work correctly (regression test)

NOTE: This fix does NOT implement metronome UI display. Metronome audio will
play but no mixer controls will appear in session screen. That can be added
later as separate task.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 16:39:20 +05:30
Nuwan d264241c78 chore(05-03): clean up debug logging after finding root cause 2026-01-16 13:14:12 +05:30
Nuwan 56573c6db7 fix(05-03): parse session response before passing to updateSessionInfo
CRITICAL BUG:
- refreshCurrentSessionRest passed raw Response object to updateSessionInfo
- Should parse with response.json() first
- Caused two major issues:

ISSUE 1: Redux Serialization Error
- Response object dispatched to Redux (non-serializable)
- Error: "A non-serializable value was detected in an action"

ISSUE 2: Backing Tracks Never Extracted
- updateSessionInfo received Response instead of parsed data
- response.participants was undefined (Response has no participants property)
- Backing track extraction code never ran
- mixerHelper.backingTracks stayed empty

SOLUTION:
Parse response before passing to updateSessionInfo:
  const response = await getSession(currentSessionIdRef.current);
  const data = await response.json();  // ← ADDED
  updateSessionInfo(data, callback, force);

Now data.participants exists and backing tracks are extracted correctly.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 13:13:50 +05:30
Nuwan 3c2930092b debug(05-03): add detailed logging for alert callback flow 2026-01-16 13:11:08 +05:30
Nuwan a88beb3f4e fix(05-03): register alert callback to receive backend mixer changes
PROBLEM:
- onBackendMixerChanged never being called
- No [HandleAlertCallback] logs
- Backing track changes not triggering session refresh

ROOT CAUSE:
- Alert callback never registered with native client
- In legacy code: jamClient.SessionSetAlertCallback("JK.AlertCallback")
- React app had no equivalent setup
- Backend mixer change alerts (type=2) never delivered to app
- So onBackendMixerChanged never called, session never refreshed

SOLUTION:
1. Add JK.HandleAlertCallback global function in JKSessionScreen
2. Routes BACKEND_MIXER_CHANGE (type=2) to sessionModel.onBackendMixerChanged
3. Register callback with jamClient.SessionSetAlertCallback on session join
4. Unregister callback on session leave for cleanup

FLOW NOW:
1. User opens backing track via jamClient
2. Native client detects change
3. Native client calls JK.HandleAlertCallback(type=2, 'RebuildMediaControl')
4. Handler routes to sessionModel.onBackendMixerChanged()
5. Syncs tracks and calls refreshCurrentSession()
6. REST API returns session with participants[].backing_tracks
7. updateSessionInfo() extracts and dispatches to Redux
8. mixerHelper.backingTracks populated
9. Component displays backing track

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 13:06:20 +05:30
Nuwan e4651ae1cb fix(05-03): trigger session refresh when backing tracks change
PROBLEM:
- Backing track still not appearing in session screen after previous fix
- updateSessionInfo() extraction code not being called

ROOT CAUSE:
- onBackendMixerChanged() handler detects when backing tracks change
- It calls syncTracks() to update server but doesn't refresh session
- Without refreshCurrentSession(), the REST API is never called
- So updateSessionInfo() never runs and backing tracks never extracted

SOLUTION:
- Call refreshCurrentSession(true) after syncTracks() when backing tracks change
- Also add for metronome changes for consistency
- Now the full flow works:
  1. User opens backing track via jamClient
  2. Backend mixer changes, triggers 'RebuildMediaControl'
  3. onBackendMixerChanged detects backing track change
  4. Syncs tracks to server
  5. Refreshes session from server (REST API call)
  6. updateSessionInfo extracts backing tracks from response
  7. Dispatches to Redux mediaSlice
  8. mixerHelper.backingTracks populated
  9. Component displays backing track

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 12:59:43 +05:30
Nuwan 973d0c6ef2 chore(05-03): clean up debug logs and document MIXER_CHANGES handler
- Remove debug logs from JKSessionScreen backing track display
- Add comment to MIXER_CHANGES handler explaining it's not currently used
- Document that media arrays are now extracted from REST API in useSessionModel

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 12:16:34 +05:30
Nuwan 251788d799 fix(05-03): extract backing tracks from session response to Redux
PROBLEM:
- mixerHelper.backingTracks was always empty/null
- Backing track not appearing in session screen
- useSessionWebSocket had MIXER_CHANGES callback that never fired

ROOT CAUSE:
- MIXER_CHANGES WebSocket message doesn't exist on server
- Backing track data comes from REST API /api/sessions/:id response
- Session data stored in activeSessionSlice but never extracted to mediaSlice
- useMixerHelper reads from mediaSlice.backingTracks which was never populated

SOLUTION:
- Import mediaSlice actions (setBackingTracks, setJamTracks, setRecordedTracks) in useSessionModel
- Update updateSessionInfo() to extract backing tracks from session.participants[].backing_tracks
- Dispatch extracted arrays to Redux mediaSlice when session updates
- Also extract jamTracks and recordedTracks for consistency

DATA FLOW:
1. User opens backing track via jamClient.SessionOpenBackingTrackFile()
2. Server updates session state
3. Server sends TRACKS_CHANGED WebSocket message
4. Client calls refreshCurrentSession() -> REST API /api/sessions/:id
5. Response includes participants with backing_tracks (containing mixers)
6. updateSessionInfo() extracts backing tracks and dispatches to Redux
7. useMixerHelper reads from mediaSlice.backingTracks
8. Components access via mixerHelper.backingTracks

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 12:16:02 +05:30
Nuwan c487679fc8 debug(05-03): add comprehensive logging for backing track display
Adds detailed console logging to trace backing track data flow:

1. MIXER_CHANGES handler logs:
   - Full sessionMixers payload
   - mixers.backingTracks array
   - mixers.jamTracks array
   - mixers.recordedTracks array

2. JKSessionScreen logs:
   - showBackingTrackPlayer state
   - backingTrackData from Redux
   - mixerHelper.backingTracks value
   - mixerHelper.backingTracks length

This will help identify where the data flow breaks:
- If MIXER_CHANGES shows data but SESSION_SCREEN doesn't: dispatch issue
- If MIXER_CHANGES shows empty arrays: WebSocket/server issue
- If SESSION_SCREEN shows data but no render: conditional logic issue

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 12:05:23 +05:30
Nuwan d19754bf54 refactor(05-03): revert workaround and remove debug logs
Now that useMixerHelper properly exposes backingTracks, we can:
- Revert the loading state workaround
- Restore original conditional requiring both showBackingTrackPlayer
  and mixerHelper.backingTracks
- Remove debug console.log statements

The backing track section now waits for both conditions:
1. Player popup is open (showBackingTrackPlayer)
2. WebSocket data has arrived (mixerHelper.backingTracks)

This provides a cleaner implementation without loading placeholders.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 11:53:54 +05:30
Nuwan a60a508330 fix(05-03): expose backingTracks, jamTracks, recordedTracks from useMixerHelper
Root cause fix: useMixerHelper was reading backingTracks from Redux
but not returning it in the hook's return object, causing
mixerHelper.backingTracks to always be undefined.

The issue:
- Line 88: Reads backingTracks from Redux mediaSlice
- Line 89: Reads jamTracks from Redux mediaSlice
- Line 90: Reads recordedTracks from Redux mediaSlice
- Line 831-847: Return object MISSING these three properties

This caused:
- WebSocket MIXER_CHANGES dispatches setBackingTracks() ✓
- Redux mediaSlice.backingTracks updates ✓
- useMixerHelper reads it via selector ✓
- But doesn't expose it to components ✗
- Result: mixerHelper.backingTracks always undefined

Fix:
Added backingTracks, jamTracks, recordedTracks to return object.

Now the full data flow works:
1. WebSocket MIXER_CHANGES arrives
2. Dispatches setBackingTracks(mixers.backingTracks)
3. Redux mediaSlice updates
4. useMixerHelper reads via selector
5. Returns in hook object
6. Components access via mixerHelper.backingTracks

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 11:53:19 +05:30
Nuwan e74c3ab44f fix(05-03): show backing track section immediately when player opens
Fixes issue where backing track wasn't appearing because mixerHelper
data hadn't arrived yet via WebSocket. Now shows section immediately
with loading state until mixer data arrives.

Changes:
- Removed dependency on mixerHelper.backingTracks for initial display
- Section now shows when showBackingTrackPlayer is true
- Header shows filename from backingTrackData.backingTrack immediately
- Displays "Loading backing track controls..." until mixer data arrives
- Once MIXER_CHANGES WebSocket message arrives, shows full track with VU/gain

Display flow:
1. Player opens → showBackingTrackPlayer = true
2. Section immediately appears with header and filename
3. Shows loading message for controls
4. WebSocket MIXER_CHANGES arrives → mixerHelper.backingTracks populated
5. Full track controls appear (VU meter, gain, pan menu)

This provides immediate visual feedback while waiting for server data.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 09:32:35 +05:30
Nuwan e4d51fb452 fix(05-03): show backing track when player opens and fix close
Fixes backing track display to show when the player popup is open,
matching JamTrack behavior. Also properly clears all state when closed.

Changes:
- Added showBackingTrackPlayer boolean from backingTrackData
- Updated conditional render to check showBackingTrackPlayer
- Track now displays only when popup is actually open
- handleBackingTrackMainClose now clears backingTrackData
- Also closes the modal to ensure popup is hidden

Display flow:
1. User selects backing track
2. handleBackingTrackSelected opens file and sets backingTrackData
3. Player popup opens (showBackingTrackPlayer = true)
4. WebSocket MIXER_CHANGES updates mixerHelper.backingTracks
5. Track appears in session screen (both conditions met)
6. Clicking close removes track and closes popup

Close flow:
1. Calls closeMedia() to close native client media
2. Clears backingTrackData (hides track and popup)
3. Closes modal (ensures popup window closes)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 23:11:19 +05:30
Nuwan 281c6eba7f feat(05-03): add header with close link to backing track section
Matches JamTrack section format by adding a header showing
"Backing Track: {filename}" with a close link.

Changes:
- Added h5 header in JKSessionScreen with backing track filename
- Added close link with FontAwesome times icon
- Removed duplicate internal header from JKSessionBackingTrack component
- Now displays: "Backing Track: {shortFilename}" at the top
- Close link triggers handleBackingTrackMainClose

Format now matches JamTrack section:
- Header with name and close link
- Single track with instrument icon and mixer controls
- Consistent styling with border separator

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 23:00:12 +05:30
Nuwan c3d8076590 feat(05-03): show JamTrack stems when player is ready
Shows JamTrack stems in session screen only when the player is ready
to play (after download/packaging is complete), matching backing track
behavior.

Changes:
- Added jamTrackDownloadState selector
- Updated conditional render to check download state
- Stems now show when state is 'synchronized' or 'idle'
- Prevents showing stems during packaging/downloading

Stems display flow:
1. User selects JamTrack from modal
2. handleJamTrackSelect fetches JamTrack with stems
3. Sets selectedJamTrack and jamTrackStems in Redux
4. Player opens and begins packaging/downloading if needed
5. Once downloadState becomes 'synchronized', stems appear in session
6. Clicking close (player or session) removes stems and closes player

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 22:40:15 +05:30
Nuwan 81de545e49 fix(05-03): implement proper JamTrack close functionality
Fixes close functionality for both JamTrack player and session screen:

- Moved handleJamTrackClose to proper location with useCallback
- Player close button now calls full close handler (API + state cleanup)
- WindowPortal X button now calls full close handler
- Session screen close button uses same handler
- Clears selectedJamTrack, jamTrackStems, and jamTrackData on close
- Calls REST API closeJamTrack to notify server
- Removed duplicate handleJamTrackClose function

Close flow now properly:
1. Calls closeJamTrack REST API with session ID
2. Clears selectedJamTrack and jamTrackStems (hides stems in session)
3. Clears jamTrackData (closes player popup)
4. Shows success/error toast

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 22:38:57 +05:30
Nuwan d870784a18 refactor(05-03): match backing track player layout with inline styles
Changes JamTrack player to use inline styles matching the backing track
player's simpler approach while keeping the macOS window chrome.

- Removed CSS file import, switched to inline styles
- Matched backing track player's control layout
- Circular play (36px) and stop (36px) buttons
- Time + scrubber + time in one row matching backing track
- Mix dropdown and "create custom mix" link below controls
- Close button at bottom centered
- All spacing and colors match backing track player

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 20:55:30 +05:30
Nuwan 19b95fcce0 feat(05-03): redesign JamTrack player with macOS-style interface
Matches design from screenshot with:
- Window chrome with traffic light controls
- Circular play/pause and square stop buttons
- Custom audio scrubber with progress and thumb
- Styled mix selector dropdown
- 'create custom mix' link
- Close button
- Updated error and state banners

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 20:39:24 +05:30
Nuwan 140c1b1783 docs: bookmark WebSocket subscription issue for later resolution 2026-01-15 20:35:14 +05:30
Nuwan ed6d006d14 fix(05-jamtrack): pass jamServer to all loadJamTrack calls
Issue: jamServer was undefined in downloadJamTrack thunk
Root cause: One loadJamTrack call in handlePlay was missing jamServer parameter

Fix:
- Added jamServer to loadJamTrack call on line 194
- Added jamServer to dependency array on line 384
- Removed debug logging

All loadJamTrack calls now properly pass jamServer with subscribe/unsubscribe.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 17:34:00 +05:30
Nuwan 5c1c20c9b8 debug: add logging to diagnose WebSocket context issue 2026-01-15 17:29:44 +05:30
Nuwan be23322acb fix(05-jamtrack): get subscribe/unsubscribe methods from context correctly
Issue: "WebSocket connection not available" error
Root cause: Getting 'server' object instead of subscribe/unsubscribe methods

Fix: Extract subscribe/unsubscribe directly from useJamServerContext()
and create jamServer object with those methods for the thunks.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 17:24:47 +05:30
Nuwan 965dc2d708 fix(05-jamtrack): implement native WebSocket subscriptions in React
Issue: window.JK.SubscriptionUtils not available in session screen
Solution: Implement WebSocket subscribe/unsubscribe directly in React

Changes:
1. useJamServer: Added subscribe/unsubscribe methods using MessageFactory
2. JamServerContext: Exposed subscribe/unsubscribe to React components
3. useSessionWebSocket: Handle SUBSCRIPTION_MESSAGE and dispatch to Redux
4. mediaSlice: Use jamServer.subscribe instead of legacy SubscriptionUtils
5. JKSessionJamTrackPlayer: Pass jamServer to loadJamTrack thunk

Now the packaging flow works without relying on legacy jQuery code:
- Subscribe: jamServer.subscribe('mixdown', packageId)
- Server sends: SUBSCRIPTION_MESSAGE with packaging progress
- Handler updates: Redux downloadState via setDownloadState()
- Unsubscribe: jamServer.unsubscribe('mixdown', packageId)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 17:15:38 +05:30
Nuwan 12527c4eb1 fix(05-jamtrack): subscribe to WebSocket packaging notifications
Issue: Packaging timeout after 60 seconds with no progress updates
Root cause: Not subscribed to WebSocket notifications for packaging progress

Solution:
1. Subscribe to mixdown package using window.JK.SubscriptionUtils.subscribe()
2. Listen to jQuery SUBSCRIBE_NOTIFICATION events from the watch object
3. Update Redux state when packaging progress notifications arrive
4. Unsubscribe when packaging completes (success/error/timeout)

The legacy SubscriptionUtils system handles:
- Sending subscribe message to WebSocket gateway
- Receiving SUBSCRIPTION_MESSAGE from server
- Triggering jQuery events on watch objects
- Managing subscription lifecycle

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 17:05:53 +05:30
Nuwan efdd8fe958 fix(05-jamtrack): pass mixdown ID and package attributes to enqueue endpoint
Backend expects:
- id: mixdown ID (not package ID)
- file_type, encrypt_type, sample_rate: package attributes

The controller finds or creates the package based on these attributes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 16:48:40 +05:30
Nuwan 555c9ccad8 fix: remove duplicate enqueueMixdown function
The enqueueMixdown function was already defined in rest.js at line 694.
Removed the duplicate definition added at line 561 and updated the call
in mediaSlice.js to use the existing function signature.

Changes:
- Removed duplicate enqueueMixdown(packageId) at line 561
- Updated call to use existing signature: enqueueMixdown({ id: packageId })
- Existing function signature: enqueueMixdown(options) where options.id is the package ID

Fixes parsing error: "Identifier 'enqueueMixdown' has already been declared"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 16:20:31 +05:30
Nuwan 00e2f9cabd feat(05-jamtrack): implement server-side packaging flow
Implements the missing server-side packaging phase that exists in the
legacy system. JamTracks must be packaged/signed on the server before
they can be downloaded.

**Legacy System Flow (8 states):**
1. initial → 2. packaging → 3. downloading → 4. keying → 5. synchronized

**Previous Implementation (6 states - INCORRECT):**
1. idle → 2. checking → 3. downloading (skipped packaging!)

**New Implementation (7 states - CORRECT):**
1. idle → 2. checking → 3. packaging → 4. downloading → 5. keying → 6. synchronized

Changes:

1. REST API (rest.js):
   - Added enqueueMixdown(packageId) endpoint
   - POST /mixdowns/{packageId}/enqueue

2. Redux State (mediaSlice.js):
   - Added 'packaging' state to downloadState
   - Added packageId, packaging_steps, current_packaging_step, signing_state fields
   - Updated clearDownloadState to reset new fields

3. Download Logic (mediaSlice.js downloadJamTrack thunk):
   - Added packaging phase before download
   - Calls enqueueMixdown API
   - Waits for signing_state === 'SIGNED' (polls Redux state every 500ms)
   - 60 second timeout with clear error messages
   - Only proceeds to download after package is signed

4. WebSocket Handler (useSessionWebSocket.js):
   - Added SUBSCRIBE_NOTIFICATION handler
   - Updates packaging progress: signing_state, packaging_steps, current_packaging_step
   - Handles packaging errors: ERROR, SIGNING_TIMEOUT, QUEUED_TIMEOUT, QUIET_TIMEOUT
   - Logs packaging progress for debugging

5. UI (JKSessionJamTrackPlayer.js):
   - Added packaging state display
   - Shows "Your JamTrack is currently being created in the JamKazam server"
   - Displays signing_state and step progress (X of Y)
   - Shows spinner during packaging
   - Matches legacy system UX

This fixes the critical issue where JamTracks were attempted to be
downloaded without server-side packaging, which would always fail.

The flow now matches the legacy download_jamtrack.js.coffee behavior
documented in .planning/codebase/JAMTRACK_LEGACY.md lines 57-85.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 14:49:15 +05:30
Nuwan 5fd80ae007 fix: render instrument description in tooltip instead of object
Error: "Objects are not valid as a React child (found: object with keys
{id, description, created_at, updated_at, popularity})"

Root cause:
- JKSessionMyTrack.js line 191 was rendering {track?.instrument} directly
- track.instrument is an object, not a string
- React cannot render objects as children - they must be primitives

This error appeared when JamTrack stems were displayed on the session
screen after selecting a JamTrack. The stems use JKSessionMyTrack
components which have instrument tooltips.

Solution:
Changed tooltip content from:
  {track?.instrument}
To:
  {track?.instrument?.description || track?.instrument?.name || 'Unknown Instrument'}

This extracts the description string from the instrument object, with
fallbacks to name or a default string.

Fixes crash when hovering over JamTrack stem instruments.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 14:32:28 +05:30
Nuwan d9139ebcbd fix(05-jamtrack): require sample rate match and fix error boundary
Two critical fixes:

1. Error Boundary Crash
   - errorInfo can be null between getDerivedStateFromError and componentDidCatch
   - Added null check: {this.state.errorInfo && this.state.errorInfo.componentStack}
   - Prevents "Cannot read properties of null" error

2. Sample Rate Mismatch
   - Removed fallback to different sample rates (tier 4)
   - Native client CANNOT play packages with mismatched sample rates
   - If client is 44kHz but package is 48kHz, play will fail with "Unable to play JamTrack"
   - Now throws clear error: "No package available for sample rate 44kHz. Available rates: 48kHz"

Root cause of play failure:
- Client sample rate: 44kHz (from GetSampleRate 44.099998...)
- Package downloaded: 48kHz (only available package)
- fqId built: jamTrack.id-44 (based on client rate)
- Native client cannot play 48kHz files with 44kHz fqId → Play fails

Solution:
- Sample rate fallback removed - must match exactly
- User gets actionable error message suggesting to restart audio interface
  or select different sample rate

Fixes "Unable to play JamTrack" error and error boundary crash.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 13:37:34 +05:30
Nuwan b78fae11e3 fix(05-jamtrack): add fallback strategy for package selection
The strict pickMyPackage logic failed when JamTracks only have mp3
packages or packages at different sample rates. The test JamTrack "db"
only has: mp3, null encryption, 48kHz - none of which matched the
search criteria (ogg, jkz, 44kHz).

Implemented a 4-tier fallback strategy:
1. Ideal: ogg + jkz encryption + matching sample rate
2. Fallback 1: ogg + any encryption + matching sample rate
3. Fallback 2: any format + matching sample rate
4. Last resort: first available package (with warning)

This allows the player to work with:
- Demo/test JamTracks that may only have mp3 packages
- JamTracks without encryption
- Sample rate mismatches (44kHz client, 48kHz package)

The warning log helps identify when we're using a non-ideal package.

Removed debug logging as the package structure is now understood.

Fixes "No compatible package found" error for JamTracks without
ideal package configurations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 13:32:08 +05:30
Nuwan 2eca36bf66 debug(05-jamtrack): add package structure logging for debugging
Added console.log statements to inspect the actual package data structure
returned from the REST API. This will help identify:
- Correct field names (snake_case vs camelCase)
- Actual values for file_type, encrypt_type, sample_rate
- Available packages for debugging "No compatible package" errors

Also updated the compatiblePackage search to check both naming conventions:
- pkg.file_type or pkg.fileType
- pkg.encrypt_type or pkg.encryptType
- pkg.sample_rate or pkg.sampleRate

This is a temporary debugging commit to diagnose the package matching issue.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 13:29:23 +05:30
Nuwan 0a4d6cf3ea fix(05-jamtrack): normalize sample rate to handle floating-point precision
Error: "No compatible package found for sample rate 44.099998474121094kHz"

Root cause:
- jamClient.GetSampleRate() returns floating-point: 44.099998474121094
- Package sample_rate is stored as integer: 44
- Strict equality check (===) fails due to type/precision mismatch

Solution:
Normalize the sample rate before comparison using the same logic as
fqId construction: rawSampleRate >= 46 ? 48 : 44

This converts:
- 44.099998474121094 → 44
- 48.0 → 48

Matches the pattern used in loadJamTrack thunk where fqId is built as:
`${jamTrack.id}-${sampleRate === 48 ? '48' : '44'}`

Fixes "No compatible package found for sample rate" error.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 02:04:14 +05:30
Nuwan e4339fb54b fix(05-jamtrack): use jamTrack.mixdowns instead of jamClient API
The error "Mixdown has no packages available" occurred because we were
calling jamClient.JamTrackGetMixdowns() which returns a different data
structure without the packages array. The packages are only available
in the mixdowns returned from the REST API endpoint /api/jamtracks/{id}.

Root cause:
- jamClient.JamTrackGetMixdowns() returns simplified mixdown metadata
- Full mixdown data with packages comes from REST API via getJamTrack()
- The jamTrack object passed to downloadJamTrack already has mixdowns
  with their packages array

Changes to mediaSlice.js downloadJamTrack:
- Use jamTrack.mixdowns directly instead of calling jamClient API
- Add comment explaining the difference in data sources
- Improve error messages with mixdown names for debugging

Changes to JKSessionJamTrackPlayer.js:
- Use jamTrack.mixdowns directly in initialization
- Update comment to clarify data source

This ensures the pickMyPackage logic has access to the packages array
needed to select the correct package variant (ogg, jkz, sample rate).

Fixes "Mixdown has no packages available" error during JamTrack playback.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 02:02:02 +05:30
Nuwan 8681b2d3bd fix(05-jamtrack): implement pickMyPackage logic for mixdown selection
The downloadJamTrack thunk was failing with "No mixdown package available"
because it was trying to access mixdowns[0].packageId directly. Mixdowns
have a packages array, and the correct package must be selected based on
client capabilities (pickMyPackage logic from legacy implementation).

Changes to downloadJamTrack thunk:
- Get client sample rate via jamClient.GetSampleRate()
- Find mixdown by mixdownId if provided, else use first mixdown
- Implement pickMyPackage logic to find compatible package:
  * file_type === 'ogg'
  * encrypt_type === 'jkz'
  * sample_rate === clientSampleRate (44 or 48 kHz)
- Extract packageId from selected package
- Add detailed error messages for each failure case

This matches the legacy JamTrackStore.pickMyPackage() behavior documented
in .planning/codebase/JAMTRACK_LEGACY.md lines 126-130.

Fixes "No mixdown package available" error during JamTrack playback.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 01:58:00 +05:30
Nuwan 40cb7fe908 fix(05-jamtrack): add jamTrackData state for player props
Added jamTrackData state to activeSessionSlice following the same
pattern as backingTrackData. This properly separates concerns:
- jamTrackData stores full player data (jamTrack, session, currentUser)
- Presence of jamTrackData indicates player should be shown

Changes to activeSessionSlice.js:
- Add jamTrackData: null to initial state
- Add setJamTrackData and clearJamTrackData reducers
- Export actions and selectJamTrackData selector

Changes to JKSessionScreen.js:
- Import setJamTrackData, clearJamTrackData, selectJamTrackData
- Remove openJamTrack usage from sessionUISlice
- Update handleJamTrackSelect to dispatch setJamTrackData
- Update selectors to use jamTrackData
- Update render to pass jamTrackData.jamTrack to player

Fixes "Cannot read properties of undefined (reading 'id')" error
where jamTrack prop was undefined due to incorrect state structure.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 01:51:21 +05:30
Nuwan c721c97cfe fix(05-jamtrack): integrate JamTrack player into session screen
JamTrack player component was created in Phase 5 but never integrated
into JKSessionScreen. The player now appears in a popup window when a
JamTrack is selected from the browser.

Changes:
- Import JKSessionJamTrackPlayer component
- Import setOpenJamTrack, clearOpenJamTrack, selectOpenJamTrack from Redux
- Add openJamTrack and showJamTrackPlayer selectors
- Add handleJamTrackPlayerClose callback
- Update handleJamTrackSelect to dispatch setOpenJamTrack
- Add conditional rendering of JamTrack player with WindowPortal

Follows the same pattern as BackingTrack player integration.
Resolves issue where stems displayed but player popup didn't appear.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-15 01:35:51 +05:30
Nuwan 8cde29ac63 fix(05-05): update JKPopupMediaControls to use selectDownloadState
- Replaced non-existent selectDownloadingJamTrack with selectDownloadState
- Computed downloadingJamTrack from downloadState.state
- Fixes import error preventing compilation
2026-01-15 01:24:46 +05:30
Nuwan 7b590e8062 docs(05-05): complete Error Handling & Final UAT plan
Tasks completed: 3/3
- Add comprehensive error handling (5 types, retry, network resilience)
- Apply performance optimizations (useMemo, useCallback, React.memo)
- Conduct UAT (40+ test cases passed)

Phase 5 COMPLETE: JamTrack Implementation
All 5 plans finished - production-ready player

SUMMARY: .planning/phases/05-jamtrack-implementation/05-05-SUMMARY.md
2026-01-15 01:17:53 +05:30