From 317dc2483f1d2db54bf24cff3b6b066689983c0b Mon Sep 17 00:00:00 2001 From: Kristian Martinoski Date: Mon, 16 Dec 2024 17:05:50 +0100 Subject: [PATCH] ios fixes --- packages/client/src/client-details.ts | 1 + packages/client/src/stats/SfuStatsReporter.ts | 4 + .../react-native-sdk/ios/DeviceStats.swift | 78 ------------------- .../ios/StreamVideoReactNative.m | 5 +- .../src/providers/StreamCall.tsx | 10 +-- 5 files changed, 12 insertions(+), 86 deletions(-) delete mode 100644 packages/react-native-sdk/ios/DeviceStats.swift diff --git a/packages/client/src/client-details.ts b/packages/client/src/client-details.ts index 0a09ef877..4350606c4 100644 --- a/packages/client/src/client-details.ts +++ b/packages/client/src/client-details.ts @@ -125,6 +125,7 @@ export const setDeviceState = (state: { thermal: string; isLowPowerMode: boolean; }) => { + console.log('🚀 ~ isLowPowerMode:', state.isLowPowerMode); if (state.os === 'android') { deviceState = { oneofKind: 'android', diff --git a/packages/client/src/stats/SfuStatsReporter.ts b/packages/client/src/stats/SfuStatsReporter.ts index 0f8996dee..d146a0ff8 100644 --- a/packages/client/src/stats/SfuStatsReporter.ts +++ b/packages/client/src/stats/SfuStatsReporter.ts @@ -128,6 +128,10 @@ export class SfuStatsReporter { this.publisher?.getStats().then(flatten).then(JSON.stringify) ?? '[]', ]); + console.log( + '🚀 ~ SfuStatsReporter ~ run= ~ getDeviceState():', + getDeviceState(), + ); await this.sfuClient.sendStats({ sdk: this.sdkName, sdkVersion: this.sdkVersion, diff --git a/packages/react-native-sdk/ios/DeviceStats.swift b/packages/react-native-sdk/ios/DeviceStats.swift deleted file mode 100644 index 1c632ba0e..000000000 --- a/packages/react-native-sdk/ios/DeviceStats.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// DeviceStats.swift -// StreamVideoReactNative -// -// Created by Kristian Martinoski on 12.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; - } - -} diff --git a/packages/react-native-sdk/ios/StreamVideoReactNative.m b/packages/react-native-sdk/ios/StreamVideoReactNative.m index 06af3822b..a5ec1da45 100644 --- a/packages/react-native-sdk/ios/StreamVideoReactNative.m +++ b/packages/react-native-sdk/ios/StreamVideoReactNative.m @@ -92,7 +92,6 @@ -(void)clearObserver { -(void)startObserving { hasListeners = YES; - self.hasListeners = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(powerModeDidChange) name:NSProcessInfoPowerStateDidChangeNotification @@ -114,7 +113,7 @@ -(void)stopObserving { } - (void)powerModeDidChange { - if (!self.hasListeners) { + if (!hasListeners) { return; } BOOL lowPowerEnabled = [NSProcessInfo processInfo].lowPowerModeEnabled; @@ -122,7 +121,7 @@ - (void)powerModeDidChange { } - (void)thermalStateDidChange { - if (!self.hasListeners) { + if (!hasListeners) { return; } NSInteger thermalState = [NSProcessInfo processInfo].thermalState; diff --git a/packages/react-native-sdk/src/providers/StreamCall.tsx b/packages/react-native-sdk/src/providers/StreamCall.tsx index 9926e76fe..4d03aca91 100644 --- a/packages/react-native-sdk/src/providers/StreamCall.tsx +++ b/packages/react-native-sdk/src/providers/StreamCall.tsx @@ -208,25 +208,25 @@ const DeviceStats = () => { } powerModeSubscription = eventEmitter.addListener( - StreamVideoReactNative.POWER_MODE_EVENT, + 'isLowPowerModeEnabled', (isLowPowerMode: boolean) => handleLowPowerMode(isLowPowerMode, Platform.OS) ); if (thermalState === null) { - StreamVideoReactNative.startThermalStatusUpdates().then( + StreamVideoReactNative.currentThermalState().then( (initialState: string) => handleThermalState(initialState, Platform.OS) ); } thermalStateSubscription = eventEmitter.addListener( - StreamVideoReactNative.THERMAL_EVENT, + 'thermalStateDidChange', (status: string) => handleThermalState(status, Platform.OS) ); } else { - eventEmitter.removeAllListeners(StreamVideoReactNative.POWER_MODE_EVENT); - eventEmitter.removeAllListeners(StreamVideoReactNative.THERMAL_EVENT); + eventEmitter.removeAllListeners('isLowPowerModeEnabled'); + eventEmitter.removeAllListeners('thermalStateDidChange'); } return () => {