Swift SDK to work with Jellyfin servers.
Created using openapi-generator
Documentation is available on Swift Package Index.
JellyfinClient uses an underlying Get APIClient to provide basic functionality for interfacing with a Jellyfin server:
- inject required
Authorizationheader for every request - encoding/decoding of expected
Datevalues signInfor generating a session access tokensignOutfor revoking the current access token
// Create client instance
let jellyfinClient = JellyfinClient(configuration: configuration)
// Sign in user with credentials
let response = jellyfinClient.signIn(username: "jelly", password: "fin")Alternatively, you can use your own network stack with the generated Entities and Paths.
JellyfinSocket opens a long-lived WebSocket session to the Jellyfin server, delivering real-time updates as a stream of events. Subscriptions can be added or removed imperatively at any time and are restored automatically across reconnects.
/// Open a session
let session = client.socket(
supportsMediaControl: true,
supportedCommands: [.displayMessage, .play, .pause]
).connect()
/// Subscribe to feeds (uses each subscription's default timing)
session.subscribe(.sessions)
session.subscribe(.activityLog, interval: .seconds(10))
/// Iterate events for the lifetime of the session
for try await event in session.events {
switch event {
case .connecting:
print("Connecting...")
case let .connected(url):
print("Connected to \(url)")
case let .message(message):
switch message {
case let .sessionsMessage(msg):
print("Sessions: \(msg)")
default:
break
}
}
}
/// Remove a subscription
session.unsubscribe(.activityLog)
/// Close the session (also triggered on `deinit`)
session.disconnect()JellyfinClient provides a Quick Connect authorization flow.
for try await state in client.quickConnect.connect() {
switch state {
case let .polling(code: code):
print("Code: \(code)")
case let .authenticated(secret: secret):
try await client.signIn(quickConnectSecret: secret)
}
}JellyfinClient discovers other Jellyfin servers on the local network via UDP broadcast. IPv4 only, mirroring the server's behavior.
for try await server in JellyfinClient.discover(duration: .seconds(5)) {
print("Found server: \(server.name) at \(server.url)")
}# Download latest spec and run CreateAPI
$ make update