mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Can toggle local streams
This commit is contained in:
parent
2858c50449
commit
2927f72674
@ -47,9 +47,18 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
final _renderers = Map<int, RTCVideoRenderer>();
|
||||
MediaStream _localStream;
|
||||
|
||||
bool get isStreamingAudio =>
|
||||
_localStream != null && _localStream.getAudioTracks().length > 0;
|
||||
|
||||
bool get isStreamingVideo =>
|
||||
_localStream != null && _localStream.getVideoTracks().length > 0;
|
||||
|
||||
bool get isAudioMuted =>
|
||||
isStreamingAudio && !_localStream.getAudioTracks()[0].enabled;
|
||||
|
||||
bool get isVideoMuted =>
|
||||
isStreamingVideo && !_localStream.getVideoTracks()[0].enabled;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -67,7 +76,8 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
setState(() => _error = false);
|
||||
|
||||
// First, load information about the conversation
|
||||
_conversation = await ConversationsHelper().getSingleOrThrow(convID);
|
||||
_conversation =
|
||||
await ConversationsHelper().getSingleOrThrow(convID, force: true);
|
||||
_convName =
|
||||
await ConversationsHelper.getConversationNameAsync(_conversation);
|
||||
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
|
||||
Future<void> _memberReady(int memberID) async {
|
||||
try {
|
||||
@ -400,8 +435,10 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
// Toggle audio button
|
||||
Expanded(
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.mic_off),
|
||||
onPressed: () => _startStreaming(false),
|
||||
icon: Icon(isStreamingAudio && !isAudioMuted
|
||||
? Icons.mic
|
||||
: Icons.mic_off),
|
||||
onPressed: () => _toggleStreaming(false),
|
||||
),
|
||||
),
|
||||
|
||||
@ -416,8 +453,10 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
// Toggle video button
|
||||
Expanded(
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.videocam_off),
|
||||
onPressed: () => _startStreaming(true),
|
||||
icon: Icon(isStreamingVideo && !isVideoMuted
|
||||
? Icons.videocam
|
||||
: Icons.videocam_off),
|
||||
onPressed: () => _toggleStreaming(true),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user