Skip to content

Commit

Permalink
change ios thermal state impl to return string
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian-mkd committed Dec 31, 2024
1 parent 8ad58db commit 5b6ed61
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/client/src/client-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ export const setThermalState = (state: string) => {
}

if (osInfo.name.toLowerCase() === 'ios') {
// the thermal state is sent as number from the native side
const thermalState = parseInt(state) || 0;
const thermalState =
AppleThermalState[state as keyof typeof AppleThermalState] ||
AppleThermalState.UNSPECIFIED;

deviceState = {
oneofKind: 'apple',
Expand Down
22 changes: 20 additions & 2 deletions packages/react-native-sdk/ios/StreamVideoReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ -(instancetype)init {
}

RCT_EXPORT_METHOD(currentThermalState:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
resolve(@([NSProcessInfo processInfo].thermalState));
NSInteger thermalState = [NSProcessInfo processInfo].thermalState;
NSString *thermalStateString = [self stringForThermalState:thermalState];
resolve(thermalStateString);
}

-(void)dealloc {
Expand Down Expand Up @@ -125,7 +127,23 @@ - (void)thermalStateDidChange {
return;
}
NSInteger thermalState = [NSProcessInfo processInfo].thermalState;
[self sendEventWithName:@"thermalStateDidChange" body:@(thermalState)];
NSString *thermalStateString = [self stringForThermalState:thermalState];
[self sendEventWithName:@"thermalStateDidChange" body:thermalStateString];
}

- (NSString *)stringForThermalState:(NSInteger)thermalState {
switch (thermalState) {
case NSProcessInfoThermalStateNominal:
return @"NOMINAL";
case NSProcessInfoThermalStateFair:
return @"FAIR";
case NSProcessInfoThermalStateSerious:
return @"SERIOUS";
case NSProcessInfoThermalStateCritical:
return @"CRITICAL";
default:
return @"UNSPECIFIED";
}
}

-(void)screenShareEventReceived:(NSString*)event {
Expand Down

0 comments on commit 5b6ed61

Please sign in to comment.