Skip to content

Commit 91be03d

Browse files
Brazold3xvn
andauthored
feat(llc): added mirror parameter to CameraConstraints (#641)
* added mirror parameter to CameraConstraints * Update packages/stream_video/CHANGELOG.md Co-authored-by: Deven Joshi <[email protected]> * changed mirror to enum --------- Co-authored-by: Deven Joshi <[email protected]>
1 parent 5e3a4f3 commit 91be03d

File tree

6 files changed

+27
-3
lines changed

6 files changed

+27
-3
lines changed

packages/stream_video/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased
2+
✅ Added
3+
4+
* Added `mirror` parameter to `CameraConstraints`, which determines whether the camera for the given track should be mirrored or not. When set as null the default is true when `facingMode` is set to `user` and false when facingMode is set to `environment`.
5+
16
## 0.3.6
27
✅ Added
38

packages/stream_video/lib/src/webrtc/media/camera_constraints.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
import '../../platform_detector/platform_detector.dart';
22
import '../model/rtc_video_parameters.dart';
33
import 'constraints/facing_mode.dart';
4+
import 'constraints/mirror_mode.dart';
45
import 'video_constraints.dart';
56

67
/// Options used when creating a video track that captures the camera.
8+
/// [mirror]: Whether the video should be mirrored. If set to null, the default is true when facingMode is user and false when facingMode is environment.
79
class CameraConstraints extends VideoConstraints {
810
const CameraConstraints({
9-
super.deviceId,
1011
this.facingMode = FacingMode.user,
12+
this.mirrorMode = MirrorMode.defaultMode,
13+
super.deviceId,
1114
super.maxFrameRate,
1215
super.params = RtcVideoParametersPresets.h720_16x9,
1316
});
1417

1518
CameraConstraints.from({required VideoConstraints constraints})
1619
: facingMode = FacingMode.user,
20+
mirrorMode = MirrorMode.defaultMode,
1721
super(
1822
deviceId: constraints.deviceId,
1923
maxFrameRate: constraints.maxFrameRate,
2024
params: constraints.params,
2125
);
2226

2327
final FacingMode facingMode;
28+
final MirrorMode mirrorMode;
2429

2530
@override
2631
Map<String, dynamic> toMap() {
2732
final constraints = <String, dynamic>{
2833
...super.toMap(),
2934
'facingMode': facingMode.alias,
35+
'mirror': mirrorMode.name,
3036
};
3137
if (deviceId != null) {
3238
if (CurrentPlatform.isWeb) {
@@ -52,11 +58,13 @@ class CameraConstraints extends VideoConstraints {
5258
FacingMode? facingMode,
5359
String? deviceId,
5460
double? maxFrameRate,
61+
MirrorMode? mirrorMode,
5562
}) =>
5663
CameraConstraints(
5764
params: params ?? this.params,
5865
facingMode: facingMode ?? this.facingMode,
5966
deviceId: deviceId ?? this.deviceId,
6067
maxFrameRate: maxFrameRate ?? this.maxFrameRate,
68+
mirrorMode: mirrorMode ?? this.mirrorMode,
6169
);
6270
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum MirrorMode {
2+
on,
3+
off,
4+
defaultMode,
5+
}

packages/stream_video/lib/src/webrtc/media/media_constraints.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export 'audio_constraints.dart';
88
export 'camera_constraints.dart';
99
export 'constraints/camera_position.dart';
1010
export 'constraints/facing_mode.dart';
11+
export 'constraints/mirror_mode.dart';
1112
export 'screen_share_constraints.dart';
1213
export 'video_constraints.dart';
1314

packages/stream_video_flutter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Here are some of the features we support:
6060
| Push notification providers support ||| |
6161
| Call recording ||| |
6262
| Broadcasting to HLS ||| |
63-
| Picture in picture support || | In the Roadmap, part of the next major release |
63+
| Picture in picture support || | In the Roadmap, part of the next major release |
6464

6565

6666
### Known Issues

packages/stream_video_flutter/lib/src/renderer/video_renderer.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ class StreamVideoRenderer extends StatelessWidget {
8787
} else if (videoTrack is RtcLocalTrack<CameraConstraints>) {
8888
final isBackCamera =
8989
videoTrack.mediaConstraints.facingMode == FacingMode.environment;
90-
mirror = !isBackCamera;
90+
91+
mirror = switch (videoTrack.mediaConstraints.mirrorMode) {
92+
MirrorMode.defaultMode => mirror && !isBackCamera,
93+
MirrorMode.on => true,
94+
MirrorMode.off => false
95+
};
9196
}
9297

9398
return VideoTrackRenderer(

0 commit comments

Comments
 (0)