1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Can toggle local streams

This commit is contained in:
Pierre HUBERT 2020-04-21 13:46:26 +02:00
parent 2858c50449
commit 2927f72674

View File

@ -47,9 +47,18 @@ class _CallScreenState extends SafeState<CallScreen> {
final _renderers = Map<int, RTCVideoRenderer>(); final _renderers = Map<int, RTCVideoRenderer>();
MediaStream _localStream; MediaStream _localStream;
bool get isStreamingAudio =>
_localStream != null && _localStream.getAudioTracks().length > 0;
bool get isStreamingVideo => bool get isStreamingVideo =>
_localStream != null && _localStream.getVideoTracks().length > 0; _localStream != null && _localStream.getVideoTracks().length > 0;
bool get isAudioMuted =>
isStreamingAudio && !_localStream.getAudioTracks()[0].enabled;
bool get isVideoMuted =>
isStreamingVideo && !_localStream.getVideoTracks()[0].enabled;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -67,7 +76,8 @@ class _CallScreenState extends SafeState<CallScreen> {
setState(() => _error = false); setState(() => _error = false);
// First, load information about the conversation // First, load information about the conversation
_conversation = await ConversationsHelper().getSingleOrThrow(convID); _conversation =
await ConversationsHelper().getSingleOrThrow(convID, force: true);
_convName = _convName =
await ConversationsHelper.getConversationNameAsync(_conversation); await ConversationsHelper.getConversationNameAsync(_conversation);
assert(_convName != null); assert(_convName != null);
@ -205,6 +215,31 @@ class _CallScreenState extends SafeState<CallScreen> {
} }
} }
/// Toggle local video streaming
Future<void> _toggleStreaming(bool isVideo) async {
if (isVideo && _conversation.callCapabilities != CallCapabilities.VIDEO) {
print("Attempting to switch video call on a non-capable video stream!");
return;
}
// Start streaming if required
if (!isStreamingAudio || (!isStreamingVideo && isVideo)) {
await _startStreaming(isVideo);
}
// Toggle appropriate mute
else {
if (!isVideo)
_localStream.getAudioTracks()[0].enabled =
!_localStream.getAudioTracks()[0].enabled;
else
_localStream.getVideoTracks()[0].enabled =
!_localStream.getVideoTracks()[0].enabled;
}
setState(() {});
}
/// Call this when a user started to stream media /// Call this when a user started to stream media
Future<void> _memberReady(int memberID) async { Future<void> _memberReady(int memberID) async {
try { try {
@ -400,8 +435,10 @@ class _CallScreenState extends SafeState<CallScreen> {
// Toggle audio button // Toggle audio button
Expanded( Expanded(
child: IconButton( child: IconButton(
icon: Icon(Icons.mic_off), icon: Icon(isStreamingAudio && !isAudioMuted
onPressed: () => _startStreaming(false), ? Icons.mic
: Icons.mic_off),
onPressed: () => _toggleStreaming(false),
), ),
), ),
@ -416,8 +453,10 @@ class _CallScreenState extends SafeState<CallScreen> {
// Toggle video button // Toggle video button
Expanded( Expanded(
child: IconButton( child: IconButton(
icon: Icon(Icons.videocam_off), icon: Icon(isStreamingVideo && !isVideoMuted
onPressed: () => _startStreaming(true), ? Icons.videocam
: Icons.videocam_off),
onPressed: () => _toggleStreaming(true),
), ),
), ),
], ],