Skip to content

Commit 3661903

Browse files
authored
Merge pull request #16 from Bandwidth/dev
Disable tracks when disconnecting from the server
2 parents 021ce07 + 3c365f7 commit 3661903

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Sources/BandwidthWebRTC/RTCBandwidth.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,24 @@ 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()
84+
localConnections.forEach { $0.peerConnection.senders.forEach { $0.track?.isEnabled = false } }
7085
localConnections.removeAll()
7186
}
7287

@@ -172,7 +187,7 @@ public class RTCBandwidth: NSObject {
172187
}
173188
}
174189
#endif
175-
190+
176191
private func negotiateSDP(endpointId: String, direction: String, mediaTypes: [MediaType], for peerConnection: RTCPeerConnection, completion: @escaping () -> Void) {
177192
debugPrint(direction)
178193

Sources/BandwidthWebRTC/Signaling/Signaling.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)