Files
OBS-Replay-Buffer-for-IT-Su…/README.md

149 lines
8.5 KiB
Markdown

# OBS Replay Buffer for IT Support
IT support tool that runs OBS Studio's replay buffer silently on VDI sessions, giving users a system tray button to save the last N minutes of screen activity when an issue occurs. Clips are saved to a central UNC share organized by username.
## How It Works
1. DEM runs `Start-OBSReplayBuffer.ps1` as a logon task
2. The script validates all required project files are accessible — each path is polled for up to 2 minutes before failing, to handle slow network share availability at logon
3. OBS config files are deployed to `%APPDATA%\obs-studio\` automatically
4. OBS launches hidden; the script waits for the process to appear, locates the new OBS log file, then confirms the replay buffer has actually started before proceeding
5. A WPF notification window informs the user that screen recording is active, shows the shield tray icon so they know what to look for, and auto-dismisses after 30 seconds
6. A system tray icon remains in the taskbar — right-click → **Save Replay**
7. On save, the script sends the request via WebSocket, then verifies a new `.mkv` file appears on disk before confirming success
8. A WPF confirmation window shows the saved filename and file size, and auto-dismisses after 30 seconds
## Architecture
| Component | Role |
|---|---|
| **DEM Logon Task** | Runs `Start-OBSReplayBuffer.ps1` at logon — only DEM task required |
| **`config.psd1`** | Central config — UNC path, buffer duration, OBS executable path, IT contact number |
| **`Start-OBSReplayBuffer.ps1`** | Validates project files (with retry), deploys OBS config, creates user capture folder, writes OBS profile, launches OBS, confirms replay buffer started via log, shows startup notification, launches tray icon |
| **`Show-ReplayTray.ps1`** | WinForms system tray icon — right-click menu with Save Replay / Exit |
| **`Invoke-ReplaySave.ps1`** | Sends `SaveReplayBuffer` to OBS via WebSocket v5, verifies the file was written to disk, shows save confirmation popup |
| **`obs-config/`** | OBS config files — deployed to `%APPDATA%\obs-studio\` at logon by the script |
## Repository Structure
```
obs-replay-buffer/
├── config.psd1
├── scripts/
│ ├── Start-OBSReplayBuffer.ps1
│ ├── Show-ReplayTray.ps1
│ └── Invoke-ReplaySave.ps1
└── obs-config/
├── global.ini
└── scenes/
└── ITMonitor.json
```
## Prerequisites
- **OBS Studio 28+** — delivered via App Volumes AppStack **or** installed directly on the machine (WebSocket v5 is built in — no plugin needed)
- **VMware DEM** to run the logon task
- A **UNC share** writable by VDI users for clip storage
- A **network share** to host this repo's files, accessible from all VDI machines
> **App Volumes is optional.** If OBS Studio is installed directly on the machine (e.g. via SCCM, Intune, or manual install), App Volumes is not required. Set `OBSExecutable` in `config.psd1` to the correct path and the script will work as-is.
## Configuration
Edit `config.psd1` before deploying:
| Key | Description | Default |
|---|---|---|
| `UNCPath` | Base UNC path for clip storage — username subfolder created automatically | `\\server\ITCaptures` |
| `LogPath` | Directory path for script logs — supports `%USERNAME%` and other environment variables; each script writes its own log file | `\\server\ITLogs\%USERNAME%` |
| `BufferSeconds` | Replay buffer duration in seconds | `120` |
| `WebSocketPort` | OBS WebSocket port — must match `[OBSWebSocket]` in `obs-config/global.ini` | `4455` |
| `OBSExecutable` | Full path to `obs64.exe` on the target machine | `C:\Program Files\obs-studio\bin\64bit\obs64.exe` |
| `ProfileName` | OBS profile name — must match the folder under `obs-config/profiles/` | `ITMonitor` |
| `SceneCollection` | OBS scene collection name — must match the filename under `obs-config/scenes/` | `ITMonitor` |
| `ITContactNumber` | IT help desk phone number shown in startup and save confirmation popups | `555-555-5555` |
## Deployment
### Step 1 — Host the repo on a network share
Place this repo (or a copy of it) on a share accessible from all target machines, e.g.:
```
\\stcu-fs01\IT-Tools\OBS-Record\
```
### Step 2 — DEM: Logon task
Create one logon task in DEM (scoped to the target user group). Set it to **not wait for completion**.
```
powershell.exe -ExecutionPolicy Bypass -NonInteractive -WindowStyle Hidden -File "\\stcu-fs01\IT-Tools\OBS-Record\scripts\Start-OBSReplayBuffer.ps1"
```
This is the only DEM task needed. The script handles all config file deployment, folder creation, and launching both OBS and the tray icon. It will exit cleanly (code 1) if any required project file is inaccessible after the 2-minute retry window, or exit 0 if OBS is already running.
> **No DEM file transfer tasks are needed.** The script deploys `global.ini` and the scene collection from the repo to `%APPDATA%\obs-studio\` at each logon. `basic.ini` is written dynamically so the correct UNC path, primary monitor resolution, and monitor device ID are baked in per session.
### Step 3 — OBS Studio (App Volumes or native install)
**Option A — App Volumes:** Assign the OBS AppStack to the same user group.
**Option B — Native install:** Ensure OBS Studio 28+ is installed at the path set in `OBSExecutable` in `config.psd1`. No other configuration is needed.
## User Experience
- At logon, a WPF popup notifies the user that screen recording is active, explains the replay buffer, shows the shield tray icon so they know what to look for, and includes the IT contact number — auto-dismisses after 30 seconds or on OK
- A shield icon remains in the system tray — right-click → **Save Replay** to save the last `BufferSeconds` of screen activity
- After a save, a WPF confirmation popup shows the saved filename and file size — auto-dismisses after 30 seconds or on OK
- Clips appear at `\\server\ITCaptures\<username>\` named by timestamp
- Logs are written to `\\server\ITLogs\<username>\` — three files, one per script, overwritten on each run:
- `OBSReplayBuffer.log` — startup, path validation, OBS launch verification, and config deployment
- `OBSReplayBuffer-Tray.log` — tray lifetime and save attempts
- `OBSReplayBuffer-Save.log` — WebSocket steps and file verification for each save attempt
## Changing the Buffer Duration
Update `BufferSeconds` in `config.psd1`. The value is written into the OBS profile at each logon, so no repackaging or redeployment is needed.
## Notes
### Startup Verification
`Start-OBSReplayBuffer.ps1` performs three checks after launching OBS before showing the user notification:
1. **Process check** — polls for the `obs64` process for up to 30 seconds
2. **Log file check** — waits up to 30 seconds for OBS to create a new session log file
3. **Replay buffer check** — polls the log file for a replay buffer started message for up to 2 minutes
If any check times out, the script exits with code 1 and logs the failure. The tray icon is not launched.
### Save Verification
After OBS acknowledges the `SaveReplayBuffer` request, `Invoke-ReplaySave.ps1` polls the user's capture folder for up to 30 seconds for a new `.mkv` file. If no file appears, the save is treated as failed. This catches cases where OBS accepts the request but fails to write the file.
### VDI Compatibility
This tool is designed for VDI environments running without a physical GPU (e.g. Microsoft Basic Render Driver):
- **Video encoder:** x264 (software) is used explicitly — hardware encoders (NVENC, QSV, AMF) are not available on most VDI machines
- **Display capture:** compatibility mode (BitBlt) is used instead of DXGI or WGC, which do not work reliably on virtual displays
- **Monitor ID:** the startup script uses `EnumDisplayDevices` with `EDD_GET_DEVICE_INTERFACE_NAME` to detect the active session's display device path at logon — this handles RDP/VDI sessions where the display UID varies per user or session
### WebSocket Settings
OBS 29+ stores WebSocket server settings in `global.ini` under `[OBSWebSocket]`, not in a separate `plugin_config` JSON file. The `global.ini` in this repo includes the WebSocket configuration directly:
```ini
[OBSWebSocket]
FirstLoad=false
ServerEnabled=true
ServerPort=4455
AlertsEnabled=false
AuthRequired=false
```
### OBS Tray Icon vs. IT Tray Icon
OBS places its own tray icon when minimized. Users will see two icons — the OBS icon and the IT Screen Recorder shield icon. The OBS icon can be right-clicked to quit OBS, which would break the replay buffer. If this is a concern, a future enhancement could suppress the OBS tray icon via an OBS config setting.