diff --git a/README.md b/README.md index f033e717..d4d9e6a1 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,15 @@ 10. Add the contents from the `Bridging-Header.h` file in `../node_modules/opentok-react-native/ios` to `-Bridging-Header.h` +11. Ensure you have enabled both camera and microphone usage by adding the following entries to your `Info.plist` file: + +``` +NSCameraUsageDescription +Your message to user when the camera is accessed for the first time +NSMicrophoneUsageDescription +Your message to user when the microphone is accessed for the first time +``` + ### Android Installation 1. In you terminal, change into your project directory. @@ -97,6 +106,19 @@ 6. Make sure the following in your app's gradle `compileSdkVersion`, `buildToolsVersion`, `minSdkVersion`, and `targetSdkVersion` are the same in the OpenTok React Native library. +7. As for the older Android devices, ensure you add camera and audio permissions to your `AndroidManifest.xml` file: + +```xml + + + + + + +``` + +Newer versions of Android–`API Level 23` (Android 6.0)–have a different permissions model that is already handled by this lib. + ## API Reference The `OpenTok React Native` library comprises of: @@ -210,6 +232,7 @@ The `properties` prop is used for initial set up of the Publisher and making cha | Publisher Property | Action | | --- | --- | +| cameraPosition | Calls OT.changeCameraPosition() to toggle the camera | | publishAudio | Calls OT.publishAudio() to toggle audio on and off | | publishVideo | Calls OT.publishVideo() to toggle video on and off | @@ -234,4 +257,4 @@ The `OTSubscriber` component will subscribe to a specified stream from a specifi ## Contributing -If you make changes to the project that you would like to contribute back then please follow the [contributing guidelines](CONTRIBUTING.md). All contributions are greatly appreciated! \ No newline at end of file +If you make changes to the project that you would like to contribute back then please follow the [contributing guidelines](CONTRIBUTING.md). All contributions are greatly appreciated! diff --git a/android/src/main/java/com/opentokreactnative/OTSessionManager.java b/android/src/main/java/com/opentokreactnative/OTSessionManager.java index 2509ef7c..109bbc60 100644 --- a/android/src/main/java/com/opentokreactnative/OTSessionManager.java +++ b/android/src/main/java/com/opentokreactnative/OTSessionManager.java @@ -195,6 +195,14 @@ public void publishVideo(Boolean publishVideo) { mPublisher.setPublishVideo(publishVideo); } + @ReactMethod + public void changeCameraPosition(String cameraPosition) { + + Publisher mPublisher = sharedState.getPublisher(); + mPublisher.cycleCamera(); + Log.i(TAG, "Changing camera to " + cameraPosition); + } + @ReactMethod public void setNativeEvents(ReadableArray events) { diff --git a/ios/OTSessionManager.m b/ios/OTSessionManager.m index a070a067..1a8bdc62 100644 --- a/ios/OTSessionManager.m +++ b/ios/OTSessionManager.m @@ -36,6 +36,8 @@ @interface RCT_EXTERN_MODULE(OTSessionManager, RCTEventEmitter) (BOOL)pubAudio) RCT_EXTERN_METHOD(publishVideo: (BOOL)pubVideo) +RCT_EXTERN_METHOD(changeCameraPosition: + (NSString*)cameraPosition) RCT_EXTERN_METHOD(setNativeEvents: (NSArray*)events) RCT_EXTERN_METHOD(removeNativeEvents: diff --git a/ios/OTSessionManager.swift b/ios/OTSessionManager.swift index 336592e3..243c177a 100644 --- a/ios/OTSessionManager.swift +++ b/ios/OTSessionManager.swift @@ -121,6 +121,9 @@ class OTSessionManager: RCTEventEmitter { OTRN.sharedState.publisher?.publishVideo = pubVideo; } + @objc func changeCameraPosition(_ cameraPosition: String) -> Void { + OTRN.sharedState.publisher?.cameraPosition = cameraPosition == "front" ? .front : .back; + } @objc func setNativeEvents(_ events: Array) -> Void { for event in events { diff --git a/src/OTPublisher.js b/src/OTPublisher.js index 0f9339e1..5f43234a 100644 --- a/src/OTPublisher.js +++ b/src/OTPublisher.js @@ -37,12 +37,17 @@ class OTPublisher extends Component { const updatePublisherProperty = (key, defaultValue) => { if (shouldUpdate(key, defaultValue)) { const value = useDefault(this.props.properties[key], defaultValue); - OT[key](value); + if (key === 'cameraPosition') { + OT.changeCameraPosition(value); + } else { + OT[key](value); + } } }; updatePublisherProperty('publishAudio', true); updatePublisherProperty('publishVideo', true); + updatePublisherProperty('cameraPosition', 'front'); } componentWillUnmount() { OT.destroyPublisher((error) => {