Documentation
¶
Overview ¶
Package wsclient implements the websocket listener that connects to Plex's notification channel and dispatches playing / transcode-update events into the session tracker. Reconnect, backoff, ping/pong, and read-limit policy live here.
Index ¶
- Constants
- func FillSessionLibrary(ss *sessions.Session, media *plexapi.SessionMetadata, libs []library.Library)
- func MarkTranscodePending(ss *sessions.Session, transcodeSession string)
- func SubtitleAction(ts *plexapi.WSTranscodeSession) string
- func TranscodeKind(ts *plexapi.WSTranscodeSession) string
- type BackoffConfig
- type Listener
Constants ¶
const ( NotifTypePlaying = "playing" NotifTypeTranscodeUpdate = "transcodeSession.update" )
Plex WebSocket notification type identifiers. These match the `NotificationContainer.type` field in Plex's /:/websockets/notifications protocol and gate which handler runs for each message.
const PingInterval = 30 * time.Second
PingInterval is how often we send a Ping while the WebSocket is connected. A failed ping closes the connection so the main read loop returns, triggering a normal reconnect. This catches half-open connections (NAT/middlebox state dropped without RST).
const PongTimeout = 10 * time.Second
PongTimeout is the deadline for a single ping round-trip.
Variables ¶
This section is empty.
Functions ¶
func FillSessionLibrary ¶
func FillSessionLibrary(ss *sessions.Session, media *plexapi.SessionMetadata, libs []library.Library)
FillSessionLibrary populates library labels on ss when missing, using the provided library list matched by LibrarySectionID. No-op if ss already has a library name.
func MarkTranscodePending ¶
MarkTranscodePending records the transcode session key from the playing notification and flags the session as pending classification. The bare key (e.g. "pqa0kbrvowd7llgyggagzgjz") stored here is a suffix of the path-prefixed TranscodeSession.key (e.g. "/transcode/sessions/pqa0kbrvowd7llgyggagzgjz") that arrives on transcodeSession.update notifications, letting Tracker.UpdateTranscode correlate the two streams precisely even when multiple sessions are pending simultaneously. No-op if the session already has a resolved transcode kind.
func SubtitleAction ¶
func SubtitleAction(ts *plexapi.WSTranscodeSession) string
SubtitleAction classifies a transcode session's subtitle handling. Return values are one of ValBurn, ValCopy, ValTranscode, ValNone, or "other".
func TranscodeKind ¶
func TranscodeKind(ts *plexapi.WSTranscodeSession) string
TranscodeKind classifies a transcode session by audio/video decision and codec changes. Return values are one of ValVideo, ValAudio, ValBoth, or ValNone.
Types ¶
type BackoffConfig ¶
BackoffConfig holds reconnect backoff parameters. Zero values mean "use package defaults" (1s min, 30s max).
type Listener ¶
type Listener struct {
Client *plex.Client
Sessions *sessions.Tracker
Libraries func() []library.Library
RecordError func(kind string)
SetConnected func(bool)
Backoff BackoffConfig
}
Listener opens and maintains the Plex websocket notification channel, dispatching events into the session tracker. Dependencies are injected as closures and a narrow interface so the listener stays free of any import-cycle back-edge to package server; the composition root in package main wires the callbacks.
func (*Listener) ConnectAndListen ¶
ConnectAndListen opens the WebSocket and blocks in the read loop until the connection ends. Returns (sawTraffic, err): sawTraffic is true once at least one message has been received; this is the signal the caller uses to distinguish "healthy connection dropped" from "accept-and-reject" loops.
func (*Listener) HandlePlaying ¶
func (l *Listener) HandlePlaying(ctx context.Context, notif plexapi.WSNotification)
HandlePlaying applies a "playing"-type websocket notification to the session tracker. Stopped notifications are applied without a /status/sessions fetch (they don't need session metadata and must not be dropped when the sessions API is temporarily down); all other states require a metadata fetch to populate labels.
func (*Listener) HandleTranscodeUpdate ¶
func (l *Listener) HandleTranscodeUpdate(notif plexapi.WSNotification)
HandleTranscodeUpdate applies a "transcodeSession.update" websocket event by correlating it with an existing session (via stored bare transcode key or media part URL) and recording the classification.