Skip to content

Commit

Permalink
Merge pull request #41 from opentok/0.5.0
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
Manik Sachdeva authored Apr 19, 2018
2 parents fa74a55 + 59b14f4 commit abcd614
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@

10. Add the contents from the `Bridging-Header.h` file in `../node_modules/opentok-react-native/ios` to `<YourProjectName>-Bridging-Header.h`

11. Ensure you have enabled both camera and microphone usage by adding the following entries to your `Info.plist` file:

```
<key>NSCameraUsageDescription</key>
<string>Your message to user when the camera is accessed for the first time</string>
<key>NSMicrophoneUsageDescription</key>
<string>Your message to user when the microphone is accessed for the first time</string>
```

### Android Installation

1. In you terminal, change into your project directory.
Expand All @@ -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
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
```

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:
Expand Down Expand Up @@ -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 |

Expand All @@ -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!
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!
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 2 additions & 0 deletions ios/OTSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions ios/OTSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Void {
for event in events {
Expand Down
7 changes: 6 additions & 1 deletion src/OTPublisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit abcd614

Please sign in to comment.