Skip to content

Commit

Permalink
Detect and monitor network type during LO and apply right FPS settings
Browse files Browse the repository at this point in the history
This PR creates to monitoring systems:
1. Network connection monitor, that keeps an eye on the type of connection
the phone has.
2. Fps monitor keeps an eye on the connection type, and updates needed
fps accordingly

MOB-2706
  • Loading branch information
rasmustautsglia committed Oct 17, 2023
1 parent 9102f5a commit 9889bc0
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 3 deletions.
24 changes: 24 additions & 0 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@
C0175A2C2A67E2E9001FACDE /* Theme+Gva.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0175A2B2A67E2E9001FACDE /* Theme+Gva.swift */; };
C02248A72AD53DDA00CC4930 /* LiveObservationConfirmation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C02248A62AD53DDA00CC4930 /* LiveObservationConfirmation.swift */; };
C02248AA2AD53E6100CC4930 /* LiveObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C02248A92AD53E6100CC4930 /* LiveObservation.swift */; };
C02248AE2ADD791C00CC4930 /* FpsMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C02248AD2ADD791C00CC4930 /* FpsMonitor.swift */; };
C02248B02ADD797F00CC4930 /* NetworkConnectionMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C02248AF2ADD797F00CC4930 /* NetworkConnectionMonitor.swift */; };
C03A8047292BA76D00DDECA6 /* ChatViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C03A8046292BA76D00DDECA6 /* ChatViewControllerTests.swift */; };
C03A8049292BC8DB00DDECA6 /* CallViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C03A8048292BC8DB00DDECA6 /* CallViewControllerTests.swift */; };
C05AB01C295F416700AA381F /* VisitorCodeCloseButtonProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05AB01B295F416700AA381F /* VisitorCodeCloseButtonProperties.swift */; };
Expand Down Expand Up @@ -1333,6 +1335,8 @@
C0175A2B2A67E2E9001FACDE /* Theme+Gva.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+Gva.swift"; sourceTree = "<group>"; };
C02248A62AD53DDA00CC4930 /* LiveObservationConfirmation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveObservationConfirmation.swift; sourceTree = "<group>"; };
C02248A92AD53E6100CC4930 /* LiveObservation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveObservation.swift; sourceTree = "<group>"; };
C02248AD2ADD791C00CC4930 /* FpsMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FpsMonitor.swift; sourceTree = "<group>"; };
C02248AF2ADD797F00CC4930 /* NetworkConnectionMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConnectionMonitor.swift; sourceTree = "<group>"; };
C03A8046292BA76D00DDECA6 /* ChatViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewControllerTests.swift; sourceTree = "<group>"; };
C03A8048292BC8DB00DDECA6 /* CallViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallViewControllerTests.swift; sourceTree = "<group>"; };
C05AB016295DA9FC00AA381F /* AlertViewController+VisitorCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AlertViewController+VisitorCode.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2061,6 +2065,8 @@
1A60AFC12566857200E53F53 /* Sources */ = {
isa = PBXGroup;
children = (
C02248AC2ADD78F000CC4930 /* FpsMonitor */,
C02248AB2ADD785800CC4930 /* NetworkConnectionMonitor */,
C02248A82AD53DDF00CC4930 /* LiveObservation */,
84D5B95E2A14DEFD00807F92 /* QuickLookBased */,
C05E3EDC29C99DEE0013BC81 /* ProximityManager */,
Expand Down Expand Up @@ -3525,6 +3531,22 @@
path = LiveObservation;
sourceTree = "<group>";
};
C02248AB2ADD785800CC4930 /* NetworkConnectionMonitor */ = {
isa = PBXGroup;
children = (
C02248AF2ADD797F00CC4930 /* NetworkConnectionMonitor.swift */,
);
path = NetworkConnectionMonitor;
sourceTree = "<group>";
};
C02248AC2ADD78F000CC4930 /* FpsMonitor */ = {
isa = PBXGroup;
children = (
C02248AD2ADD791C00CC4930 /* FpsMonitor.swift */,
);
path = FpsMonitor;
sourceTree = "<group>";
};
C05E3EDC29C99DEE0013BC81 /* ProximityManager */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4545,6 +4567,7 @@
1A8366B025FF40AB005FE7EE /* LocalFile.swift in Sources */,
84265E62298D7B2900D65842 /* ScreenSharingCoordinator+DelegateEvent.swift in Sources */,
C0D2F048299272D100803B47 /* VideoCallView.ConnectOperatorView.swift in Sources */,
C02248B02ADD797F00CC4930 /* NetworkConnectionMonitor.swift in Sources */,
9A3E1D8A27B6B824005634EB /* FileDownload.Environment.Interface.swift in Sources */,
C0175A152A56E2DD001FACDE /* Gva.swift in Sources */,
9A8130B727D7578500220BBD /* LocalFile.Environment.Mock.swift in Sources */,
Expand Down Expand Up @@ -4713,6 +4736,7 @@
3115D45C29A4FD3F00D99561 /* SecureConversations.Availability.swift in Sources */,
9A19926E27D3BB7800161AAE /* Theme.Mock.swift in Sources */,
9AE9E4B127E0E45200BFE239 /* CallViewController.Mock.swift in Sources */,
C02248AE2ADD791C00CC4930 /* FpsMonitor.swift in Sources */,
9AE0A7642822B02C00725946 /* FontScaling.Environment.Mock.swift in Sources */,
AFC40C1C29965F0F001B4C53 /* SecureConversations.ChatWithTranscriptModel.swift in Sources */,
6B48213E2735873300F2900A /* Feature.swift in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions GliaWidgets/Sources/FpsMonitor/FpsMonitor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation
import Combine

class FpsMonitor {
@Published private(set) var currentFPS: Int = 1

private let wifiFps: Int
private let cellularFps: Int
private var cancellables: Set<AnyCancellable> = []

init(
environment: Environment,
wifiFps: Int,
cellularFps: Int
) {
self.wifiFps = wifiFps
self.cellularFps = cellularFps

environment.networkMonitor.$connectionType
.map { connectionType -> Int in
switch connectionType {
case .unlimited:
return self.wifiFps
case .metered, .unknown:
return self.cellularFps
}
}
.assign(to: \.currentFPS, on: self)
.store(in: &cancellables)
}
}

extension FpsMonitor {
struct Environment {
let networkMonitor: NetworkConnectionMonitor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extension Glia {
var screenShareHandler: ScreenShareHandler
var messagesWithUnreadCountLoaderScheduler: CoreSdkClient.ReactiveSwift.DateScheduler
var orientationManager: OrientationManager
var networkConnectionMonitor: NetworkConnectionMonitor
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ extension Glia.Environment {
uiApplication: .live,
uiDevice: .live,
notificationCenter: .live
))
)),

Check warning on line 35 in GliaWidgets/Sources/GliaEnvironment/Glia.Environment.Live.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
networkConnectionMonitor: .init()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extension Glia.Environment {
createFileUploadListModel: SecureConversations.FileUploadListViewModel.mock(environment:),
screenShareHandler: .mock,
messagesWithUnreadCountLoaderScheduler: CoreSdkClient.reactiveSwiftDateSchedulerMock,
orientationManager: .mock()
orientationManager: .mock(),
networkConnectionMonitor: .init()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Network
import Combine

class NetworkConnectionMonitor: ObservableObject {
@Published private(set) var connectionType: ConnectionType = .unknown

private var monitor: NWPathMonitor?
private var queue = DispatchQueue(label: "NetworkMonitor")

init() {
monitor = NWPathMonitor()
monitor?.pathUpdateHandler = { [weak self] path in
guard let self = self else { return }
guard path.status == .satisfied else {

Check warning on line 14 in GliaWidgets/Sources/NetworkConnectionMonitor/NetworkConnectionMonitor.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// No conection to the internet
self.connectionType = .unknown
return
}

if path.usesInterfaceType(.wifi) {
self.connectionType = .unlimited
} else if path.usesInterfaceType(.cellular) {
self.connectionType = .metered
} else {
self.connectionType = .unknown
}
}

monitor?.start(queue: queue)
}
}

extension NetworkConnectionMonitor {
enum ConnectionType {
case unlimited
case metered
case unknown
}
}
3 changes: 2 additions & 1 deletion GliaWidgetsTests/Glia.Environment.Failing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ extension Glia.Environment {
},
screenShareHandler: .mock,
messagesWithUnreadCountLoaderScheduler: CoreSdkClient.reactiveSwiftDateSchedulerMock,
orientationManager: .mock()
orientationManager: .mock(),
networkConnectionMonitor: .init()
)
}

Expand Down

0 comments on commit 9889bc0

Please sign in to comment.