Skip to content

Commit 90fddbc

Browse files
authored
feat: add native methods to check for hardware presence in android RN-310 (#2023)
### 💡 Overview Added utility methods for detecting hardware presence SDK as below ```ts import { StreamVideoRN } from "@stream-io/video-react-native-sdk"; const hasCameraHardware = await StreamVideoRN.androidHasCameraHardware(); const hasAudioOutputHardware = await StreamVideoRN.androidHasAudioOutputHardware(); const hasMicrophoneHardware = await StreamVideoRN.androidHasMicrophoneHardware(); ``` 🎫 Ticket: https://linear.app/stream/issue/RN-310 📑 Docs: GetStream/docs-content#796
1 parent 6265ca6 commit 90fddbc

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

packages/react-native-sdk/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativeModule.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
44
import android.content.Context
55
import android.content.Intent
66
import android.content.IntentFilter
7+
import android.content.pm.PackageManager
78
import android.graphics.Bitmap
89
import android.media.AudioAttributes
910
import android.media.AudioFormat
@@ -333,6 +334,24 @@ class StreamVideoReactNativeModule(reactContext: ReactApplicationContext) :
333334
}
334335
}
335336

337+
@ReactMethod
338+
fun hasAudioOutputHardware(promise: Promise) {
339+
val hasAudioOutput = reactApplicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)
340+
promise.resolve(hasAudioOutput)
341+
}
342+
343+
@ReactMethod
344+
fun hasMicrophoneHardware(promise: Promise) {
345+
val hasAudioInput = reactApplicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE)
346+
promise.resolve(hasAudioInput)
347+
}
348+
349+
@ReactMethod
350+
fun hasCameraHardware(promise: Promise) {
351+
val hasCamera = reactApplicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
352+
promise.resolve(hasCamera)
353+
}
354+
336355
private fun getBatteryStatusFromIntent(intent: Intent): WritableMap {
337356
val status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
338357
val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)

packages/react-native-sdk/src/utils/StreamVideoRN/index.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import newNotificationCallbacks, {
55
} from '../internal/newNotificationCallbacks';
66
import { setupIosCallKeepEvents } from '../push/setupIosCallKeepEvents';
77
import { setupIosVoipPushEvents } from '../push/setupIosVoipPushEvents';
8-
import { NativeModules } from 'react-native';
8+
import { NativeModules, Platform } from 'react-native';
99

1010
// Utility type for deep partial
1111
type DeepPartial<T> = {
@@ -171,13 +171,49 @@ export class StreamVideoRN {
171171
* Play native busy tone for call rejection
172172
*/
173173
static async playBusyTone() {
174-
return NativeModules.StreamVideoReactNative?.playBusyTone();
174+
return NativeModules.StreamVideoReactNative.playBusyTone();
175175
}
176176

177177
/**
178178
* Stop native busy tone
179179
*/
180180
static async stopBusyTone() {
181-
return NativeModules.StreamVideoReactNative?.stopBusyTone();
181+
return NativeModules.StreamVideoReactNative.stopBusyTone();
182+
}
183+
184+
/**
185+
* Check if the device has audio output hardware
186+
* @returns True if the device has audio output hardware
187+
*/
188+
static async androidHasAudioOutputHardware(): Promise<boolean> {
189+
if (Platform.OS !== 'android')
190+
throw new Error(
191+
'androidHasAudioOutputHardware function is only available on Android',
192+
);
193+
return NativeModules.StreamVideoReactNative.hasAudioOutputHardware();
194+
}
195+
196+
/**
197+
* Check if the device has microphone hardware
198+
* @returns True if the device has microphone hardware
199+
*/
200+
static async androidHasMicrophoneHardware(): Promise<boolean> {
201+
if (Platform.OS !== 'android')
202+
throw new Error(
203+
'androidHasMicrophoneHardware function is only available on Android',
204+
);
205+
return NativeModules.StreamVideoReactNative.hasMicrophoneHardware();
206+
}
207+
208+
/**
209+
* Check if the device has camera hardware
210+
* @returns True if the device has camera hardware
211+
*/
212+
static async androidHasCameraHardware(): Promise<boolean> {
213+
if (Platform.OS !== 'android')
214+
throw new Error(
215+
'androidHasCameraHardware function is only available on Android',
216+
);
217+
return NativeModules.StreamVideoReactNative.hasCameraHardware();
182218
}
183219
}

0 commit comments

Comments
 (0)