Skip to content

Commit e6c8215

Browse files
committed
Allow connecting to the signaling server via URL
1 parent e6c847a commit e6c8215

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/BandwidthWebRTC/RTCBandwidth.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ public class RTCBandwidth: NSObject {
6464
}
6565
}
6666

67+
/// Connect to the signaling server to start publishing media.
68+
/// - Parameters:
69+
/// - url: Complete URL containing everything required to access WebRTC.
70+
/// - completion: The completion handler to call when the connect request is complete.
71+
/// - Throws: Throw when a connection to the signaling server experiences an error.
72+
public func connect(to url: URL, completion: @escaping () -> Void) throws {
73+
signaling = Signaling()
74+
signaling?.delegate = self
75+
76+
try signaling?.connect(to: url) {
77+
completion()
78+
}
79+
}
80+
6781
/// Disconnect from Bandwidth's WebRTC signaling server and remove all local connections.
6882
public func disconnect() {
6983
signaling?.disconnect()

Sources/BandwidthWebRTC/Signaling/Signaling.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protocol SignalingDelegate {
2727

2828
class Signaling {
2929
private let client = Client()
30-
30+
3131
var delegate: SignalingDelegate?
3232

3333
func connect(using token: String, completion: @escaping () -> Void) throws {
@@ -44,6 +44,12 @@ class Signaling {
4444
throw SignalingError.invalidWebSocketURL
4545
}
4646

47+
try connect(to: url) {
48+
completion()
49+
}
50+
}
51+
52+
func connect(to url: URL, completion: @escaping () -> Void) throws {
4753
try client.subscribe(to: SignalingMethod.endpointRemoved.rawValue, type: EndpointRemovedParameters.self)
4854
client.on(method: SignalingMethod.endpointRemoved.rawValue, type: EndpointRemovedParameters.self) { parameters in
4955
self.delegate?.signaling(self, didReceiveEndpointRemoved: parameters)

0 commit comments

Comments
 (0)