-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMoblinSettingsUrl.swift
127 lines (109 loc) · 3.32 KB
/
MoblinSettingsUrl.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import Foundation
class MoblinSettingsWebBrowser: Codable {
var home: String?
}
class MoblinSettingsSrt: Codable {
var latency: Int32?
var adaptiveBitrateEnabled: Bool?
var dnsLookupStrategy: SettingsDnsLookupStrategy?
}
class MoblinSettingsUrlStreamVideo: Codable {
var resolution: SettingsStreamResolution?
var fps: Int?
var bitrate: UInt32?
var codec: SettingsStreamCodec?
var bFrames: Bool?
var maxKeyFrameInterval: Int32?
}
class MoblinSettingsUrlStreamAudio: Codable {
var bitrate: Int?
}
class MoblinSettingsUrlStreamObs: Codable {
var webSocketUrl: String
var webSocketPassword: String
init(webSocketUrl: String, webSocketPassword: String) {
self.webSocketUrl = webSocketUrl
self.webSocketPassword = webSocketPassword
}
}
class MoblinSettingsUrlStreamTwitch: Codable {
var channelName: String
var channelId: String
init(channelName: String, channelId: String) {
self.channelName = channelName
self.channelId = channelId
}
}
class MoblinSettingsUrlStreamKick: Codable {
var channelName: String
init(channelName: String) {
self.channelName = channelName
}
}
class MoblinSettingsUrlStream: Codable {
var name: String
var url: String
// periphery:ignore
var enabled: Bool?
var selected: Bool?
var video: MoblinSettingsUrlStreamVideo?
var audio: MoblinSettingsUrlStreamAudio?
var srt: MoblinSettingsSrt?
var obs: MoblinSettingsUrlStreamObs?
var twitch: MoblinSettingsUrlStreamTwitch?
var kick: MoblinSettingsUrlStreamKick?
init(name: String, url: String) {
self.name = name
self.url = url
}
}
class MoblinSettingsButton: Codable {
var type: SettingsButtonType
var enabled: Bool?
init(type: SettingsButtonType) {
self.type = type
}
}
class MoblinQuickButtons: Codable {
var twoColumns: Bool?
var showName: Bool?
var enableScroll: Bool?
// Use "buttons" to enable buttons after disabling all.
var disableAllButtons: Bool?
var buttons: [MoblinSettingsButton]?
}
class MoblinSettingsUrl: Codable {
// The last enabled stream will be selected (if any).
var streams: [MoblinSettingsUrlStream]?
var quickButtons: MoblinQuickButtons?
var webBrowser: MoblinSettingsWebBrowser?
func toString() throws -> String {
let encoder = JSONEncoder()
encoder.outputFormatting = [.sortedKeys, .withoutEscapingSlashes]
return try String.fromUtf8(data: encoder.encode(self))
}
static func fromString(query: String) throws -> MoblinSettingsUrl {
let query = try JSONDecoder().decode(
MoblinSettingsUrl.self,
from: query.data(using: .utf8)!
)
for stream in query.streams ?? [] {
if let message = isValidUrl(url: cleanUrl(url: stream.url)) {
throw message
}
if let srt = stream.srt {
if let latency = srt.latency {
if latency < 0 {
throw "Negative SRT latency"
}
}
}
if let obs = stream.obs {
if let message = isValidWebSocketUrl(url: cleanUrl(url: obs.webSocketUrl)) {
throw message
}
}
}
return query
}
}