-
Notifications
You must be signed in to change notification settings - Fork 43
feat: report low power mode and thermal info to stats #1583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1d474a1
add initial implementation for thermal info for android
kristian-mkd b6b7e9b
add PowerModeModule and optimized thermal status event reading
kristian-mkd 2eb759c
update power mode module for android
kristian-mkd 6bcf26e
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 95099ae
lobby changes
kristian-mkd 3285f62
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 4e3c055
complete feature
kristian-mkd 2a0a7e3
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 6fb9434
code clean up
kristian-mkd ba72fca
fix review remarks
kristian-mkd 947747b
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 2125dff
ios fixes
kristian-mkd ea718a9
fix streamCall review remarks
kristian-mkd 188dbe3
revert the objc version of the main module
kristian-mkd f547910
revert some changes
kristian-mkd 20bb896
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd c50a76d
new device stats methods
kristian-mkd 22a2c58
remove device stats swift
kristian-mkd edba555
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 1219bfd
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 317dc24
ios fixes
kristian-mkd ab99c7c
fix android device stats
kristian-mkd d9626f3
fix tests
kristian-mkd c36a1f7
Merge branch 'main' into report-low-power-and-thermal-info
kristian-mkd 5056b05
fix review remarks
kristian-mkd 7559c6b
review fixes
kristian-mkd ba8454c
remove unused import
kristian-mkd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // | ||
| // DeviceState.m | ||
| // StreamVideoReactNative | ||
| // | ||
| // Created by Kristian Martinoski on 3.12.24. | ||
| // Copyright © 2024 Facebook. All rights reserved. | ||
| // | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
| #import <React/RCTBridgeModule.h> | ||
| #import <React/RCTEventEmitter.h> | ||
|
|
||
| @interface | ||
| RCT_EXTERN_MODULE(DeviceState, RCTEventEmitter) | ||
| RCT_EXTERN_METHOD(isLowPowerModeEnabled: | ||
| (RCTPromiseResolveBlock) resolve | ||
| reject:(RCTPromiseRejectBlock) reject) | ||
| RCT_EXTERN_METHOD(currentThermalState: | ||
| (RCTPromiseResolveBlock) resolve | ||
| reject:(RCTPromiseRejectBlock) reject) | ||
|
|
||
| @end |
kristian-mkd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // | ||
| // DeviceState.swift | ||
| // StreamVideoReactNative | ||
| // | ||
| // Created by Kristian Martinoski on 3.12.24. | ||
| // Copyright © 2024 Facebook. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| @objc(DeviceState) | ||
| class DeviceState:RCTEventEmitter{ | ||
|
|
||
| private var hasListeners = false; | ||
| override init(){ | ||
| super.init(); | ||
| UIDevice.current.isBatteryMonitoringEnabled = true; | ||
| } | ||
|
|
||
| @objc | ||
| func isLowPowerModeEnabled(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) { | ||
| resolve(ProcessInfo.processInfo.isLowPowerModeEnabled); | ||
| } | ||
|
|
||
| @objc | ||
| func currentThermalState(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) { | ||
| resolve(ProcessInfo.processInfo.thermalState.rawValue); | ||
| } | ||
|
|
||
| override func startObserving() { | ||
| hasListeners = true; | ||
|
|
||
| NotificationCenter.default.addObserver(self, | ||
| selector: #selector(powerModeDidChange), | ||
| name: NSNotification.Name.NSProcessInfoPowerStateDidChange, object: nil) | ||
|
|
||
| NotificationCenter.default.addObserver(self, | ||
| selector: #selector(thermalStateDidChange), | ||
| name: ProcessInfo.thermalStateDidChangeNotification, object: nil) | ||
| } | ||
|
|
||
| override func stopObserving() { | ||
| hasListeners = false; | ||
|
|
||
| NotificationCenter.default.removeObserver(self, | ||
| name: NSNotification.Name.NSProcessInfoPowerStateDidChange, object: nil) | ||
|
|
||
| NotificationCenter.default.removeObserver(self, | ||
| name: NSNotification.Name.NSProcessInfoPowerStateDidChange, object: nil) | ||
| } | ||
|
|
||
| @objc func powerModeDidChange() { | ||
| if(!hasListeners) { | ||
| return; | ||
| } | ||
| let lowPowerEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled; | ||
|
|
||
| self.sendEvent(withName: "isLowPowerModeEnabled", body: lowPowerEnabled); | ||
|
|
||
| } | ||
|
|
||
| @objc func thermalStateDidChange() { | ||
| if (!hasListeners) { | ||
| return | ||
| } | ||
| let thermalState = ProcessInfo.processInfo.thermalState.rawValue | ||
| self.sendEvent(withName: "thermalStateDidChange", body: thermalState) | ||
| } | ||
|
|
||
| override func supportedEvents() -> [String]! { | ||
| return ["isLowPowerModeEnabled", "thermalStateDidChange"]; | ||
| } | ||
|
|
||
| override class func requiresMainQueueSetup() -> Bool { | ||
| return false; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.