Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Sources/BandwidthWebRTC/RTCBandwidth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,24 @@ public class RTCBandwidth: NSObject {
}
}

/// Connect to the signaling server to start publishing media.
/// - Parameters:
/// - url: Complete URL containing everything required to access WebRTC.
/// - completion: The completion handler to call when the connect request is complete.
/// - Throws: Throw when a connection to the signaling server experiences an error.
public func connect(to url: URL, completion: @escaping () -> Void) throws {
signaling = Signaling()
signaling?.delegate = self

try signaling?.connect(to: url) {
completion()
}
}

/// Disconnect from Bandwidth's WebRTC signaling server and remove all local connections.
public func disconnect() {
signaling?.disconnect()
localConnections.forEach { $0.peerConnection.senders.forEach { $0.track?.isEnabled = false } }
localConnections.removeAll()
}

Expand Down Expand Up @@ -172,7 +187,7 @@ public class RTCBandwidth: NSObject {
}
}
#endif

private func negotiateSDP(endpointId: String, direction: String, mediaTypes: [MediaType], for peerConnection: RTCPeerConnection, completion: @escaping () -> Void) {
debugPrint(direction)

Expand Down
6 changes: 6 additions & 0 deletions Sources/BandwidthWebRTC/Signaling/Signaling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Signaling {
throw SignalingError.invalidWebSocketURL
}

try connect(to: url) {
completion()
}
}

func connect(to url: URL, completion: @escaping () -> Void) throws {
try client.subscribe(to: SignalingMethod.endpointRemoved.rawValue, type: EndpointRemovedParameters.self)
client.on(method: SignalingMethod.endpointRemoved.rawValue, type: EndpointRemovedParameters.self) { parameters in
self.delegate?.signaling(self, didReceiveEndpointRemoved: parameters)
Expand Down