Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Format .swift files
Browse files Browse the repository at this point in the history
  • Loading branch information
incubo4u committed Dec 21, 2023
1 parent 5eceb72 commit b19ba37
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 77 deletions.
28 changes: 19 additions & 9 deletions MembraneRTCTest/PeerConnectionManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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")

Expand All @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion MembraneVideoroomDemo/Controllers/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
26 changes: 18 additions & 8 deletions MembraneVideoroomDemo/Controllers/RoomController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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)

}
Expand Down
3 changes: 2 additions & 1 deletion MembraneVideoroomDemo/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion MembraneVideoroomDemo/Views/ParticipantVideoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions MembraneVideoroomDemo/Views/RoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion Sources/MembraneRTC/IPC/IPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public class IPCServer: IPC {
port = CFMessagePortCreateLocal(
nil, name as CFString,
{
(port: CFMessagePort?, id: Int32, data: CFData?, _: UnsafeMutableRawPointer?) -> Unmanaged<CFData>? in
(port: CFMessagePort?, id: Int32, data: CFData?, _: UnsafeMutableRawPointer?) -> Unmanaged<
CFData
>? in
guard let selfObj = port?.associatedSelf() as? IPCServer,
let data = data as Data?
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 8 additions & 6 deletions Sources/MembraneRTC/Media/Tracks/LocalVideoTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,12 +41,12 @@ public class LocalVideoTrack: VideoTrack, LocalTrack {
}

/**
Use this to create a local track for preview etc.
For local track that is sent to the backend use `createVideoTrack` from MembraneRTC
Use this to create a local track for preview etc.
For local track that is sent to the backend use `createVideoTrack` from MembraneRTC

- Parameters:
- videoParameters: The parameters used for choosing the proper camera resolution and target framerate
*/
- Parameters:
- videoParameters: The parameters used for choosing the proper camera resolution and target framerate
*/
public static func create(videoParameters: VideoParameters) -> LocalVideoTrack {
return create(
for: .camera, videoParameters: videoParameters,
Expand Down
Loading

0 comments on commit b19ba37

Please sign in to comment.