---
phase: 24-fix-recording-crash
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - jam-ui/src/hooks/useRecordingHelpers.js
  - jam-ui/src/components/client/JKSessionScreen.js
autonomous: true

must_haves:
  truths:
    - "Clicking Start Recording does not crash the C++ client"
    - "Recording starts successfully after clicking Start Recording"
    - "Recording stops successfully after clicking Stop Recording"
    - "Recording callbacks are invoked correctly by C++ client"
  artifacts:
    - path: "jam-ui/src/hooks/useRecordingHelpers.js"
      provides: "Recording start/stop with correct jamClient method calls"
      contains: "StartRecording"
    - path: "jam-ui/src/components/client/JKSessionScreen.js"
      provides: "Session recording with correct method call"
      contains: "StartRecording"
  key_links:
    - from: "jam-ui/src/hooks/useRecordingHelpers.js"
      to: "jamClient.StartRecording"
      via: "jamClient proxy call with unpacked parameters"
      pattern: "jamClient\\.StartRecording\\("
    - from: "jam-ui/src/hooks/useRecordingHelpers.js"
      to: "jamClient.StopRecording"
      via: "jamClient proxy call"
      pattern: "jamClient\\.StopRecording\\("
---

<objective>
Fix C++ client crash when Start Recording is clicked by correcting method names and parameter format.

Purpose: The recording feature crashes because jam-ui uses wrong method names (`StartMediaRecording` instead of `StartRecording`) and passes a settings object instead of unpacked individual parameters. This makes the C++ client unable to process the call correctly.

Output: Working recording start/stop that matches the legacy implementation pattern.
</objective>

<execution_context>
@/Users/nuwan/.claude/get-shit-done/workflows/execute-plan.md
@/Users/nuwan/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/research/RECORDING-ANALYSIS.md

# Key source files
@jam-ui/src/hooks/useRecordingHelpers.js
@jam-ui/src/components/client/JKSessionScreen.js

# Reference: Legacy implementation (working pattern)
@web/app/assets/javascripts/recordingModel.js (lines 99, 141)
</context>

<tasks>

<task type="auto">
  <name>Task 1: Fix useRecordingHelpers.js method names and parameters</name>
  <files>jam-ui/src/hooks/useRecordingHelpers.js</files>
  <action>
Fix the recording method calls to match the legacy implementation:

1. **Fix startRecording function (around line 101):**
   - Change `jamClient.StartMediaRecording(recording.id, groupedTracks, recordSettings)`
   - To: `jamClient.StartRecording(recording.id, groupedTracks, recordVideo, recordChat, recordFramerate)`
   - Unpack `recordSettings` into individual parameters:
     - `recordVideo` = `recordSettings.videoType || 0` (integer, 0 means no video)
     - `recordChat` = `recordSettings.recordChat ? 1 : 0` (integer flag)
     - `recordFramerate` = `0` (default, matches legacy)
   - The `recordVideo` variable already exists at line 83: `const recordVideo = recordSettings.recordingType === RECORD_TYPE_BOTH;`
   - This boolean needs to be converted to the videoType integer for the C++ call

2. **Fix stopRecording function (around line 166):**
   - Change `jamClient.FrontStopRecording(recording.id, groupedTracks)`
   - To: `jamClient.StopRecording(recording.id, groupedTracks)`

**Legacy signatures for reference:**
```javascript
// Start: recordingModel.js line 99
jamClient.StartRecording(recording["id"], groupedTracks, recordVideo, recordChat, recordFramerate);

// Stop: recordingModel.js line 141
jamClient.StopRecording(recording.id, groupedTracks);
```

**Note:** Keep the existing error handling and state management logic unchanged. Only modify the jamClient method calls.
  </action>
  <verify>
1. Grep for `StartMediaRecording` in useRecordingHelpers.js returns no results
2. Grep for `FrontStopRecording` in useRecordingHelpers.js returns no results
3. Grep for `StartRecording` in useRecordingHelpers.js returns the new call
4. Grep for `StopRecording` in useRecordingHelpers.js returns the new call
5. No TypeScript/ESLint errors when running `npm run lint` (if applicable)
  </verify>
  <done>
- `useRecordingHelpers.js` calls `jamClient.StartRecording(id, tracks, videoType, chatFlag, framerate)` with unpacked parameters
- `useRecordingHelpers.js` calls `jamClient.StopRecording(id, tracks)` with correct method name
- No references to `StartMediaRecording` or `FrontStopRecording` in useRecordingHelpers.js
  </done>
</task>

<task type="auto">
  <name>Task 2: Fix JKSessionScreen.js doStartRecording method</name>
  <files>jam-ui/src/components/client/JKSessionScreen.js</files>
  <action>
Fix the doStartRecording function (around line 880) to use the correct method name and parameters:

1. **Current code (line 880):**
   ```javascript
   await jamClient.StartMediaRecording(currentRecordingId, groupedTracks, params);
   ```

2. **Change to:**
   ```javascript
   const recordVideo = params.videoType || 0;
   const recordChat = params.recordChat ? 1 : 0;
   const recordFramerate = 0;
   await jamClient.StartRecording(currentRecordingId, groupedTracks, recordVideo, recordChat, recordFramerate);
   ```

**Note:** The `params` object coming into doStartRecording contains:
- `recordVideo` (boolean from modal)
- `recordChat` (boolean)
- `videoType` (integer for video source)

Extract and convert these to match the legacy C++ client expectations.
  </action>
  <verify>
1. Grep for `StartMediaRecording` in JKSessionScreen.js returns no results in doStartRecording
2. Grep for `StartRecording` in JKSessionScreen.js shows the corrected call
3. No syntax errors - file parses correctly
  </verify>
  <done>
- `JKSessionScreen.js` `doStartRecording` function calls `jamClient.StartRecording` with correct parameters
- No references to `StartMediaRecording` in the recording-related code paths
  </done>
</task>

</tasks>

<verification>
After both tasks are complete:

1. **Code verification:**
   ```bash
   # Should return 0 results for old method names in recording code
   grep -n "StartMediaRecording\|FrontStopRecording" jam-ui/src/hooks/useRecordingHelpers.js
   grep -n "StartMediaRecording" jam-ui/src/components/client/JKSessionScreen.js | grep doStartRecording

   # Should show new correct calls
   grep -n "jamClient.StartRecording\|jamClient.StopRecording" jam-ui/src/hooks/useRecordingHelpers.js
   ```

2. **Build verification:**
   ```bash
   cd jam-ui && npm run build
   ```
   Build should complete without errors.

3. **Manual testing (for human verification in Phase 25):**
   - Start jam-ui with `npm run start`
   - Join a session
   - Open recording modal
   - Click Start Recording
   - Expected: No crash, recording starts
</verification>

<success_criteria>
1. Method names corrected: `StartRecording` and `StopRecording` used instead of `StartMediaRecording` and `FrontStopRecording`
2. Parameters unpacked: Individual params (id, tracks, videoType, chatFlag, framerate) passed instead of settings object
3. Build passes without errors
4. No regressions in existing code (state management, error handling unchanged)
</success_criteria>

<output>
After completion, create `.planning/phases/24-fix-recording-crash/24-01-SUMMARY.md`
</output>
