-
-
Notifications
You must be signed in to change notification settings - Fork 21
[WIP] WebSocket #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[WIP] WebSocket #46
Conversation
…ction more stable and hard type but this SHOULD work!
…ng from an existing token vs a new token.
Hey @LePips no rush at all! I'm getting really close to being ready. I wanted to check in and make sure this structure/usage made sense to you. I've never build something like this before so I just wanted to be sure this structure wasn't going to cause headaches. Let me know what you think! /// Create a WebSocket instance with all available parameters
let socket = JellyfinSocket(
client: client,
userID: user.id,
isSupportsMediaControl: true,
supportedCommands: [.displayMessage, .play, .pause],
logLevel: .debug
)
/// Observe socket state changes
let stateSubscription = socket.$state
.receive(on: DispatchQueue.main)
.sink { state in
switch state {
case .idle:
print("Socket is idle")
case .connecting:
print("Connecting...")
case .connected(let url):
print("Connected to: \(url)")
case .disconnecting:
print("Disconnecting...")
case .closed(let error):
print("Closed: \(String(describing: error))")
case .error(let error):
print("Socket error: \(error)")
}
}
/// Observe parsed server messages
let messageSubscription = socket.messages
.receive(on: DispatchQueue.main)
.sink { message in
switch message {
case .sessionsMessage(let msg):
print("Received session update: \(msg)")
case .outboundKeepAliveMessage:
print("Received keep-alive pong")
default:
break
}
}
/// Connect the socket
socket.connect()
/// Subscribe to sessions feed immediately with updates every 2 seconds
socket.subscribe(.sessions(initialDelayMs: 0, intervalMs: 2000))
/// Later, unsubscribe
socket.unsubscribe(.sessions())
/// Gracefully disconnect (optional; also triggered by deinit)
socket.disconnect() The primary things that I want to confirm look good:
|
…hat need it. Still Swift 6 no warnings
`JellyfinSocket`
Summary
Create a JellyfinSocket item for WebSocket activity. Right now, this is in a fully functional, but messy state but I thought I would make a draft PR just to signal this was something I was working on. The goal is to get this working, add it to the SDK, and eventually be able to work on this: jellyfin/Swiftfin#408
WIP
This is currently a work in progress. The current version is functional but the following still need work:
Sendable
violations (likely threading) - I think I did this?Why Not NIO?
Not against it. Just getting this error:
PendingDatagramWritesManager.swift:291:33 Property 'msg_len' is not available due to missing import of defining module 'CNIODarwin'
I think the structure, or at least what I learned from doing this, should be reusable if we decide NIO is the best route. I would just need to get past that
CNIODarwin
dependency that only shows up on iOS.As a note - WebSocket (at least for Jellyfin) are named from the Server's perspective.
Inbound
means inbound into Server.