Skip to content

Commit

Permalink
ios, android: add camera position in facing property
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlosQ authored and saghul committed Jun 11, 2019
1 parent 166b50e commit 3ea1487
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ mediaDevices.enumerateDevices().then(sourceInfos => {
let videoSourceId;
for (let i = 0; i < sourceInfos.length; i++) {
const sourceInfo = sourceInfos[i];
if(sourceInfo.kind == "video" && sourceInfo.facing == (isFront ? "front" : "back")) {
videoSourceId = sourceInfo.id;
if(sourceInfo.kind == "videoinput" && sourceInfo.facing == (isFront ? "front" : "back")) {
videoSourceId = sourceInfo.deviceId;
}
}
mediaDevices.getUserMedia({
Expand Down Expand Up @@ -93,6 +93,9 @@ pc.onicecandidate = function (event) {
// also support setRemoteDescription, createAnswer, addIceCandidate, onnegotiationneeded, oniceconnectionstatechange, onsignalingstatechange, onaddstream

```

### RTCView

However, render video stream should be used by React way.

Rendering RTCView.
Expand All @@ -101,6 +104,14 @@ Rendering RTCView.
<RTCView streamURL={this.state.stream.toURL()}/>
```

| Name | Type | Default | Description |
| ------------------------------ | ---------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| mirror | boolean | false | Indicates whether the video specified by "streamURL" should be mirrored during rendering. Commonly, applications choose to mirror theuser-facing camera. |
| objectFit | string | 'contain' | Can be contain or cover |
| streamURL | string | '' | This is mandatory |
| zOrder | number | 0 | Similarly to zIndex |


### Custom APIs

#### MediaStreamTrack.prototype._switchCamera()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ ReadableArray enumerateDevices() {

for(int i = 0; i < devices.length; ++i) {
WritableMap params = Arguments.createMap();
if (cameraEnumerator.isFrontFacing(devices[i])) {
params.putString("facing", "front");
} else {
params.putString("facing", "back");
}
params.putString("deviceId", "" + i);
params.putString("groupId", "");
params.putString("label", devices[i]);
Expand Down
7 changes: 7 additions & 0 deletions ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints {
NSMutableArray *devices = [NSMutableArray array];
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in videoDevices) {
NSString *position = @"";
if (device.position == AVCaptureDevicePositionBack) {
position = @"back";
} else if (device.position == AVCaptureDevicePositionFront) {
position = @"front";
}
[devices addObject:@{
@"facing": position,
@"deviceId": device.uniqueID,
@"groupId": @"",
@"label": device.localizedName,
Expand Down

0 comments on commit 3ea1487

Please sign in to comment.