Skip to content

Commit

Permalink
Merge pull request #175 from voximplant/android_orientation_listener
Browse files Browse the repository at this point in the history
Add API to use Android orientation listener
  • Loading branch information
YuliaGrigorieva authored Jan 24, 2023
2 parents 60410ac + 2ba1c33 commit af164b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void addListener(String eventName) {
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}

@Override
public String getName() {
return "RNVICameraModule";
Expand All @@ -60,22 +60,27 @@ public void switchCamera(String cameraType) {
mCameraIndex = Utils.convertCameraTypeToCameraIndex(cameraType);
mCameraManager.setCamera(mCameraIndex, mCameraResolutionWidth, mCameraResolutionHeight);
}

@ReactMethod
public void setCameraResolution(int width, int height) {
mCameraResolutionWidth = width;
mCameraResolutionHeight = height;
mCameraManager.setCamera(mCameraIndex, mCameraResolutionWidth, mCameraResolutionHeight);
}

@ReactMethod
public void useOrientationEventListener(boolean use) {
mCameraManager.useOrientationEventListener(use);
}

@Override
public void onCameraDisconnected() {
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_NAME_CAMERA_DISCONNECTED);
sendEvent(EVENT_CAMERA_DISCONNECTED, params);
}

@Override
@Override
public void onCameraError(String errorDescription) {
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_NAME_CAMERA_ERROR);
Expand All @@ -91,7 +96,7 @@ public void onCameraSwitchDone(boolean isFrontCamera) {
sendEvent(EVENT_CAMERA_SWITCH_DONE, params);
}

@Override
@Override
public void onCameraSwitchError(String errorDescription) {
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_NAME_CAMERA_SWITCH_ERROR);
Expand All @@ -102,4 +107,4 @@ public void onCameraSwitchError(String errorDescription) {
private void sendEvent(String eventName, @Nullable WritableMap params) {
mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
}
}
}
25 changes: 23 additions & 2 deletions src/hardware/CameraManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class CameraManager {
EventEmitter.addListener('VICameraError', this._onCameraError);
EventEmitter.addListener('VICameraSwitchDone', this._onCameraSwitchDone);
EventEmitter.addListener('VICameraSwitchError', this._onCameraSwitchError);
}
}
}

/**
Expand All @@ -72,6 +72,27 @@ export default class CameraManager {
CameraModule.setCameraResolution(width, height);
}

/**
* ANDROID ONLY.
*
* Use OrientationEventListener to detect the device rotation and to rotate camera frames according to device orientation.
*
* By default, Display rotation is used to determine the device rotation.
*
* The way how the device orientation is detected, affects camera frames rotation on local and remote side if auto-rotate is disabled on a mobile phone:
*
* OrientationEventListener will detect landscape orientation
* Display rotation will always report portrait orientation
* The method should be called in idle camera state, i.e. video is currently not sending in a call.
* @param {boolean} use - True, if OrientationEventListener should be used to detect the device orientation, otherwise Display rotation is used.
* @memberOf Voximplant.Hardware.CameraManager
*/
useOrientationEventListener(use) {
if (Platform.OS === 'android') {
CameraModule.useOrientationEventListener(use);
}
}

/**
* Register a handler for the specified camera event.
* One event can have more than one handler.
Expand Down Expand Up @@ -156,4 +177,4 @@ export default class CameraManager {
this._emit(CameraEvents.CameraSwitchError, event);
};

}
}

0 comments on commit af164b6

Please sign in to comment.