Connection
The WebSocket server runs onws://localhost:44030/ and accepts connections from the frontend.
The backend only allows one active WebSocket connection. New connections automatically close previous ones.
The backend also listens on the legacy port
ws://localhost:5000/. Connections to that port immediately receive an AppVersion message and are then closed, which causes older frontends to detect a version mismatch and reload against the current port.Message Structure
Frontend to Backend
Messages sent viawindow.external.sendMessage() use this JSON structure:
Backend to Frontend
Messages received via WebSocket use this JSON structure:Frontend to Backend Methods
These commands can be sent from the frontend to control the backend.Recording Control
Starts a manual recording session.Parameters: NoneExample:
Stops the current recording.Parameters: NoneExample:
Authentication
Signs out the current user.Parameters: NoneExample:
Clip Creation
Creates clips from selected video segments.Parameters:Example:
Array of segment objects defining clip ranges
Unique identifier for this segment
Start timestamp in seconds
End timestamp in seconds
Source video file name
Full path to source video
Content type:
Session, Buffer, Clip, or HighlightGame name for organizing clips
Optional title for the clip
IGDB game database ID
Optional array of audio track indexes to mute in the output
Optional map of
{ "<trackIndex>": <volume> } to apply per-track volume adjustmentsCancels an in-progress clip operation.Parameters:Example:
The clip operation ID to cancel
Creates AI-generated highlights from a video.Parameters:Example:
Video file name to process
Content Management
Deletes multiple content items in a batch operation.Parameters:Example:
Array of items to delete, each with FileName and ContentType
Renames a content file.Parameters: Handled by ContentService.HandleRenameContentExample:
Imports an external video file into Segra.Parameters: Handled by ImportService.HandleImportFileExample:
Upload & Compression
Uploads content to a platform (e.g., Segra.tv).Parameters: Handled by UploadService.HandleUploadContentExample:
Cancels an in-progress upload.Parameters:Example:
File name of the upload to cancel
Compresses a video to reduce file size.Parameters:Example:
Full path to the video file
Bookmarks
Adds a bookmark during recording or playback.Parameters: Handled by ContentService.HandleAddBookmarkExample:
Removes a bookmark.Parameters: Handled by ContentService.HandleDeleteBookmarkExample:
Settings
Updates application settings.Parameters: Handled by SettingsService.HandleUpdateSettingsExample:
Opens a folder picker to change the video storage location.Parameters: NoneExample:
Opens a folder picker to change the cache storage location.Parameters: NoneExample:
Applies a video quality preset (see Example:
PresetsService.ApplyVideoPreset).Parameters:Preset name:
low, standard, high, or customApplies a clip quality preset (see Example:
PresetsService.ApplyClipPreset).Parameters:Preset name:
low, standard, high, or customGame Management
Per-game record/skip preferences live on the unified
games array in Settings.Instance (each entry has a record boolean plus optional quality / recording-mode overrides). Update them by sending an UpdateSettings message with the modified games array — there are no dedicated AddToWhitelist / AddToBlacklist / MoveGame methods. The legacy whitelist / blacklist fields are migration-only and may be removed in a future release.Opens a file picker to select a game executable.Parameters: NoneResponse: Backend sends
SelectedGameExecutable message with the selected fileExample:System Actions
Opens Windows Explorer to the file location.Parameters:Example:
Full path to the file
Copies a file to the Windows clipboard so it can be pasted into Explorer, chat clients, or other apps that accept file drops.Parameters:Example:
Full path to the file to copy
Opens Windows Explorer to the logs folder.Parameters: NoneExample:
Toggles fullscreen mode.Parameters:Example:
True to enable fullscreen, false to disable
Updates
Checks for available application updates.Parameters: NoneExample:
Applies a downloaded update and restarts the application.Parameters: NoneExample:
Connection
Signals that a new WebSocket connection has been established. The backend responds with initial state.Parameters: NoneResponse: Backend sends:
Settingswith persisted settingsStatewith runtime application stateGameListwith available gamesAppVersionwith backend version (only when an update manager build is available)UpdateProgressif an update download/install was in flight when the client (re)connected, replaying the most recent progress payloadReleaseNotesasynchronously, after fetching from the update channel
Storage & Recovery
Confirms or cancels a storage warning action.Parameters: Handled by StorageWarningService.HandleStorageWarningConfirm
Confirms recovery of temporary files after a crash.Parameters: Handled by RecoveryService.HandleRecoveryConfirm
Triggers migration of existing content into Segra’s canonical folder layout.Parameters: Handled by ContentMigrationService.HandleMigrateContentProgress: The backend streams
ContentMigrationProgress events while the migration runs.Backend to Frontend Events
These messages are sent from the backend to update the frontend state.State Updates
Sends the persisted user settings to the frontend.
content is the bare Settings.Instance object (no wrapping settings key).Example:Runtime state (active recording, content library, detected devices, current folder size, etc.) is no longer nested under
settings.state. It is delivered separately via the State message described below.Sends the runtime Example:
AppState.Instance object to the frontend. This is non-persisted, in-memory state that mirrors the live application status.Content (selected fields):The active
Recording (or null when idle)A
PreRecording placeholder while Segra is preparing to record (or null)All known content items (sessions, buffers, clips, highlights)
Detected audio input devices
Detected audio output devices
Detected monitors
Available video codecs/encoders
OBS versions known to the updater
Detected GPU vendor (
Nvidia, Amd, Intel, or Unknown)Detected CUDA compute capability for NVIDIA GPUs
Maximum height of any connected display (used for resolution clamping)
True once OBS has been initialized
True while an update check is in-flight
Total size of the content folder in GB
Sends the list of detected games.Content: The
content field is itself an array of GameEntry objects — there is no wrapping games key.Example:Each entry uses the
GameEntry shape from Backend/Games/GameUtils.cs — name and executables (back-slashed). It is distinct from the Game shape used for whitelist/blacklist commands, which uses paths.Sends the backend application version for version mismatch detection.Content:Example:
Semantic version string (e.g., “1.2.3”)
Frontend automatically reloads if this doesn’t match
__APP_VERSION__Progress Events
Reports progress of upload operations.Content:Example:
File being uploaded
Title submitted with the upload (mirrored in every progress event)
Progress percentage (0-100), or -1 for error
Upload status: “uploading”, “processing”, “done”, or “error”
Status message or error description
Reports progress of file import operations.Content:
Import operation ID
Current file being imported
Progress percentage for current file
Import status: “importing”, “done”, or “error”
Total number of files to import
Index of current file (0-based)
Status message
Reports progress of AI highlight generation.Content: Handled by AiService
Indicates whether the recording-preview window is currently active (the in-app live preview controlled by the
TogglePreview keybind).Content:Whether preview rendering is active
Streams a frame of the live recording preview to the frontend (sent only while the preview is enabled).Content: A frame payload emitted by
RecordingPreviewService.Reports progress of a content-folder migration triggered by
MigrateContent.Content:Migration operation ID
File currently being moved
Progress percentage (0-100), or -1 for error
Migration status (e.g.
"migrating", "done", "error")Total number of files in the migration
Index of the file currently being moved
Status or error message
Fired when the user saves the replay buffer (typically via the
SaveReplayBuffer keybind). Emitted with an empty content payload — frontends usually surface a toast or sound effect in response.User Notifications
Warns user about storage space issues and requests confirmation.Content:
Unique ID for this warning
Warning title
Warning description
Text for confirm button
Text for cancel button
Action to perform if confirmed
Data needed to perform the action
Notifies that a bookmark was created (typically from a keybind).Content: Empty objectExample:
UI Events
Triggers the frontend to display release notes.Content: Version string to show notes for
Heartbeat
Response to ping heartbeat message.Content: Empty objectExample:
Error Handling
Frontend Validation
Always check if the backend connection is available before sending messages:Backend Error Responses
When operations fail, the backend typically:- Logs the error with Serilog
- Sends a progress event with
progress: -1and anerrorfield - Optionally shows a
ShowModalmessage to the user
Connection Failures
The WebSocket automatically reconnects if the connection drops:- Reconnect attempts: Infinite
- Reconnect interval: 3 seconds
- Heartbeat timeout: 30 seconds
Best Practices
Use TypeScript Types
Import message type definitions from
Models/WebSocketMessages.ts for type safety.Handle All States
Progress events can be: in-progress (0-100), complete (100), or error (-1). Handle all cases.
Listen to Events
Use
window.addEventListener('websocket-message') to react to backend events globally.Graceful Degradation
Always check if
window.external.sendMessage exists before calling it.Example: Complete Clip Workflow
Here’s a complete example showing the clip creation workflow:Next Steps
API Overview
Learn about the internal architecture
Core Services
Browse backend service documentation