mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-12 04:51:28 +03:00
refact: android audio input, voice call (#8037)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/mobile/widgets/gesture_help.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
@@ -79,7 +80,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
initSharedStates(widget.id);
|
||||
gFFI.chatModel
|
||||
.changeCurrentKey(MessageKey(widget.id, ChatModel.clientModeID));
|
||||
|
||||
gFFI.chatModel.voiceCallStatus.value = VoiceCallStatus.notStarted;
|
||||
_blockableOverlayState.applyFfi(gFFI);
|
||||
}
|
||||
|
||||
@@ -102,6 +103,11 @@ class _RemotePageState extends State<RemotePage> {
|
||||
}
|
||||
await keyboardSubscription.cancel();
|
||||
removeSharedStates(widget.id);
|
||||
if (isAndroid) {
|
||||
// Only one client is considered here for now.
|
||||
// TODO: take into account the case where there are multiple clients
|
||||
gFFI.invokeMethod("on_voice_call_closed");
|
||||
}
|
||||
}
|
||||
|
||||
// to-do: It should be better to use transparent color instead of the bgColor.
|
||||
@@ -369,9 +375,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
onPressed: () {
|
||||
clientClose(sessionId, gFFI.dialogManager);
|
||||
},
|
||||
)
|
||||
] +
|
||||
<Widget>[
|
||||
),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.tv),
|
||||
@@ -416,11 +420,9 @@ class _RemotePageState extends State<RemotePage> {
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.message),
|
||||
onPressed: () {
|
||||
gFFI.chatModel.changeCurrentKey(MessageKey(
|
||||
widget.id, ChatModel.clientModeID));
|
||||
gFFI.chatModel.toggleChatOverlay();
|
||||
},
|
||||
onPressed: () => isAndroid
|
||||
? showChatOptions(widget.id)
|
||||
: onPressedTextChat(widget.id),
|
||||
)
|
||||
]) +
|
||||
[
|
||||
@@ -538,6 +540,82 @@ class _RemotePageState extends State<RemotePage> {
|
||||
}();
|
||||
}
|
||||
|
||||
onPressedTextChat(String id) {
|
||||
gFFI.chatModel.changeCurrentKey(MessageKey(id, ChatModel.clientModeID));
|
||||
gFFI.chatModel.toggleChatOverlay();
|
||||
}
|
||||
|
||||
showChatOptions(String id) async {
|
||||
onPressVoiceCall() => bind.sessionRequestVoiceCall(sessionId: sessionId);
|
||||
onPressEndVoiceCall() => bind.sessionCloseVoiceCall(sessionId: sessionId);
|
||||
|
||||
makeTextMenu(String label, String svg, VoidCallback onPressed,
|
||||
{ColorFilter? colorFilter, TextStyle? labelStyle}) =>
|
||||
TTextMenu(
|
||||
child: Text(translate(label), style: labelStyle),
|
||||
trailingIcon: Transform.scale(
|
||||
scale: (isDesktop || isWebDesktop) ? 0.8 : 1,
|
||||
child: IconButton(
|
||||
onPressed: onPressed,
|
||||
icon: SvgPicture.asset(
|
||||
svg,
|
||||
colorFilter: colorFilter ??
|
||||
ColorFilter.mode(MyTheme.accent, BlendMode.srcIn),
|
||||
),
|
||||
),
|
||||
),
|
||||
onPressed: onPressed,
|
||||
);
|
||||
|
||||
final isInVoice = [
|
||||
VoiceCallStatus.waitingForResponse,
|
||||
VoiceCallStatus.connected
|
||||
].contains(gFFI.chatModel.voiceCallStatus.value);
|
||||
final menus = [
|
||||
makeTextMenu(
|
||||
'Text chat', 'assets/chat.svg', () => onPressedTextChat(widget.id)),
|
||||
isInVoice
|
||||
? makeTextMenu(
|
||||
'End voice call', 'assets/call_wait.svg', onPressEndVoiceCall,
|
||||
colorFilter: ColorFilter.mode(Colors.redAccent, BlendMode.srcIn),
|
||||
labelStyle: TextStyle(color: Colors.redAccent))
|
||||
: makeTextMenu(
|
||||
'Voice call', 'assets/call_wait.svg', onPressVoiceCall),
|
||||
];
|
||||
getChild(TTextMenu menu) {
|
||||
if (menu.trailingIcon != null) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
menu.child,
|
||||
menu.trailingIcon!,
|
||||
]);
|
||||
} else {
|
||||
return menu.child;
|
||||
}
|
||||
}
|
||||
|
||||
final menuItems = menus
|
||||
.asMap()
|
||||
.entries
|
||||
.map((e) => PopupMenuItem<int>(child: getChild(e.value), value: e.key))
|
||||
.toList();
|
||||
Future.delayed(Duration.zero, () async {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final x = 120.0;
|
||||
final y = size.height;
|
||||
var index = await showMenu(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(x, y, x, y),
|
||||
items: menuItems,
|
||||
elevation: 8,
|
||||
);
|
||||
if (index != null && index < menus.length) {
|
||||
menus[index].onPressed.call();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// aka changeTouchMode
|
||||
BottomAppBar getGestureHelp() {
|
||||
return BottomAppBar(
|
||||
|
||||
@@ -637,40 +637,94 @@ class ConnectionManager extends StatelessWidget {
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
).marginOnly(bottom: 5),
|
||||
client.authorized
|
||||
? Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ElevatedButton.icon(
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStatePropertyAll(Colors.red)),
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
bind.cmCloseConnection(connId: client.id);
|
||||
gFFI.invokeMethod(
|
||||
"cancel_notification", client.id);
|
||||
},
|
||||
label: Text(translate("Disconnect"))))
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
child: Text(translate("Dismiss")),
|
||||
onPressed: () {
|
||||
serverModel.sendLoginResponse(
|
||||
client, false);
|
||||
}).marginOnly(right: 15),
|
||||
if (serverModel.approveMode != 'password')
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.check),
|
||||
label: Text(translate("Accept")),
|
||||
onPressed: () {
|
||||
serverModel.sendLoginResponse(
|
||||
client, true);
|
||||
}),
|
||||
]),
|
||||
? _buildDisconnectButton(client)
|
||||
: _buildNewConnectionHint(serverModel, client),
|
||||
if (client.incomingVoiceCall && !client.inVoiceCall)
|
||||
..._buildNewVoiceCallHint(context, serverModel, client),
|
||||
])))
|
||||
.toList());
|
||||
}
|
||||
|
||||
Widget _buildDisconnectButton(Client client) {
|
||||
final disconnectButton = ElevatedButton.icon(
|
||||
style: ButtonStyle(backgroundColor: MaterialStatePropertyAll(Colors.red)),
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
bind.cmCloseConnection(connId: client.id);
|
||||
gFFI.invokeMethod("cancel_notification", client.id);
|
||||
},
|
||||
label: Text(translate("Disconnect")),
|
||||
);
|
||||
final buttons = [disconnectButton];
|
||||
if (client.inVoiceCall) {
|
||||
buttons.insert(
|
||||
0,
|
||||
ElevatedButton.icon(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStatePropertyAll(Colors.red)),
|
||||
icon: const Icon(Icons.phone),
|
||||
label: Text(translate("Stop")),
|
||||
onPressed: () {
|
||||
bind.cmCloseVoiceCall(id: client.id);
|
||||
gFFI.invokeMethod("cancel_notification", client.id);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (buttons.length == 1) {
|
||||
return Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: disconnectButton,
|
||||
);
|
||||
} else {
|
||||
return Row(
|
||||
children: buttons,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildNewConnectionHint(ServerModel serverModel, Client client) {
|
||||
return Row(mainAxisAlignment: MainAxisAlignment.end, children: [
|
||||
TextButton(
|
||||
child: Text(translate("Dismiss")),
|
||||
onPressed: () {
|
||||
serverModel.sendLoginResponse(client, false);
|
||||
}).marginOnly(right: 15),
|
||||
if (serverModel.approveMode != 'password')
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.check),
|
||||
label: Text(translate("Accept")),
|
||||
onPressed: () {
|
||||
serverModel.sendLoginResponse(client, true);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
List<Widget> _buildNewVoiceCallHint(
|
||||
BuildContext context, ServerModel serverModel, Client client) {
|
||||
return [
|
||||
Text(
|
||||
translate("android_new_voice_call_tip"),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
).marginOnly(bottom: 5),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
|
||||
TextButton(
|
||||
child: Text(translate("Dismiss")),
|
||||
onPressed: () {
|
||||
serverModel.handleVoiceCall(client, false);
|
||||
}).marginOnly(right: 15),
|
||||
if (serverModel.approveMode != 'password')
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.check),
|
||||
label: Text(translate("Accept")),
|
||||
onPressed: () {
|
||||
serverModel.handleVoiceCall(client, true);
|
||||
}),
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class PaddingCard extends StatelessWidget {
|
||||
@@ -787,6 +841,15 @@ void androidChannelInit() {
|
||||
gFFI.serverModel.stopService();
|
||||
break;
|
||||
}
|
||||
case "msgbox":
|
||||
{
|
||||
var type = arguments["type"] as String;
|
||||
var title = arguments["title"] as String;
|
||||
var text = arguments["text"] as String;
|
||||
var link = (arguments["link"] ?? '') as String;
|
||||
msgBox(gFFI.sessionId, type, title, text, link, gFFI.dialogManager);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrintStack(label: "MethodCallHandler err:$e");
|
||||
|
||||
Reference in New Issue
Block a user