🐛 Bug fixes

This commit is contained in:
LittleSheep 2024-05-02 01:38:45 +08:00
parent b39c8c770e
commit d968169e42
4 changed files with 111 additions and 108 deletions

View File

@ -35,9 +35,7 @@ class ChatProvider extends ChangeNotifier {
scheme: ori.scheme.replaceFirst('http', 'ws'), scheme: ori.scheme.replaceFirst('http', 'ws'),
host: ori.host, host: ori.host,
path: ori.path, path: ori.path,
queryParameters: { queryParameters: {'tk': Uri.encodeComponent(auth.client!.credentials.accessToken)},
'tk': Uri.encodeComponent(auth.client!.credentials.accessToken)
},
); );
final channel = WebSocketChannel.connect(uri); final channel = WebSocketChannel.connect(uri);
@ -80,8 +78,7 @@ class ChatProvider extends ChangeNotifier {
} }
} }
bool handleCallJoin(Call call, Channel channel, bool handleCallJoin(Call call, Channel channel, {Function? onUpdate, Function? onDispose}) {
{Function? onUpdate, Function? onDispose}) {
if (currentCall != null) return false; if (currentCall != null) return false;
currentCall = ChatCallInstance( currentCall = ChatCallInstance(
@ -151,8 +148,7 @@ class ChatCallInstance {
}); });
void init() { void init() {
subscription = subscription = Hardware.instance.onDeviceChange.stream.listen(revertDevices);
Hardware.instance.onDeviceChange.stream.listen(revertDevices);
room = Room(); room = Room();
listener = room.createListener(); listener = room.createListener();
Hardware.instance.enumerateDevices().then(revertDevices); Hardware.instance.enumerateDevices().then(revertDevices);
@ -179,8 +175,7 @@ class ChatCallInstance {
throw Exception('unauthorized'); throw Exception('unauthorized');
} }
var uri = getRequestUri( var uri = getRequestUri('messaging', '/api/channels/${channel.alias}/calls/ongoing/token');
'messaging', '/api/channels/${channel.alias}/calls/ongoing/token');
var res = await auth.client!.post(uri); var res = await auth.client!.post(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
@ -233,12 +228,10 @@ class ChatCallInstance {
useiOSBroadcastExtension: true, useiOSBroadcastExtension: true,
params: VideoParameters( params: VideoParameters(
dimensions: VideoDimensionsPresets.h1080_169, dimensions: VideoDimensionsPresets.h1080_169,
encoding: encoding: VideoEncoding(maxBitrate: 3 * 1000 * 1000, maxFramerate: 30),
VideoEncoding(maxBitrate: 3 * 1000 * 1000, maxFramerate: 30),
), ),
), ),
defaultCameraCaptureOptions: defaultCameraCaptureOptions: CameraCaptureOptions(maxFrameRate: 30, params: videoParameters),
CameraCaptureOptions(maxFrameRate: 30, params: videoParameters),
), ),
fastConnectOptions: FastConnectOptions( fastConnectOptions: FastConnectOptions(
microphone: TrackOption(track: audioTrack), microphone: TrackOption(track: audioTrack),
@ -271,8 +264,7 @@ class ChatCallInstance {
room.addListener(onRoomDidUpdate); room.addListener(onRoomDidUpdate);
setupRoomListeners(context); setupRoomListeners(context);
sortParticipants(); sortParticipants();
WidgetsBindingCompatible.instance WidgetsBindingCompatible.instance?.addPostFrameCallback((_) => autoPublish(context));
?.addPostFrameCallback((_) => autoPublish(context));
if (lkPlatformIsMobile()) { if (lkPlatformIsMobile()) {
Hardware.instance.setSpeakerphoneOn(true); Hardware.instance.setSpeakerphoneOn(true);
@ -347,8 +339,7 @@ class ChatCallInstance {
} }
// First joined people first // First joined people first
return a.participant.joinedAt.millisecondsSinceEpoch - return a.participant.joinedAt.millisecondsSinceEpoch - b.participant.joinedAt.millisecondsSinceEpoch;
b.participant.joinedAt.millisecondsSinceEpoch;
}); });
ParticipantTrack localTrack = ParticipantTrack( ParticipantTrack localTrack = ParticipantTrack(
@ -357,8 +348,7 @@ class ChatCallInstance {
isScreenShare: false, isScreenShare: false,
); );
if (room.localParticipant != null) { if (room.localParticipant != null) {
final localParticipantTracks = final localParticipantTracks = room.localParticipant?.videoTrackPublications;
room.localParticipant?.videoTrackPublications;
if (localParticipantTracks != null) { if (localParticipantTracks != null) {
for (var t in localParticipantTracks) { for (var t in localParticipantTracks) {
localTrack.videoTrack = t.track; localTrack.videoTrack = t.track;
@ -371,8 +361,7 @@ class ChatCallInstance {
if (focusTrack == null) { if (focusTrack == null) {
focusTrack = participantTracks.first; focusTrack = participantTracks.first;
} else { } else {
final idx = participantTracks final idx = participantTracks.indexWhere((x) => focusTrack!.participant.sid == x.participant.sid);
.indexWhere((x) => focusTrack!.participant.sid == x.participant.sid);
focusTrack = participantTracks[idx]; focusTrack = participantTracks[idx];
} }

View File

@ -108,92 +108,74 @@ class _ChannelEditorScreenState extends State<ChannelEditorScreen> {
child: Text(AppLocalizations.of(context)!.apply.toUpperCase()), child: Text(AppLocalizations.of(context)!.apply.toUpperCase()),
), ),
], ],
child: Center( child: Column(
child: Container( children: [
constraints: const BoxConstraints(maxWidth: 640), _isSubmitting ? const LinearProgressIndicator().animate().scaleX() : Container(),
child: Column( ListTile(
children: [ title: Text(AppLocalizations.of(context)!.chatChannelUsage),
_isSubmitting subtitle: Text(AppLocalizations.of(context)!.chatChannelUsageCaption),
? const LinearProgressIndicator().animate().scaleX() leading: const CircleAvatar(
: Container(), backgroundColor: Colors.teal,
ListTile( child: Icon(Icons.tag, color: Colors.white),
title: Text(AppLocalizations.of(context)!.chatChannelUsage), ),
subtitle:
Text(AppLocalizations.of(context)!.chatChannelUsageCaption),
leading: const CircleAvatar(
backgroundColor: Colors.teal,
child: Icon(Icons.tag, color: Colors.white),
),
),
const Divider(thickness: 0.3),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
child: Row(
children: [
Expanded(
child: TextField(
autofocus: true,
controller: _aliasController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!
.chatChannelAliasLabel,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
TextButton(
style: TextButton.styleFrom(
shape: const CircleBorder(),
visualDensity:
const VisualDensity(horizontal: -2, vertical: -2),
),
onPressed: () => randomizeAlias(),
child: const Icon(Icons.refresh),
)
],
),
),
const Divider(thickness: 0.3),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: TextField(
autocorrect: true,
controller: _nameController,
decoration: InputDecoration.collapsed(
hintText:
AppLocalizations.of(context)!.chatChannelNameLabel,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
const Divider(thickness: 0.3),
Expanded(
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: TextField(
minLines: 5,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.multiline,
controller: _descriptionController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!
.chatChannelDescriptionLabel,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
),
widget.editing != null ? editingBanner : Container(),
],
), ),
), const Divider(thickness: 0.3),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
child: Row(
children: [
Expanded(
child: TextField(
autofocus: true,
controller: _aliasController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!.chatChannelAliasLabel,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
),
),
TextButton(
style: TextButton.styleFrom(
shape: const CircleBorder(),
visualDensity: const VisualDensity(horizontal: -2, vertical: -2),
),
onPressed: () => randomizeAlias(),
child: const Icon(Icons.refresh),
)
],
),
),
const Divider(thickness: 0.3),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: TextField(
autocorrect: true,
controller: _nameController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!.chatChannelNameLabel,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
),
),
const Divider(thickness: 0.3),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: TextField(
minLines: 5,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.multiline,
controller: _descriptionController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!.chatChannelDescriptionLabel,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
),
),
),
widget.editing != null ? editingBanner : Container(),
],
), ),
); );
} }

View File

@ -10,6 +10,7 @@ import 'package:solian/providers/auth.dart';
import 'package:solian/providers/chat.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/chat/channel_action.dart';
import 'package:solian/widgets/chat/maintainer.dart'; import 'package:solian/widgets/chat/maintainer.dart';
import 'package:solian/widgets/chat/message.dart'; import 'package:solian/widgets/chat/message.dart';
import 'package:solian/widgets/chat/message_action.dart'; import 'package:solian/widgets/chat/message_action.dart';
@ -24,10 +25,25 @@ class ChatScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final chat = context.watch<ChatProvider>();
return IndentWrapper( return IndentWrapper(
title: AppLocalizations.of(context)!.post, title: chat.focusChannel?.name ?? 'Loading...',
noSafeArea: true, noSafeArea: true,
hideDrawer: true, hideDrawer: true,
appBarActions: chat.focusChannel != null
? [
ChannelCallAction(
call: chat.ongoingCall,
channel: chat.focusChannel!,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias),
),
ChannelManageAction(
channel: chat.focusChannel!,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias),
),
]
: [],
child: ChatScreenWidget( child: ChatScreenWidget(
alias: alias, alias: alias,
), ),

View File

@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.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/screens/chat/chat.dart'; import 'package:solian/screens/chat/chat.dart';
import 'package:solian/utils/service_url.dart'; import 'package:solian/utils/service_url.dart';
import 'package:solian/widgets/chat/channel_action.dart';
import 'package:solian/widgets/chat/chat_new.dart'; import 'package:solian/widgets/chat/chat_new.dart';
import 'package:solian/widgets/empty.dart'; import 'package:solian/widgets/empty.dart';
import 'package:solian/widgets/exts.dart'; import 'package:solian/widgets/exts.dart';
@ -27,12 +29,26 @@ class _ChatIndexScreenState extends State<ChatIndexScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final chat = context.watch<ChatProvider>();
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
final isLargeScreen = screenWidth >= 600; final isLargeScreen = screenWidth >= 600;
return IndentWrapper( return IndentWrapper(
title: AppLocalizations.of(context)!.chat, title: AppLocalizations.of(context)!.chat,
appBarActions: const [NotificationButton()], appBarActions: chat.focusChannel != null
? [
ChannelCallAction(
call: chat.ongoingCall,
channel: chat.focusChannel!,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias),
),
ChannelManageAction(
channel: chat.focusChannel!,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias),
),
]
: [const NotificationButton()],
fixedAppBarColor: isLargeScreen, fixedAppBarColor: isLargeScreen,
child: isLargeScreen child: isLargeScreen
? Row( ? Row(