fix: voice call, select audio input device (#7922)

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-05-07 16:18:48 +08:00
committed by GitHub
parent f08933f93c
commit 2c1595d0d5
50 changed files with 305 additions and 79 deletions

View File

@@ -4,6 +4,7 @@ import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/widgets/audio_input.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
import 'package:flutter_hbb/models/chat_model.dart';
@@ -701,17 +702,86 @@ class _CmControlPanel extends StatelessWidget {
children: [
Offstage(
offstage: !client.inVoiceCall,
child: buildButton(
context,
color: Colors.red,
onClick: () => closeVoiceCall(),
icon: Icon(
Icons.call_end_rounded,
color: Colors.white,
size: 14,
),
text: "Stop voice call",
textColor: Colors.white,
child: Row(
children: [
Expanded(
child: buildButton(context,
color: MyTheme.accent,
onClick: null, onTapDown: (details) async {
final devicesInfo = await AudioInput.getDevicesInfo();
List<String> devices = devicesInfo['devices'] as List<String>;
if (devices.isEmpty) {
msgBox(
gFFI.sessionId,
'custom-nocancel-info',
'Prompt',
'no_audio_input_device_tip',
'',
gFFI.dialogManager,
);
return;
}
String currentDevice = devicesInfo['current'] as String;
final x = details.globalPosition.dx;
final y = details.globalPosition.dy;
final position = RelativeRect.fromLTRB(x, y, x, y);
showMenu(
context: context,
position: position,
items: devices
.map((d) => PopupMenuItem<String>(
value: d,
height: 18,
padding: EdgeInsets.zero,
onTap: () => AudioInput.setDevice(d),
child: IgnorePointer(
child: RadioMenuButton(
value: d,
groupValue: currentDevice,
onChanged: (v) {
if (v != null) AudioInput.setDevice(v);
},
child: Container(
child: Text(
d,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
constraints: BoxConstraints(
maxWidth:
kConnectionManagerWindowSizeClosedChat
.width -
80),
),
)),
))
.toList(),
);
},
icon: Icon(
Icons.call_rounded,
color: Colors.white,
size: 14,
),
text: "Audio input",
textColor: Colors.white),
),
Expanded(
child: buildButton(
context,
color: Colors.red,
onClick: () => closeVoiceCall(),
icon: Icon(
Icons.call_end_rounded,
color: Colors.white,
size: 14,
),
text: "Stop voice call",
textColor: Colors.white,
),
)
],
),
),
Offstage(
@@ -872,12 +942,14 @@ class _CmControlPanel extends StatelessWidget {
Widget buildButton(BuildContext context,
{required Color? color,
required Function() onClick,
Icon? icon,
GestureTapCallback? onClick,
Widget? icon,
BoxBorder? border,
required String text,
required Color? textColor,
String? tooltip}) {
String? tooltip,
GestureTapDownCallback? onTapDown}) {
assert(!(onClick == null && onTapDown == null));
Widget textWidget;
if (icon != null) {
textWidget = Text(
@@ -901,7 +973,16 @@ class _CmControlPanel extends StatelessWidget {
color: color, borderRadius: borderRadius, border: border),
child: InkWell(
borderRadius: borderRadius,
onTap: () => checkClickTime(client.id, onClick),
onTap: () {
if (onClick == null) return;
checkClickTime(client.id, onClick);
},
onTapDown: (details) {
if (onTapDown == null) return;
checkClickTime(client.id, () {
onTapDown.call(details);
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [