wip: implement flutter ui

This commit is contained in:
Kingtous
2023-02-06 20:10:39 +08:00
parent ea391542fc
commit 5e21a81a5c
7 changed files with 84 additions and 4 deletions

View File

@@ -426,6 +426,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
menubarItems.add(_buildKeyboard(context));
if (!isWeb) {
menubarItems.add(_buildChat(context));
menubarItems.add(_buildVoiceCall(context));
}
menubarItems.add(_buildRecording(context));
menubarItems.add(_buildClose(context));
@@ -707,6 +708,32 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
);
}
Widget _buildVoiceCall(BuildContext context) {
return Obx(
() {
switch (widget.ffi.chatModel.voiceCallStatus.value) {
case VoiceCallStatus.waitingForResponse:
return SvgPicture.asset(
"assets/voice_call_waiting.svg",
color: _MenubarTheme.commonColor,
width: Theme.of(context).iconTheme.size ?? 24.0,
height: Theme.of(context).iconTheme.size ?? 24.0,
);
break;
case VoiceCallStatus.connected:
return SvgPicture.asset(
"assets/voice_call.svg",
color: Colors.red,
width: Theme.of(context).iconTheme.size ?? 24.0,
height: Theme.of(context).iconTheme.size ?? 24.0,
);
default:
return const Offstage();
}
},
);
}
List<MenuEntryBase<String>> _getChatMenu(BuildContext context) {
final List<MenuEntryBase<String>> chatMenu = [];
const EdgeInsets padding = EdgeInsets.only(left: 14.0, right: 5.0);
@@ -728,7 +755,10 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
translate('Voice call'),
style: style,
),
proc: () {},
proc: () {
// Request a voice call.
bind.sessionRequestVoiceCall(id: widget.id);
},
padding: padding,
dismissOnClicked: true,
),

View File

@@ -2,6 +2,7 @@ import 'package:dash_chat_2/dash_chat_2.dart';
import 'package:draggable_float_widget/draggable_float_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/models/platform_model.dart';
import 'package:get/get.dart';
import 'package:window_manager/window_manager.dart';
import '../consts.dart';
@@ -33,8 +34,13 @@ class ChatModel with ChangeNotifier {
OverlayState? _overlayState;
OverlayEntry? chatIconOverlayEntry;
OverlayEntry? chatWindowOverlayEntry;
bool isConnManager = false;
final Rx<VoiceCallStatus> _voiceCallStatus = Rx(VoiceCallStatus.notStarted);
Rx<VoiceCallStatus> get voiceCallStatus => _voiceCallStatus;
final ChatUser me = ChatUser(
id: "",
firstName: "Me",
@@ -292,4 +298,30 @@ class ChatModel with ChangeNotifier {
resetClientMode() {
_messages[clientModeID]?.clear();
}
void onVoiceCallWaiting() {
_voiceCallStatus.value = VoiceCallStatus.waitingForResponse;
}
void onVoiceCallStarted() {
_voiceCallStatus.value = VoiceCallStatus.connected;
}
void onVoiceCallClosed(String reason) {
_voiceCallStatus.value = VoiceCallStatus.notStarted;
}
void onVoiceCallIncoming() {
if (isConnManager) {
_voiceCallStatus.value = VoiceCallStatus.incoming;
}
}
}
enum VoiceCallStatus {
notStarted,
waitingForResponse,
connected,
// Connection manager only.
incoming
}

View File

@@ -203,6 +203,21 @@ class FfiModel with ChangeNotifier {
} else if (name == "on_url_scheme_received") {
final url = evt['url'].toString();
parseRustdeskUri(url);
} else if (name == "on_voice_call_waiting") {
// Waiting for the response from the peer.
parent.target?.chatModel.onVoiceCallWaiting();
} else if (name == "on_voice_call_started") {
// Voice call is connected.
parent.target?.chatModel.onVoiceCallStarted();
} else if (name == "on_voice_call_closed") {
// Voice call is closed with reason.
final reason = evt['reason'].toString();
parent.target?.chatModel.onVoiceCallClosed(reason);
} else if (name == "on_voice_call_incoming") {
// Voice call is requested by the peer.
parent.target?.chatModel.onVoiceCallIncoming();
} else {
debugPrint("Unknown event name: $name");
}
};
}