🐛 Dispose current call when hang up

This commit is contained in:
LittleSheep 2024-05-02 21:35:33 +08:00
parent 1a5faabf86
commit 9f6942a8cb

View File

@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import 'package:solian/models/call.dart'; import 'package:solian/models/call.dart';
import 'package:solian/models/channel.dart'; import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/providers/chat.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/utils/service_url.dart'; import 'package:solian/utils/service_url.dart';
import 'package:solian/widgets/exts.dart'; import 'package:solian/widgets/exts.dart';
@ -14,8 +15,7 @@ class ChannelCallAction extends StatefulWidget {
final Channel channel; final Channel channel;
final Function onUpdate; final Function onUpdate;
const ChannelCallAction( const ChannelCallAction({super.key, this.call, required this.channel, required this.onUpdate});
{super.key, this.call, required this.channel, required this.onUpdate});
@override @override
State<ChannelCallAction> createState() => _ChannelCallActionState(); State<ChannelCallAction> createState() => _ChannelCallActionState();
@ -33,8 +33,7 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
return; return;
} }
var uri = getRequestUri( var uri = getRequestUri('messaging', '/api/channels/${widget.channel.alias}/calls');
'messaging', '/api/channels/${widget.channel.alias}/calls');
var res = await auth.client!.post(uri); var res = await auth.client!.post(uri);
if (res.statusCode != 200) { if (res.statusCode != 200) {
@ -48,19 +47,24 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
Future<void> endsCall() async { Future<void> endsCall() async {
setState(() => _isSubmitting = true); setState(() => _isSubmitting = true);
final chat = context.read<ChatProvider>();
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
if (!await auth.isAuthorized()) { if (!await auth.isAuthorized()) {
setState(() => _isSubmitting = false); setState(() => _isSubmitting = false);
return; return;
} }
var uri = getRequestUri( var uri = getRequestUri('messaging', '/api/channels/${widget.channel.alias}/calls/ongoing');
'messaging', '/api/channels/${widget.channel.alias}/calls/ongoing');
var res = await auth.client!.delete(uri); var res = await auth.client!.delete(uri);
if (res.statusCode != 200) { if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes); var message = utf8.decode(res.bodyBytes);
context.showErrorDialog(message); context.showErrorDialog(message);
} else {
if (chat.currentCall != null && chat.currentCall?.info.channelId == widget.channel.id) {
chat.currentCall!.deactivate();
chat.currentCall!.dispose();
}
} }
setState(() => _isSubmitting = false); setState(() => _isSubmitting = false);
@ -78,9 +82,7 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
endsCall(); endsCall();
} }
}, },
icon: widget.call == null icon: widget.call == null ? const Icon(Icons.call) : const Icon(Icons.call_end),
? const Icon(Icons.call)
: const Icon(Icons.call_end),
); );
} }
} }
@ -89,8 +91,7 @@ class ChannelManageAction extends StatelessWidget {
final Channel channel; final Channel channel;
final Function onUpdate; final Function onUpdate;
const ChannelManageAction( const ChannelManageAction({super.key, required this.channel, required this.onUpdate});
{super.key, required this.channel, required this.onUpdate});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {