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.
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
method
Starts a manual recording session.Parameters: NoneExample:
method
Stops the current recording.Parameters: NoneExample:
Authentication
method
method
Signs out the current user.Parameters: NoneExample:
Clip Creation
method
Creates clips from selected video segments.Parameters:Example:
string
Optional. Set to
"separate" to export each segment as its own clip instead of concatenating them.array
required
Array of segment objects defining clip ranges. Segments no longer duplicate content metadata; the backend resolves game, title, type, IGDB ID, file name, and file path from the referenced content.
number
required
Unique identifier for this segment
string
required
ID of the source content (from
Content.id). The backend looks up the source file, type, game, title, and IGDB ID from application state.number
required
Start timestamp in seconds
number
required
End timestamp in seconds
number[]
Optional array of audio track indexes to mute in the output
object
Optional map of
{ "<trackIndex>": <volume> } to apply per-track volume adjustmentsmethod
Cancels an in-progress clip operation.Parameters:Example:
number
required
The clip operation ID to cancel
method
Creates AI-generated highlights from a video.Parameters:Example:
string
required
ID of the source content to process (from
Content.id).Content Management
method
Deletes a single piece of content.Parameters:Example:
string
required
ID of the content to delete (from
Content.id). The backend resolves the file path and content type from application state.method
Deletes multiple content items in a batch operation.Parameters:Example:
string[]
required
Array of content IDs to delete (from
Content.id).method
method
Imports an external video file into Segra.Parameters: Handled by ImportService.HandleImportFileExample:
Upload & Compression
method
Uploads content to Segra.tv. The backend reads Example:
Game and IgdbId off the referenced content and uses the current session for authentication (no JWT field is sent).Parameters:string
required
ID of the content to upload (from
Content.id).string
required
Title to display on Segra.tv.
string
Optional description for the upload.
string
"Public" or "Unlisted".method
method
Compresses a video to reduce file size. The compressed file inherits the source’s name (falling back to Example:
" (1)", " (2)", … on collision) and is flagged in metadata via Content.compressed; there is no longer a _compressed filename suffix.Parameters:string
required
ID of the content to compress (from
Content.id).Bookmarks
method
method
Settings
method
Updates application settings.Parameters: Handled by SettingsService.HandleUpdateSettingsExample:
method
Opens a folder picker to change the video storage location.Parameters: NoneExample:
method
Opens a folder picker to change the cache storage location.Parameters: NoneExample:
method
Applies a video quality preset (see Example:
PresetsService.ApplyVideoPreset).Parameters:string
required
Preset name:
low, standard, high, or custommethod
Applies a clip quality preset (see Example:
PresetsService.ApplyClipPreset).Parameters:string
required
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.method
Opens a file picker to select a game executable.Parameters: NoneResponse: Backend sends
SelectedGameExecutable message with the selected fileExample:System Actions
method
method
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:
string
required
Full path to the file to copy
method
Compresses a video down to a target size and copies the result to the Windows clipboard. Powers the “Copy as MB” entries in the video page’s Copy split button.Parameters:Response: Backend streams
string
required
Full path to the source video file.
number
required
Target maximum size for the compressed copy, in megabytes. Values that are not smaller than the source are rejected by the UI. See
copyCompressSizesMb in Settings for the sizes offered by default.ClipboardCompressionProgress events during compression.Example:method
Opens Windows Explorer to the logs folder.Parameters: NoneExample:
method
Toggles fullscreen mode.Parameters:Example:
boolean
required
True to enable fullscreen, false to disable
Updates
method
Checks for available application updates.Parameters: NoneExample:
method
Applies a downloaded update and restarts the application.Parameters: NoneExample:
Connection
method
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
method
Confirms or cancels a storage warning action.Parameters: Handled by StorageWarningService.HandleStorageWarningConfirm
method
Confirms recovery of temporary files after a crash.Parameters: Handled by RecoveryService.HandleRecoveryConfirm
method
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
event
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.event
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):object
The active
Recording (or null when idle)object
A
PreRecording placeholder while Segra is preparing to record (or null)array
All known content items (sessions, buffers, clips, highlights)
array
Detected audio input devices
array
Detected audio output devices
array
Detected monitors
array
Available video codecs/encoders
array
OBS versions known to the updater
string
Detected GPU vendor (
Nvidia, Amd, Intel, or Unknown)number
Detected CUDA compute capability for NVIDIA GPUs
number
Maximum height of any connected display (used for resolution clamping)
boolean
True once OBS has been initialized
boolean
True while an update check is in-flight
number
Total size of the content folder in GB
event
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.event
Sends the backend application version for version mismatch detection.Content:Example:
string
Semantic version string (e.g., “1.2.3”)
Frontend automatically reloads if this doesn’t match
__APP_VERSION__Progress Events
event
event
Reports progress of upload operations.Content:Example:
string
required
File being uploaded
string
required
Title submitted with the upload (mirrored in every progress event)
number
required
Progress percentage (0-100), or -1 for error
string
required
Upload status: “uploading”, “processing”, “done”, or “error”
string
Status message or error description
string
Local file path of the source content’s thumbnail (from
FolderNames.GetThumbnailFilePath). Used by upload cards to render a blurred background matching the content’s cover. Omitted when no thumbnail exists.event
Reports progress of file import operations.Content:
number
required
Import operation ID
string
required
Current file being imported
number
required
Progress percentage for current file
string
required
Import status: “importing”, “done”, or “error”
number
required
Total number of files to import
number
required
Index of current file (0-based)
string
Status message
event
event
Reports progress of a
CopyCompressedFileToClipboard operation. The video page uses these events to animate the Copy button while a size-capped copy is being prepared.Content:string
required
Source file being compressed for the clipboard copy
number
required
Progress percentage (0-100)
string
required
Status: “compressing”, “done”, or “error”
string
Status or error message
event
event
Reports progress of AI highlight generation.Content: Handled by AiService
event
Indicates whether the recording-preview window is currently active (the in-app live preview controlled by the
TogglePreview keybind).Content:boolean
required
Whether preview rendering is active
event
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.event
event
Reports progress of a content-folder migration triggered by
MigrateContent.Content:string
required
Migration operation ID
string
required
File currently being moved
number
required
Progress percentage (0-100), or -1 for error
string
required
Migration status (e.g.
"migrating", "done", "error")number
Total number of files in the migration
number
Index of the file currently being moved
string
Status or error message
event
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
event
event
Warns user about storage space issues and requests confirmation.Content:
string
required
Unique ID for this warning
string
required
Warning title
string
required
Warning description
string
required
Text for confirm button
string
required
Text for cancel button
string
required
Action to perform if confirmed
any
required
Data needed to perform the action
event
event
Notifies that a bookmark was created (typically from a keybind).Content: Empty objectExample:
UI Events
event
event
event
Triggers the frontend to display release notes.Content: Version string to show notes for
event
Heartbeat
event
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