FPWCSApi2Stream check if front or back camera is used (iOS)

andrew.n

Member
Before starting the stream, the user has the option to switch from front camera to back camera.

The problem is that right now when we start the streaming if the preview (made custom by us) is for the back camera, the streaming will start by using the front camera.

Right now, I didn't find a way to set which camera to use when I create the FPWCSApi2Stream object (front/back), more than that when the streaming starts, I have just the option to switch camera but it will be useful if I can check if the streaming uses the front camera and the user selects the back camera, to switch just in that case.

Any advice on this @Max ?
 

Max

Administrator
Staff member
Good day.
Please see the Media Devices example source code. It shows how to choose camera before publishing:
Code:
- (FPWCSApi2MediaConstraints *)toMediaConstraints {
    FPWCSApi2MediaConstraints *ret = [[FPWCSApi2MediaConstraints alloc] init];
    if ([_sendAudio.control isOn])  {
        ...
    }
    if ([_sendVideo.control isOn]) {
        FPWCSApi2VideoConstraints *video = [[FPWCSApi2VideoConstraints alloc] init];
        for (FPWCSApi2MediaDevice *device in localDevices.video) {
            if ([device.label isEqualToString:_camSelector.input.text]) {
                video.deviceID = device.deviceID;
            }
        }
        ...
        ret.video = video;
    }
    return ret;
}
Note that you should set deviceId to video constraints. Then, you just pass the constraints to createStream function:
Code:
- (void)startStreaming {
    FPWCSApi2StreamOptions *options = [[FPWCSApi2StreamOptions alloc] init];
    options.name = [self getStreamName];
    options.display = _videoView.local;
    options.constraints = [_localControl toMediaConstraints];
    options.transport = _useTCPTransport.control.on ? kFPWCSTransportTCP : kFPWCSTransportUDP;
    NSError *error;
    _localStream = [_session createStream:options error:&error];
    ...
}
 

andrew.n

Member
Nice, also when we call switchCamera for on FPWCSApi2Stream, it's not switching the first time. It will be really nice if we can have like a confirmation on FPWCSApi2Stream delegate/completion block when the camera switched front/back
 
Top