feat: add AppRole, StreamingConstants, Routes, APIModels to MusicShared

feat/music-streaming
Laurent 1 month ago
parent d8863299ff
commit 981c9123a1
  1. 21
      MusicShared/Sources/MusicShared/APIModels.swift
  2. 19
      MusicShared/Sources/MusicShared/AppRole.swift
  3. 7
      MusicShared/Sources/MusicShared/StreamingConstants.swift
  4. 23
      MusicShared/Sources/MusicShared/StreamingRoutes.swift

@ -0,0 +1,21 @@
import Foundation
public struct AuthResponse: Codable, Equatable, Sendable {
public var hostName: String
public var protocolVersion: Int
public init(hostName: String, protocolVersion: Int) {
self.hostName = hostName
self.protocolVersion = protocolVersion
}
}
public struct DBMetadata: Codable, Equatable, Sendable {
public var checksum: String
public var trackCount: Int
public init(checksum: String, trackCount: Int) {
self.checksum = checksum
self.trackCount = trackCount
}
}

@ -0,0 +1,19 @@
import Foundation
public enum AppRole: String, Codable, CaseIterable, Sendable {
case local
case remoteHost
case remoteClient
case streamHost
case streamClient
}
extension AppRole {
public var isHost: Bool { self == .remoteHost || self == .streamHost }
public var isClient: Bool { self == .remoteClient || self == .streamClient }
public var isLocal: Bool { self == .local }
public var usesLocalAudio: Bool { self == .local || self == .remoteHost || self == .streamClient }
public var isReadOnlyLibrary: Bool { self == .remoteClient || self == .streamClient }
public var needsNetworkServer: Bool { self == .remoteHost || self == .streamHost }
public var isStreaming: Bool { self == .streamHost || self == .streamClient }
}

@ -0,0 +1,7 @@
import Foundation
public enum StreamingConstants: Sendable {
public static let defaultPort: Int = 8420
public static let segmentDuration: Double = 6.0
public static let protocolVersion: Int = 1
}

@ -0,0 +1,23 @@
import Foundation
public enum StreamingRoutes: Sendable {
public static let auth = "/auth"
public static let db = "/db"
public static let ws = "/ws"
public static func trackManifest(trackId: Int64) -> String {
"/tracks/\(trackId)/stream.m3u8"
}
public static func trackSegment(trackId: Int64, index: Int) -> String {
"/tracks/\(trackId)/segments/\(index).mp3"
}
public static func trackManifestPattern() -> String {
"/tracks/:trackId/stream.m3u8"
}
public static func trackSegmentPattern() -> String {
"/tracks/:trackId/segments/:index"
}
}
Loading…
Cancel
Save