Skip to content

Commit 0c6b968

Browse files
committed
Revert "Use URL type internally instead of string"
This reverts commit e8d6e9b.
1 parent 2f9ad28 commit 0c6b968

File tree

6 files changed

+37
-61
lines changed

6 files changed

+37
-61
lines changed

Sources/LiveKit/Core/Room+Engine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public enum StartReconnectReason {
233233
// Room+ConnectSequences
234234
extension Room {
235235
// full connect sequence, doesn't update connection state
236-
func fullConnectSequence(_ url: URL, _ token: String) async throws {
236+
func fullConnectSequence(_ url: String, _ token: String) async throws {
237237
let connectResponse = try await signalClient.connect(url,
238238
token,
239239
connectOptions: _state.connectOptions,

Sources/LiveKit/Core/Room.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class Room: NSObject, ObservableObject, Loggable {
7777

7878
// expose engine's vars
7979
@objc
80-
public var url: String? { _state.url?.absoluteString }
80+
public var url: String? { _state.url }
8181

8282
@objc
8383
public var token: String? { _state.token }
@@ -134,7 +134,7 @@ public class Room: NSObject, ObservableObject, Loggable {
134134
var serverInfo: Livekit_ServerInfo?
135135

136136
// Engine
137-
var url: URL?
137+
var url: String?
138138
var token: String?
139139
// preferred reconnect mode which will be used only for next attempt
140140
var nextReconnectMode: ReconnectMode?
@@ -283,12 +283,7 @@ public class Room: NSObject, ObservableObject, Loggable {
283283
connectOptions: ConnectOptions? = nil,
284284
roomOptions: RoomOptions? = nil) async throws
285285
{
286-
guard let url = URL(string: url), url.isValidForSocket else {
287-
log("URL parse failed", .error)
288-
throw LiveKitError(.failedToParseUrl)
289-
}
290-
291-
log("Connecting to room...", .info)
286+
log("connecting to room...", .info)
292287

293288
var state = _state.copy()
294289

Sources/LiveKit/Core/SignalClient.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ actor SignalClient: Loggable {
110110
}
111111

112112
@discardableResult
113-
func connect(_ url: URL,
113+
func connect(_ urlString: String,
114114
_ token: String,
115115
connectOptions: ConnectOptions? = nil,
116116
reconnectMode: ReconnectMode? = nil,
@@ -122,11 +122,14 @@ actor SignalClient: Loggable {
122122
log("[Connect] mode: \(String(describing: reconnectMode))")
123123
}
124124

125-
let url = try Utils.buildUrl(url,
126-
token,
127-
connectOptions: connectOptions,
128-
reconnectMode: reconnectMode,
129-
adaptiveStream: adaptiveStream)
125+
guard let url = Utils.buildUrl(urlString,
126+
token,
127+
connectOptions: connectOptions,
128+
reconnectMode: reconnectMode,
129+
adaptiveStream: adaptiveStream)
130+
else {
131+
throw LiveKitError(.failedToParseUrl)
132+
}
130133

131134
if reconnectMode != nil {
132135
log("[Connect] with url: \(url)")
@@ -176,11 +179,14 @@ actor SignalClient: Loggable {
176179
await cleanUp(withError: error)
177180

178181
// Validate...
179-
let validateUrl = try Utils.buildUrl(url,
180-
token,
181-
connectOptions: connectOptions,
182-
adaptiveStream: adaptiveStream,
183-
validate: true)
182+
guard let validateUrl = Utils.buildUrl(urlString,
183+
token,
184+
connectOptions: connectOptions,
185+
adaptiveStream: adaptiveStream,
186+
validate: true)
187+
else {
188+
throw LiveKitError(.failedToParseUrl, message: "Failed to parse validation url")
189+
}
184190

185191
log("Validating with url: \(validateUrl)...")
186192
let validationResponse = try await HTTP.requestString(from: validateUrl)

Sources/LiveKit/Extensions/Primitives.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ extension Bool {
4242
}
4343
}
4444

45+
extension URL {
46+
var isSecure: Bool {
47+
scheme == "https" || scheme == "wss"
48+
}
49+
}
50+
4551
public extension Double {
4652
func rounded(to places: Int) -> Double {
4753
let divisor = pow(10.0, Double(places))

Sources/LiveKit/Extensions/URL.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

Sources/LiveKit/Support/Utils.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,34 +128,34 @@ class Utils {
128128
}
129129

130130
static func buildUrl(
131-
_ url: URL,
131+
_ url: String,
132132
_ token: String,
133133
connectOptions: ConnectOptions? = nil,
134134
reconnectMode: ReconnectMode? = nil,
135135
adaptiveStream: Bool,
136136
validate: Bool = false,
137137
forceSecure: Bool = false
138-
) throws -> URL {
138+
) -> URL? {
139139
// use default options if nil
140140
let connectOptions = connectOptions ?? ConnectOptions()
141141

142-
let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
142+
guard let parsedUrl = URL(string: url) else { return nil }
143143

144-
guard var builder = components else {
145-
throw LiveKitError(.failedToParseUrl)
146-
}
144+
let components = URLComponents(url: parsedUrl, resolvingAgainstBaseURL: false)
145+
146+
guard var builder = components else { return nil }
147147

148-
let useSecure = url.isSecure || forceSecure
148+
let useSecure = parsedUrl.isSecure || forceSecure
149149
let httpScheme = useSecure ? "https" : "http"
150150
let wsScheme = useSecure ? "wss" : "ws"
151151

152-
var pathSegments = url.pathComponents
152+
var pathSegments = parsedUrl.pathComponents
153153
// strip empty & slashes
154154
pathSegments.removeAll(where: { $0.isEmpty || $0 == "/" })
155155

156156
// if already ending with `rtc` or `validate`
157157
// and is not a dir, remove it
158-
if !url.hasDirectoryPath,
158+
if !parsedUrl.hasDirectoryPath,
159159
!pathSegments.isEmpty,
160160
["rtc", "validate"].contains(pathSegments.last!)
161161
{
@@ -196,11 +196,7 @@ class Utils {
196196

197197
builder.queryItems = queryItems
198198

199-
guard let result = builder.url else {
200-
throw LiveKitError(.failedToParseUrl)
201-
}
202-
203-
return result
199+
return builder.url
204200
}
205201

206202
static func computeVideoEncodings(

0 commit comments

Comments
 (0)