diff --git a/.githooks/pre-commit b/.githooks/pre-commit index e0813ee8..0ee98df5 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,10 +1,10 @@ #!/bin/bash -git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do - swift-format format -i "${line}" --configuration swift-format-config.json; - git add "$line"; -done - -git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do - swift-format lint -s "${line}" --configuration swift-format-config.json || exit 1; -done \ No newline at end of file +swift-format --version 1>/dev/null 2>&1 +if [ $? -eq 0 ]; then + git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do + echo "${line}" + swift-format -i "${line}" + git add "$line" + done +fi diff --git a/MembraneRTCTest/PeerConnectionManagerTest.swift b/MembraneRTCTest/PeerConnectionManagerTest.swift index 0e7f4641..1d17dd72 100644 --- a/MembraneRTCTest/PeerConnectionManagerTest.swift +++ b/MembraneRTCTest/PeerConnectionManagerTest.swift @@ -15,7 +15,9 @@ class PeerConnectionManagerTest: XCTestCase { self.test = test super.init(encoder: encoder) } - override func createPeerConnection(_ configuration: RTCConfiguration, constraints: RTCMediaConstraints) + override func createPeerConnection( + _ configuration: RTCConfiguration, constraints: RTCMediaConstraints + ) -> RTCPeerConnection? { test.peerConnection = super.createPeerConnection(configuration, constraints: constraints) @@ -33,11 +35,13 @@ class PeerConnectionManagerTest: XCTestCase { let listener = ListenerImpl() manager = PeerConnectionManager( - config: config, peerConnectionFactory: peerConnectionFactory, peerConnectionListener: listener) + config: config, peerConnectionFactory: peerConnectionFactory, peerConnectionListener: listener + ) let expectation = XCTestExpectation(description: "Create sdp offer.") - manager.getSdpOffer(integratedTurnServers: [], tracksTypes: [:], localTracks: []) { sdp, midToTrackId, error in + manager.getSdpOffer(integratedTurnServers: [], tracksTypes: [:], localTracks: []) { + sdp, midToTrackId, error in XCTAssertNotNil(sdp, "Sdp offer wasn't created") expectation.fulfill() } @@ -56,7 +60,8 @@ class PeerConnectionManagerTest: XCTestCase { func testAddVideoTrack() throws { let videoTrack = LocalVideoTrack.create( - for: .camera, videoParameters: .presetHD43, peerConnectionFactoryWrapper: peerConnectionFactory) + for: .camera, videoParameters: .presetHD43, + peerConnectionFactoryWrapper: peerConnectionFactory) manager.addTrack(track: videoTrack, localStreamId: "id") XCTAssertFalse(peerConnection.transceivers.isEmpty, "No track added") @@ -65,9 +70,11 @@ class PeerConnectionManagerTest: XCTestCase { func testSimulcastConfig() throws { let preset: VideoParameters = .presetHD43 let videoParameters = VideoParameters( - dimensions: preset.dimensions, simulcastConfig: SimulcastConfig(enabled: true, activeEncodings: [.h, .l])) + dimensions: preset.dimensions, + simulcastConfig: SimulcastConfig(enabled: true, activeEncodings: [.h, .l])) let videoTrack = LocalVideoTrack.create( - for: .camera, videoParameters: videoParameters, peerConnectionFactoryWrapper: peerConnectionFactory) + for: .camera, videoParameters: videoParameters, + peerConnectionFactoryWrapper: peerConnectionFactory) manager.addTrack(track: videoTrack, localStreamId: "id") let encodings = peerConnection.transceivers[0].sender.parameters.encodings @@ -94,7 +101,8 @@ class PeerConnectionManagerTest: XCTestCase { simulcastConfig: SimulcastConfig(enabled: true, activeEncodings: [.h, .m, .l]) ) let videoTrack = LocalVideoTrack.create( - for: .camera, videoParameters: videoParameters, peerConnectionFactoryWrapper: peerConnectionFactory) + for: .camera, videoParameters: videoParameters, + peerConnectionFactoryWrapper: peerConnectionFactory) manager.addTrack(track: videoTrack, localStreamId: "id") @@ -112,12 +120,14 @@ class PeerConnectionManagerTest: XCTestCase { simulcastConfig: SimulcastConfig(enabled: true, activeEncodings: [.h, .m, .l]) ) let videoTrack = LocalVideoTrack.create( - for: .camera, videoParameters: videoParameters, peerConnectionFactoryWrapper: peerConnectionFactory) + for: .camera, videoParameters: videoParameters, + peerConnectionFactoryWrapper: peerConnectionFactory) manager.addTrack(track: videoTrack, localStreamId: "id") let encodings = peerConnection.transceivers[0].sender.parameters.encodings - XCTAssertEqual(1_536_000, encodings[2].maxBitrateBps, "h layer should have correct maxBitrateBps") + XCTAssertEqual( + 1_536_000, encodings[2].maxBitrateBps, "h layer should have correct maxBitrateBps") XCTAssertEqual(512000, encodings[1].maxBitrateBps, "m layer should have correct maxBitrateBps") XCTAssertEqual(153600, encodings[0].maxBitrateBps, "l layer should have correct maxBitrateBps") } diff --git a/MembraneVideoroomDemo/Controllers/App.swift b/MembraneVideoroomDemo/Controllers/App.swift index 56ca70c6..bdd7feba 100644 --- a/MembraneVideoroomDemo/Controllers/App.swift +++ b/MembraneVideoroomDemo/Controllers/App.swift @@ -22,7 +22,8 @@ final class AppController: ObservableObject { public func connect(room: String, displayName: String) { self.displayName = displayName - let engineUrl = Constants.getRtcEngineUrl().trimmingCharacters(in: CharacterSet(charactersIn: "/")) + let engineUrl = Constants.getRtcEngineUrl().trimmingCharacters( + in: CharacterSet(charactersIn: "/")) let transportUrl = "\(engineUrl)" diff --git a/MembraneVideoroomDemo/Controllers/RoomController.swift b/MembraneVideoroomDemo/Controllers/RoomController.swift index e6355d06..b671397b 100644 --- a/MembraneVideoroomDemo/Controllers/RoomController.swift +++ b/MembraneVideoroomDemo/Controllers/RoomController.swift @@ -18,7 +18,8 @@ class ParticipantVideo: Identifiable, ObservableObject { @Published var vadStatus: VadStatus init( - id: String, participant: Participant, videoTrack: VideoTrack? = nil, isScreensharing: Bool = false, + id: String, participant: Participant, videoTrack: VideoTrack? = nil, + isScreensharing: Bool = false, isActive: Bool = false, mirror: Bool = false ) { @@ -264,7 +265,9 @@ class RoomController: ObservableObject { // set the current primary video self.primaryVideo = video - if video.participant.id != self.localParticipantId && self.primaryVideo?.isScreensharing == false { + if video.participant.id != self.localParticipantId + && self.primaryVideo?.isScreensharing == false + { self.room?.setTargetTrackEncoding(trackId: video.id, encoding: TrackEncoding.h) } } @@ -325,7 +328,9 @@ class RoomController: ObservableObject { return participantVideos.first(where: { $0.id == id }) } - func findParticipantVideoByOwner(participantId: String, isScreencast: Bool = false) -> ParticipantVideo? { + func findParticipantVideoByOwner(participantId: String, isScreencast: Bool = false) + -> ParticipantVideo? + { if let primaryVideo = self.primaryVideo, primaryVideo.participant.id == participantId, primaryVideo.isScreensharing == isScreencast { @@ -438,9 +443,11 @@ extension RoomController: MembraneRTCDelegate { let isScreensharing = ctx.metadata["type"] as? String == "screensharing" let video = ParticipantVideo( id: ctx.trackId, participant: participant, videoTrack: videoTrack, - isScreensharing: isScreensharing, isActive: ctx.metadata["active"] as? Bool == true || isScreensharing) + isScreensharing: isScreensharing, + isActive: ctx.metadata["active"] as? Bool == true || isScreensharing) - guard let existingVideo = self.findParticipantVideoByOwner(participantId: ctx.endpoint.id) else { + guard let existingVideo = self.findParticipantVideoByOwner(participantId: ctx.endpoint.id) + else { add(video: video) if isScreensharing { @@ -505,7 +512,8 @@ extension RoomController: MembraneRTCDelegate { if ctx.endpoint.id == self.primaryVideo?.participant.id { self.primaryVideo?.participant = p } else { - self.participantVideos.first(where: { $0.participant.id == ctx.endpoint.id })?.participant = p + self.participantVideos.first(where: { $0.participant.id == ctx.endpoint.id })? + .participant = p } } @@ -514,9 +522,11 @@ extension RoomController: MembraneRTCDelegate { func onEndpointAdded(endpoint: Endpoint) { self.participants[endpoint.id] = Participant( - id: endpoint.id, displayName: endpoint.metadata["displayName"] as? String ?? "", isAudioTrackActive: false) + id: endpoint.id, displayName: endpoint.metadata["displayName"] as? String ?? "", + isAudioTrackActive: false) let pv = - ParticipantVideo(id: endpoint.id, participant: participants[endpoint.id]!, videoTrack: nil, isActive: false) + ParticipantVideo( + id: endpoint.id, participant: participants[endpoint.id]!, videoTrack: nil, isActive: false) add(video: pv) } diff --git a/MembraneVideoroomDemo/Utilities/Constants.swift b/MembraneVideoroomDemo/Utilities/Constants.swift index ea7495ee..3f1d09d8 100644 --- a/MembraneVideoroomDemo/Utilities/Constants.swift +++ b/MembraneVideoroomDemo/Utilities/Constants.swift @@ -3,7 +3,8 @@ import Foundation /// A bunch of application specific constants struct Constants { static func getRtcEngineUrl() -> String { - return (Bundle.main.infoDictionary?["videoroom_url"] as! String).replacingOccurrences(of: "\\", with: "") + return (Bundle.main.infoDictionary?["videoroom_url"] as! String).replacingOccurrences( + of: "\\", with: "") } /// App Group used for communicating with `Broadcast Upload Extension` diff --git a/MembraneVideoroomDemo/Views/ParticipantVideoView.swift b/MembraneVideoroomDemo/Views/ParticipantVideoView.swift index aa762fee..9a88a92f 100644 --- a/MembraneVideoroomDemo/Views/ParticipantVideoView.swift +++ b/MembraneVideoroomDemo/Views/ParticipantVideoView.swift @@ -41,7 +41,8 @@ struct ParticipantVideoView: View { ZStack(alignment: .topLeading) { if self.participantVideo.isActive { SwiftUIVideoView( - (self.participantVideo.videoTrack)!, layout: self.layout, mirror: self.participantVideo.mirror, + (self.participantVideo.videoTrack)!, layout: self.layout, + mirror: self.participantVideo.mirror, dimensions: $localDimensions ) .onChange(of: localDimensions) { value in diff --git a/MembraneVideoroomDemo/Views/RoomView.swift b/MembraneVideoroomDemo/Views/RoomView.swift index 8c4a29d6..5275e66f 100644 --- a/MembraneVideoroomDemo/Views/RoomView.swift +++ b/MembraneVideoroomDemo/Views/RoomView.swift @@ -237,8 +237,10 @@ struct RoomView: View { } else { AdaptiveStack(orientation: self.orientationReceiver.orientation) { if let primaryVideo = room.primaryVideo { - ParticipantVideoView(primaryVideo, height: videoFrameHeight, width: videoFrameWidth) - .padding(.bottom) + ParticipantVideoView( + primaryVideo, height: videoFrameHeight, width: videoFrameWidth + ) + .padding(.bottom) } VStack { diff --git a/Sources/MembraneRTC/IPC/IPC.swift b/Sources/MembraneRTC/IPC/IPC.swift index 2545a220..b1dc3d15 100644 --- a/Sources/MembraneRTC/IPC/IPC.swift +++ b/Sources/MembraneRTC/IPC/IPC.swift @@ -70,7 +70,9 @@ public class IPCServer: IPC { port = CFMessagePortCreateLocal( nil, name as CFString, { - (port: CFMessagePort?, id: Int32, data: CFData?, _: UnsafeMutableRawPointer?) -> Unmanaged? in + (port: CFMessagePort?, id: Int32, data: CFData?, _: UnsafeMutableRawPointer?) -> Unmanaged< + CFData + >? in guard let selfObj = port?.associatedSelf() as? IPCServer, let data = data as Data? else { diff --git a/Sources/MembraneRTC/Media/Tracks/LocalScreenBroadcastTrack.swift b/Sources/MembraneRTC/Media/Tracks/LocalScreenBroadcastTrack.swift index 6b51566c..e70e5661 100644 --- a/Sources/MembraneRTC/Media/Tracks/LocalScreenBroadcastTrack.swift +++ b/Sources/MembraneRTC/Media/Tracks/LocalScreenBroadcastTrack.swift @@ -14,10 +14,12 @@ public class LocalScreenBroadcastTrack: LocalVideoTrack, ScreenBroadcastCapturer internal init( appGroup: String, videoParameters: VideoParameters, - delegate _: LocalScreenBroadcastTrackDelegate? = nil, peerConnectionFactoryWrapper: PeerConnectionFactoryWrapper + delegate _: LocalScreenBroadcastTrackDelegate? = nil, + peerConnectionFactoryWrapper: PeerConnectionFactoryWrapper ) { self.appGroup = appGroup - super.init(parameters: videoParameters, peerConnectionFactoryWrapper: peerConnectionFactoryWrapper) + super.init( + parameters: videoParameters, peerConnectionFactoryWrapper: peerConnectionFactoryWrapper) } internal func started() { diff --git a/Sources/MembraneRTC/Media/Tracks/LocalVideoTrack.swift b/Sources/MembraneRTC/Media/Tracks/LocalVideoTrack.swift index 691d3d92..acf437df 100644 --- a/Sources/MembraneRTC/Media/Tracks/LocalVideoTrack.swift +++ b/Sources/MembraneRTC/Media/Tracks/LocalVideoTrack.swift @@ -11,7 +11,9 @@ public class LocalVideoTrack: VideoTrack, LocalTrack { case camera, file } - internal init(parameters: VideoParameters, peerConnectionFactoryWrapper: PeerConnectionFactoryWrapper) { + internal init( + parameters: VideoParameters, peerConnectionFactoryWrapper: PeerConnectionFactoryWrapper + ) { let source = peerConnectionFactoryWrapper.createVideoSource() videoSource = source diff --git a/Sources/MembraneRTC/MembraneRTC.swift b/Sources/MembraneRTC/MembraneRTC.swift index 563e54cc..403232dd 100644 --- a/Sources/MembraneRTC/MembraneRTC.swift +++ b/Sources/MembraneRTC/MembraneRTC.swift @@ -25,7 +25,8 @@ internal let pcLogPrefix = "[PeerConnection]" /// Once the user created the MembraneRTC client and connected to the server transport layer they can call the `connect` method to initialize joining the session. /// After receiving `onConnected` a user will receive notification about various peers joining/leaving the session, new tracks being published and ready for playback /// or going inactive. -public class MembraneRTC: MulticastDelegate, ObservableObject, RTCEngineListener, +public class MembraneRTC: MulticastDelegate, ObservableObject, + RTCEngineListener, PeerConnectionListener { enum State { @@ -58,7 +59,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje private var localTracks: [LocalTrack] = [] - private var localEndpoint = Endpoint(id: "", type: "webrtc", metadata: .init([:]), trackIdToMetadata: [:]) + private var localEndpoint = Endpoint( + id: "", type: "webrtc", metadata: .init([:]), trackIdToMetadata: [:]) // mapping from peer's id to itself private var remoteEndpoints: [String: Endpoint] = [:] @@ -73,7 +75,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje private lazy var peerConnectionManager: PeerConnectionManager = { return PeerConnectionManager( - config: self.config, peerConnectionFactory: self.peerConnectionFactoryWrapper, peerConnectionListener: self) + config: self.config, peerConnectionFactory: self.peerConnectionFactoryWrapper, + peerConnectionListener: self) }() internal init(config: RTCConfiguration, encoder: Encoder) { @@ -101,7 +104,9 @@ public class MembraneRTC: MulticastDelegate, ObservableObje - Returns: `MembraneRTC` client instance */ - public static func create(with options: CreateOptions = CreateOptions(), delegate: MembraneRTCDelegate) + public static func create( + with options: CreateOptions = CreateOptions(), delegate: MembraneRTCDelegate + ) -> MembraneRTC { DispatchQueue.webRTC.sync { @@ -173,7 +178,9 @@ public class MembraneRTC: MulticastDelegate, ObservableObje - Returns: `LocalCameraVideoTrack` instance that user then can use for things such as front / back camera switch. */ - public func createVideoTrack(videoParameters: VideoParameters, metadata: Metadata, captureDeviceId: String? = nil) + public func createVideoTrack( + videoParameters: VideoParameters, metadata: Metadata, captureDeviceId: String? = nil + ) -> LocalVideoTrack { DispatchQueue.webRTC.sync { @@ -183,7 +190,9 @@ public class MembraneRTC: MulticastDelegate, ObservableObje peerConnectionManager.addTrack(track: videoTrack, localStreamId: localStreamId) - if let captureDeviceId = captureDeviceId, let videoTrack = videoTrack as? LocalCameraVideoTrack { + if let captureDeviceId = captureDeviceId, + let videoTrack = videoTrack as? LocalCameraVideoTrack + { videoTrack.switchCamera(deviceId: captureDeviceId) } @@ -191,7 +200,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje localTracks.append(videoTrack) - localEndpoint = localEndpoint.withTrack(trackId: videoTrack.rtcTrack().trackId, metadata: metadata) + localEndpoint = localEndpoint.withTrack( + trackId: videoTrack.rtcTrack().trackId, metadata: metadata) engineCommunication.renegotiateTracks() @@ -219,7 +229,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje localTracks.append(audioTrack) - localEndpoint = localEndpoint.withTrack(trackId: audioTrack.rtcTrack().trackId, metadata: metadata) + localEndpoint = localEndpoint.withTrack( + trackId: audioTrack.rtcTrack().trackId, metadata: metadata) engineCommunication.renegotiateTracks() @@ -398,7 +409,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje */ public func setEncodingBandwidth(trackId: String, encoding: String, bandwidth: BandwidthLimit) { DispatchQueue.webRTC.sync { - peerConnectionManager.setEncodingBandwidth(trackId: trackId, encoding: encoding, bandwidth: bandwidth) + peerConnectionManager.setEncodingBandwidth( + trackId: trackId, encoding: encoding, bandwidth: bandwidth) } } @@ -470,7 +482,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje // initialize peer's track contexts endpoint.trackIdToMetadata?.forEach { trackId, metadata in - let context = TrackContext(track: nil, enpoint: endpoint, trackId: trackId, metadata: metadata) + let context = TrackContext( + track: nil, enpoint: endpoint, trackId: trackId, metadata: metadata) self.trackContexts[trackId] = context @@ -551,7 +564,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje func onOfferData(integratedTurnServers: [OfferDataEvent.TurnServer], tracksTypes: [String: Int]) { peerConnectionManager.getSdpOffer( - integratedTurnServers: integratedTurnServers, tracksTypes: tracksTypes, localTracks: localTracks + integratedTurnServers: integratedTurnServers, tracksTypes: tracksTypes, + localTracks: localTracks ) { sdp, midToTrackId, error in if let err = error { sdkLogger.error("Failed to create sdp offer: \(err)") @@ -568,7 +582,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje } func onSdpAnswer(type: String, sdp: String, midToTrackId: [String: String?]) { - peerConnectionManager.onSdpAnswer(sdp: sdp, midToTrackId: midToTrackId, localTracks: localTracks) + peerConnectionManager.onSdpAnswer( + sdp: sdp, midToTrackId: midToTrackId, localTracks: localTracks) } func onRemoteCandidate(candidate: String, sdpMLineIndex: Int32, sdpMid: String?) { @@ -594,7 +609,8 @@ public class MembraneRTC: MulticastDelegate, ObservableObje // for each track create a corresponding track context endpoint.trackIdToMetadata?.forEach { trackId, metadata in - let context = TrackContext(track: nil, enpoint: endpoint, trackId: trackId, metadata: metadata) + let context = TrackContext( + track: nil, enpoint: endpoint, trackId: trackId, metadata: metadata) self.trackContexts[trackId] = context @@ -638,7 +654,9 @@ public class MembraneRTC: MulticastDelegate, ObservableObje } } - func onTrackEncodingChanged(endpointId: String, trackId: String, encoding: String, encodingReason: String) { + func onTrackEncodingChanged( + endpointId: String, trackId: String, encoding: String, encodingReason: String + ) { if let trackEncoding = TrackEncoding.fromString(encoding), let trackContext = self.trackContexts[trackId], let encodingReasonEnum = EncodingReason(rawValue: encodingReason) diff --git a/Sources/MembraneRTC/PeerConnectionManager.swift b/Sources/MembraneRTC/PeerConnectionManager.swift index 7df67667..3a62af65 100644 --- a/Sources/MembraneRTC/PeerConnectionManager.swift +++ b/Sources/MembraneRTC/PeerConnectionManager.swift @@ -282,7 +282,8 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate { let duration = it.values["qualityLimitationDurations"] as? [String: Double] let qualityLimitation: QualityLimitationDurations = QualityLimitationDurations( bandwidth: duration?["bandwidth"] ?? 0.0, - cpu: duration?["cpu"] ?? 0.0, none: duration?["none"] ?? 0.0, other: duration?["other"] ?? 0.0) + cpu: duration?["cpu"] ?? 0.0, none: duration?["none"] ?? 0.0, + other: duration?["other"] ?? 0.0) let tmp = RTCOutboundStats( kind: it.values["kind"] as? String ?? "", @@ -342,7 +343,8 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate { private func splitBitrate(encodings: [RTCRtpEncodingParameters], bitrate: Int) { if encodings.isEmpty { - sdkLogger.error("\(#function): Attempted to limit bandwidth of the track that doesn't have any encodings") + sdkLogger.error( + "\(#function): Attempted to limit bandwidth of the track that doesn't have any encodings") return } @@ -380,7 +382,8 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate { integratedTurnServers: [OfferDataEvent.TurnServer], tracksTypes: [String: Int], localTracks: [LocalTrack], - onCompletion: @escaping (_ sdp: String?, _ midToTrackId: [String: String]?, _ error: Error?) -> Void + onCompletion: @escaping (_ sdp: String?, _ midToTrackId: [String: String]?, _ error: Error?) -> + Void ) { setTurnServers(integratedTurnServers) @@ -470,7 +473,8 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate { localTracks.forEach({ track in if track.rtcTrack().kind == "video" && (track as? LocalVideoTrack)?.videoParameters.simulcastConfig.enabled ?? false - && (track as? LocalVideoTrack)?.videoParameters.simulcastConfig.activeEncodings.contains(encoding) + && (track as? LocalVideoTrack)?.videoParameters.simulcastConfig.activeEncodings.contains( + encoding) != true { encodingsToDisable.append(encoding.description) @@ -478,7 +482,8 @@ internal class PeerConnectionManager: NSObject, RTCPeerConnectionDelegate { }) }) - let sdpWithDisabledEncodings = disableEncodings(sdpAnswer: sdp, encodingsToDisable: encodingsToDisable) + let sdpWithDisabledEncodings = disableEncodings( + sdpAnswer: sdp, encodingsToDisable: encodingsToDisable) let description = RTCSessionDescription(type: .answer, sdp: sdpWithDisabledEncodings) pc.setRemoteDescription( diff --git a/Sources/MembraneRTC/RTCEngineCommunication.swift b/Sources/MembraneRTC/RTCEngineCommunication.swift index 26c9f7c0..3d003507 100644 --- a/Sources/MembraneRTC/RTCEngineCommunication.swift +++ b/Sources/MembraneRTC/RTCEngineCommunication.swift @@ -32,9 +32,12 @@ internal class RTCEngineCommunication { sendEvent(event: LocalCandidateEvent(candidate: sdp, sdpMLineIndex: sdpMLineIndex)) } - func sdpOffer(sdp: String, trackIdToTrackMetadata: [String: Metadata], midToTrackId: [String: String]) { + func sdpOffer( + sdp: String, trackIdToTrackMetadata: [String: Metadata], midToTrackId: [String: String] + ) { sendEvent( - event: SdpOfferEvent(sdp: sdp, trackIdToTrackMetadata: trackIdToTrackMetadata, midToTrackId: midToTrackId)) + event: SdpOfferEvent( + sdp: sdp, trackIdToTrackMetadata: trackIdToTrackMetadata, midToTrackId: midToTrackId)) } private func sendEvent(event: SendableEvent) { @@ -54,12 +57,14 @@ internal class RTCEngineCommunication { switch event.type { case .Connected: let connected = event as! ConnectedEvent - engineListener.onConnected(endpointId: connected.data.id, otherEndpoints: connected.data.otherEndpoints) + engineListener.onConnected( + endpointId: connected.data.id, otherEndpoints: connected.data.otherEndpoints) case .EndpointAdded: let endpointAdded = event as! EndpointAddedEvent engineListener.onEndpointAdded( endpoint: Endpoint( - id: endpointAdded.data.id, type: endpointAdded.data.type, metadata: endpointAdded.data.metadata, + id: endpointAdded.data.id, type: endpointAdded.data.type, + metadata: endpointAdded.data.metadata, trackIdToMetadata: endpointAdded.data.trackIdToMetadata)) case .EndpointRemoved: let endpointRemoved = event as! EndpointRemovedEvent @@ -71,7 +76,8 @@ internal class RTCEngineCommunication { case .OfferData: let offerData = event as! OfferDataEvent engineListener.onOfferData( - integratedTurnServers: offerData.data.integratedTurnServers, tracksTypes: offerData.data.tracksTypes) + integratedTurnServers: offerData.data.integratedTurnServers, + tracksTypes: offerData.data.tracksTypes) case .Candidate: let candidate = event as! RemoteCandidateEvent engineListener.onRemoteCandidate( @@ -80,7 +86,8 @@ internal class RTCEngineCommunication { case .TracksAdded: let tracksAdded = event as! TracksAddedEvent engineListener.onTracksAdded( - endpointId: tracksAdded.data.endpointId, trackIdToMetadata: tracksAdded.data.trackIdToMetadata) + endpointId: tracksAdded.data.endpointId, + trackIdToMetadata: tracksAdded.data.trackIdToMetadata) case .TracksRemoved: let tracksRemoved = event as! TracksRemovedEvent engineListener.onTracksRemoved( @@ -93,7 +100,8 @@ internal class RTCEngineCommunication { case .SdpAnswer: let sdpAnswer = event as! SdpAnswerEvent engineListener.onSdpAnswer( - type: sdpAnswer.data.type, sdp: sdpAnswer.data.sdp, midToTrackId: sdpAnswer.data.midToTrackId) + type: sdpAnswer.data.type, sdp: sdpAnswer.data.sdp, + midToTrackId: sdpAnswer.data.midToTrackId) case .EncodingSwitched: let encodingSwitched = event as! EncodingSwitchedEvent engineListener.onTrackEncodingChanged( @@ -101,7 +109,8 @@ internal class RTCEngineCommunication { encoding: encodingSwitched.data.encoding, encodingReason: encodingSwitched.data.reason) case .VadNotification: let vadNotification = event as! VadNotificationEvent - engineListener.onVadNotification(trackId: vadNotification.data.trackId, status: vadNotification.data.status) + engineListener.onVadNotification( + trackId: vadNotification.data.trackId, status: vadNotification.data.status) case .BandwidthEstimation: let bandwidthEstimation = event as! BandwidthEstimationEvent engineListener.onBandwidthEstimation(estimation: Int(bandwidthEstimation.data.estimation)) diff --git a/Sources/MembraneRTC/RTCEngineListener.swift b/Sources/MembraneRTC/RTCEngineListener.swift index 1f54a17f..d33ad366 100644 --- a/Sources/MembraneRTC/RTCEngineListener.swift +++ b/Sources/MembraneRTC/RTCEngineListener.swift @@ -11,7 +11,8 @@ internal protocol RTCEngineListener { func onTracksAdded(endpointId: String, trackIdToMetadata: [String: Metadata]) func onTracksRemoved(endpointId: String, trackIds: [String]) func onTrackUpdated(endpointId: String, trackId: String, metadata: Metadata) - func onTrackEncodingChanged(endpointId: String, trackId: String, encoding: String, encodingReason: String) + func onTrackEncodingChanged( + endpointId: String, trackId: String, encoding: String, encodingReason: String) func onVadNotification(trackId: String, status: String) func onBandwidthEstimation(estimation: Int) } diff --git a/Sources/MembraneRTC/Types/EncodingReason.swift b/Sources/MembraneRTC/Types/EncodingReason.swift index cd28683b..9af26da8 100644 --- a/Sources/MembraneRTC/Types/EncodingReason.swift +++ b/Sources/MembraneRTC/Types/EncodingReason.swift @@ -1,9 +1,7 @@ -/** - * Type describing possible reasons of currently selected encoding. - * - other - the exact reason couldn't be determined - * - encoding_inactive - previously selected encoding became inactive - * - low_bandwidth - there is no longer enough bandwidth to maintain previously selected encoding - */ +/// Type describing possible reasons of currently selected encoding. +/// - other - the exact reason couldn't be determined +/// - encoding_inactive - previously selected encoding became inactive +/// - low_bandwidth - there is no longer enough bandwidth to maintain previously selected encoding public enum EncodingReason: String { case other case encoding_inactive diff --git a/Sources/MembraneRTC/Types/Endpoint.swift b/Sources/MembraneRTC/Types/Endpoint.swift index 428befad..7efc5310 100644 --- a/Sources/MembraneRTC/Types/Endpoint.swift +++ b/Sources/MembraneRTC/Types/Endpoint.swift @@ -12,7 +12,8 @@ public struct Endpoint: Codable { } public func with( - id: String? = nil, type: String? = nil, metadata: Metadata? = nil, trackIdToMetadata: [String: Metadata]? = nil + id: String? = nil, type: String? = nil, metadata: Metadata? = nil, + trackIdToMetadata: [String: Metadata]? = nil ) -> Self { return Endpoint( id: id ?? self.id, @@ -26,14 +27,18 @@ public struct Endpoint: Codable { var newTrackIdToMetadata = self.trackIdToMetadata newTrackIdToMetadata?[trackId] = metadata ?? Metadata() - return Endpoint(id: self.id, type: self.type, metadata: self.metadata, trackIdToMetadata: newTrackIdToMetadata) + return Endpoint( + id: self.id, type: self.type, metadata: self.metadata, trackIdToMetadata: newTrackIdToMetadata + ) } public func withoutTrack(trackId: String) -> Self { var newTrackIdToMetadata = self.trackIdToMetadata newTrackIdToMetadata?.removeValue(forKey: trackId) - return Endpoint(id: self.id, type: self.type, metadata: self.metadata, trackIdToMetadata: newTrackIdToMetadata) + return Endpoint( + id: self.id, type: self.type, metadata: self.metadata, trackIdToMetadata: newTrackIdToMetadata + ) } enum CodingKeys: String, CodingKey { diff --git a/Sources/MembraneRTC/Types/RTCStats.swift b/Sources/MembraneRTC/Types/RTCStats.swift index c8f72559..fffe1430 100644 --- a/Sources/MembraneRTC/Types/RTCStats.swift +++ b/Sources/MembraneRTC/Types/RTCStats.swift @@ -27,8 +27,10 @@ public struct RTCOutboundStats: RTCStats { public let qualityLimitationDurations: QualityLimitationDurations? public init( - kind: String = "", rid: String = "", bytesSent: UInt = 0, targetBitrate: Double = 0.0, packetsSent: UInt = 0, - framesEncoded: UInt = 0, framesPerSecond: Double = 0.0, frameWidth: UInt = 0, frameHeight: UInt = 0, + kind: String = "", rid: String = "", bytesSent: UInt = 0, targetBitrate: Double = 0.0, + packetsSent: UInt = 0, + framesEncoded: UInt = 0, framesPerSecond: Double = 0.0, frameWidth: UInt = 0, + frameHeight: UInt = 0, qualityLimitationDurations: QualityLimitationDurations? = nil ) { self.kind = kind @@ -59,7 +61,8 @@ public struct RTCInboundStats: RTCStats { public init( kind: String = "", jitter: Double = 0.0, packetsLost: UInt = 0, packetsReceived: UInt = 0, bytesReceived: UInt = 0, - framesReceived: UInt = 0, frameWidth: UInt = 0, frameHeight: UInt = 0, framesPerSecond: Double = 0.0, + framesReceived: UInt = 0, frameWidth: UInt = 0, frameHeight: UInt = 0, + framesPerSecond: Double = 0.0, framesDropped: UInt = 0 ) { self.kind = kind diff --git a/Sources/MembraneRTC/Types/VadStatus.swift b/Sources/MembraneRTC/Types/VadStatus.swift index 8766f542..ca3ff069 100644 --- a/Sources/MembraneRTC/Types/VadStatus.swift +++ b/Sources/MembraneRTC/Types/VadStatus.swift @@ -1,9 +1,7 @@ -/** - * Type describing Voice Activity Detection statuses. - * - * - speech - voice activity has been detected - * - silence - lack of voice activity has been detected - */ +/// Type describing Voice Activity Detection statuses. +/// +/// - speech - voice activity has been detected +/// - silence - lack of voice activity has been detected public enum VadStatus: String { case speech case silence