Skip to content

Commit

Permalink
Merge pull request #40 from opentok/camera-position
Browse files Browse the repository at this point in the history
  • Loading branch information
Manik Sachdeva authored Apr 19, 2018
2 parents 42cf136 + 3feb769 commit 59b14f4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,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 |

This comment has been minimized.

Copy link
@pandeybridgera

pandeybridgera Jun 20, 2019

not working, I have tried with
OT.changeCameraPosition(this.sessionId, "back");

This comment has been minimized.

Copy link
@ValeraShklyarov

ValeraShklyarov Jul 2, 2019

Same problem

| publishAudio | Calls OT.publishAudio() to toggle audio on and off |
| publishVideo | Calls OT.publishVideo() to toggle video on and off |

Expand Down
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 59b14f4

Please sign in to comment.