fix: userMediaConstraints
This commit is contained in:
parent
29d982b2de
commit
f7a4518c5f
|
|
@ -25,6 +25,7 @@ import 'package:webrtc_interface/webrtc_interface.dart';
|
||||||
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:matrix/src/utils/cached_stream_controller.dart';
|
import 'package:matrix/src/utils/cached_stream_controller.dart';
|
||||||
|
import 'package:matrix/src/voip/utils/user_media_constraints.dart';
|
||||||
|
|
||||||
/// https://github.com/matrix-org/matrix-doc/pull/2746
|
/// https://github.com/matrix-org/matrix-doc/pull/2746
|
||||||
/// version 1
|
/// version 1
|
||||||
|
|
@ -44,21 +45,6 @@ class CallTimeouts {
|
||||||
static const delayBeforeOffer = Duration(milliseconds: 100);
|
static const delayBeforeOffer = Duration(milliseconds: 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserMediaOptions {
|
|
||||||
static const optionalAudioConfig = {
|
|
||||||
'echoCancellation': true,
|
|
||||||
'googDAEchoCancellation': true,
|
|
||||||
'googEchoCancellation': true,
|
|
||||||
'googEchoCancellation2': true,
|
|
||||||
'noiseSuppression': true,
|
|
||||||
'googNoiseSuppression': true,
|
|
||||||
'googNoiseSuppression2': true,
|
|
||||||
'googAutoGainControl': true,
|
|
||||||
'googHighpassFilter': true,
|
|
||||||
'googTypingNoiseDetection': true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
extension RTCIceCandidateExt on RTCIceCandidate {
|
extension RTCIceCandidateExt on RTCIceCandidate {
|
||||||
bool get isValid =>
|
bool get isValid =>
|
||||||
sdpMLineIndex != null &&
|
sdpMLineIndex != null &&
|
||||||
|
|
@ -773,8 +759,10 @@ class CallSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pc != null &&
|
if (pc != null &&
|
||||||
pc!.iceConnectionState ==
|
{
|
||||||
RTCIceConnectionState.RTCIceConnectionStateDisconnected) {
|
RTCIceConnectionState.RTCIceConnectionStateDisconnected,
|
||||||
|
RTCIceConnectionState.RTCIceConnectionStateFailed
|
||||||
|
}.contains(pc!.iceConnectionState)) {
|
||||||
await restartIce();
|
await restartIce();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1488,17 +1476,9 @@ class CallSession {
|
||||||
|
|
||||||
Future<MediaStream?> _getUserMedia(CallType type) async {
|
Future<MediaStream?> _getUserMedia(CallType type) async {
|
||||||
final mediaConstraints = {
|
final mediaConstraints = {
|
||||||
'audio': true,
|
'audio': UserMediaConstraints.micMediaConstraints,
|
||||||
'video': type == CallType.kVideo
|
'video': type == CallType.kVideo
|
||||||
? {
|
? UserMediaConstraints.camMediaConstraints
|
||||||
'mandatory': {
|
|
||||||
'minWidth': '640',
|
|
||||||
'minHeight': '480',
|
|
||||||
'minFrameRate': '30',
|
|
||||||
},
|
|
||||||
'facingMode': 'user',
|
|
||||||
'optional': [UserMediaOptions.optionalAudioConfig],
|
|
||||||
}
|
|
||||||
: false,
|
: false,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
|
@ -1510,12 +1490,9 @@ class CallSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<MediaStream?> _getDisplayMedia() async {
|
Future<MediaStream?> _getDisplayMedia() async {
|
||||||
final mediaConstraints = {
|
|
||||||
'audio': false,
|
|
||||||
'video': true,
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
return await voip.delegate.mediaDevices.getDisplayMedia(mediaConstraints);
|
return await voip.delegate.mediaDevices
|
||||||
|
.getDisplayMedia(UserMediaConstraints.screenMediaConstraints);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await _getUserMediaFailed(e);
|
await _getUserMediaFailed(e);
|
||||||
}
|
}
|
||||||
|
|
@ -1582,7 +1559,7 @@ class CallSession {
|
||||||
Map<String, dynamic> _getOfferAnswerConstraints({bool iceRestart = false}) {
|
Map<String, dynamic> _getOfferAnswerConstraints({bool iceRestart = false}) {
|
||||||
return {
|
return {
|
||||||
'mandatory': {if (iceRestart) 'IceRestart': true},
|
'mandatory': {if (iceRestart) 'IceRestart': true},
|
||||||
'optional': [UserMediaOptions.optionalAudioConfig],
|
'optional': [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import 'package:webrtc_interface/webrtc_interface.dart';
|
||||||
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:matrix/src/utils/cached_stream_controller.dart';
|
import 'package:matrix/src/utils/cached_stream_controller.dart';
|
||||||
|
import 'package:matrix/src/voip/utils/user_media_constraints.dart';
|
||||||
|
|
||||||
/// TODO(@duan): Need to add voice activity detection mechanism
|
/// TODO(@duan): Need to add voice activity detection mechanism
|
||||||
/// const int SPEAKING_THRESHOLD = -60; // dB
|
/// const int SPEAKING_THRESHOLD = -60; // dB
|
||||||
|
|
@ -315,17 +316,9 @@ class GroupCall {
|
||||||
|
|
||||||
Future<MediaStream> _getUserMedia(CallType type) async {
|
Future<MediaStream> _getUserMedia(CallType type) async {
|
||||||
final mediaConstraints = {
|
final mediaConstraints = {
|
||||||
'audio': true,
|
'audio': UserMediaConstraints.micMediaConstraints,
|
||||||
'video': type == CallType.kVideo
|
'video': type == CallType.kVideo
|
||||||
? {
|
? UserMediaConstraints.camMediaConstraints
|
||||||
'mandatory': {
|
|
||||||
'minWidth': '640',
|
|
||||||
'minHeight': '480',
|
|
||||||
'minFrameRate': '30',
|
|
||||||
},
|
|
||||||
'facingMode': 'user',
|
|
||||||
'optional': [UserMediaOptions.optionalAudioConfig],
|
|
||||||
}
|
|
||||||
: false,
|
: false,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
|
@ -337,12 +330,9 @@ class GroupCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<MediaStream> _getDisplayMedia() async {
|
Future<MediaStream> _getDisplayMedia() async {
|
||||||
final mediaConstraints = {
|
|
||||||
'audio': false,
|
|
||||||
'video': true,
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
return await voip.delegate.mediaDevices.getDisplayMedia(mediaConstraints);
|
return await voip.delegate.mediaDevices
|
||||||
|
.getDisplayMedia(UserMediaConstraints.screenMediaConstraints);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('[VOIP] _getDisplayMedia failed because,', e, s);
|
Logs().e('[VOIP] _getDisplayMedia failed because,', e, s);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
class UserMediaConstraints {
|
||||||
|
static const Map<String, Object> micMediaConstraints = {
|
||||||
|
'echoCancellation': true,
|
||||||
|
'noiseSuppression': true,
|
||||||
|
'autoGainControl': false
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Map<String, Object> camMediaConstraints = {
|
||||||
|
'width': 1280,
|
||||||
|
'height': 720,
|
||||||
|
'facingMode': 'user',
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Map<String, Object> screenMediaConstraints = {
|
||||||
|
'audio': true,
|
||||||
|
'video': true,
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue