🐛 Bug fixes of sort participants
This commit is contained in:
parent
0483e99a4c
commit
db45764d42
@ -64,5 +64,5 @@ class ParticipantTrack {
|
|||||||
required this.isScreenShare});
|
required this.isScreenShare});
|
||||||
VideoTrack? videoTrack;
|
VideoTrack? videoTrack;
|
||||||
Participant participant;
|
Participant participant;
|
||||||
final bool isScreenShare;
|
bool isScreenShare;
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ import 'package:solian/models/call.dart';
|
|||||||
import 'package:solian/providers/auth.dart';
|
import 'package:solian/providers/auth.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/call/controls.dart';
|
||||||
import 'package:solian/widgets/chat/call/exts.dart';
|
import 'package:solian/widgets/chat/call/exts.dart';
|
||||||
import 'package:solian/widgets/chat/call/participant.dart';
|
import 'package:solian/widgets/chat/call/participant.dart';
|
||||||
import 'package:solian/widgets/indent_wrapper.dart';
|
import 'package:solian/widgets/indent_wrapper.dart';
|
||||||
@ -16,8 +17,6 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import '../../widgets/chat/call/controls.dart';
|
|
||||||
|
|
||||||
class ChatCall extends StatefulWidget {
|
class ChatCall extends StatefulWidget {
|
||||||
final Call call;
|
final Call call;
|
||||||
|
|
||||||
@ -52,7 +51,6 @@ class _ChatCallState extends State<ChatCall> {
|
|||||||
List<ParticipantTrack> _participantTracks = [];
|
List<ParticipantTrack> _participantTracks = [];
|
||||||
|
|
||||||
Future<void> checkPermissions() async {
|
Future<void> checkPermissions() async {
|
||||||
if (lkPlatformIs(PlatformType.macOS) || lkPlatformIs(PlatformType.linux)) return;
|
|
||||||
await Permission.camera.request();
|
await Permission.camera.request();
|
||||||
await Permission.microphone.request();
|
await Permission.microphone.request();
|
||||||
await Permission.bluetooth.request();
|
await Permission.bluetooth.request();
|
||||||
@ -201,32 +199,30 @@ class _ChatCallState extends State<ChatCall> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sortParticipants() {
|
void sortParticipants() {
|
||||||
List<ParticipantTrack> userMediaTracks = [];
|
|
||||||
List<ParticipantTrack> screenTracks = [];
|
List<ParticipantTrack> screenTracks = [];
|
||||||
|
Map<String, ParticipantTrack> userMediaTracks = {};
|
||||||
for (var participant in _callRoom.remoteParticipants.values) {
|
for (var participant in _callRoom.remoteParticipants.values) {
|
||||||
for (var t in participant.trackPublications.values) {
|
userMediaTracks[participant.sid] = ParticipantTrack(
|
||||||
|
participant: participant,
|
||||||
|
videoTrack: null,
|
||||||
|
isScreenShare: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (var t in participant.videoTrackPublications) {
|
||||||
if (t.isScreenShare) {
|
if (t.isScreenShare) {
|
||||||
screenTracks.add(ParticipantTrack(
|
screenTracks.add(ParticipantTrack(
|
||||||
participant: participant,
|
participant: participant,
|
||||||
videoTrack: t.track as VideoTrack,
|
videoTrack: t.track as VideoTrack,
|
||||||
isScreenShare: true,
|
isScreenShare: true,
|
||||||
));
|
));
|
||||||
} else if (t.track is VideoTrack) {
|
|
||||||
userMediaTracks.add(ParticipantTrack(
|
|
||||||
participant: participant,
|
|
||||||
videoTrack: t.track as VideoTrack,
|
|
||||||
isScreenShare: false,
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
userMediaTracks.add(ParticipantTrack(
|
userMediaTracks[participant.sid]?.videoTrack = t.track;
|
||||||
participant: participant,
|
|
||||||
videoTrack: null,
|
|
||||||
isScreenShare: false,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userMediaTracks.sort((a, b) {
|
|
||||||
|
final userMediaTrackList = userMediaTracks.values.toList();
|
||||||
|
userMediaTrackList.sort((a, b) {
|
||||||
// Loudest people first
|
// Loudest people first
|
||||||
if (a.participant.isSpeaking && b.participant.isSpeaking) {
|
if (a.participant.isSpeaking && b.participant.isSpeaking) {
|
||||||
if (a.participant.audioLevel > b.participant.audioLevel) {
|
if (a.participant.audioLevel > b.participant.audioLevel) {
|
||||||
@ -253,40 +249,30 @@ class _ChatCallState extends State<ChatCall> {
|
|||||||
return a.participant.joinedAt.millisecondsSinceEpoch - b.participant.joinedAt.millisecondsSinceEpoch;
|
return a.participant.joinedAt.millisecondsSinceEpoch - b.participant.joinedAt.millisecondsSinceEpoch;
|
||||||
});
|
});
|
||||||
|
|
||||||
final localParticipantTracks = _callRoom.localParticipant?.trackPublications.values;
|
ParticipantTrack localTrack = ParticipantTrack(
|
||||||
if (localParticipantTracks != null) {
|
participant: _callRoom.localParticipant!,
|
||||||
for (var t in localParticipantTracks) {
|
videoTrack: null,
|
||||||
if (t.isScreenShare) {
|
isScreenShare: false,
|
||||||
screenTracks.add(ParticipantTrack(
|
);
|
||||||
participant: _callRoom.localParticipant!,
|
if (_callRoom.localParticipant != null) {
|
||||||
videoTrack: t.track as VideoTrack,
|
final localParticipantTracks = _callRoom.localParticipant?.videoTrackPublications;
|
||||||
isScreenShare: true,
|
if (localParticipantTracks != null) {
|
||||||
));
|
for (var t in localParticipantTracks) {
|
||||||
} else if (t.track is VideoTrack) {
|
if (t.isScreenShare) {
|
||||||
userMediaTracks.add(ParticipantTrack(
|
screenTracks.add(ParticipantTrack(
|
||||||
participant: _callRoom.localParticipant!,
|
participant: _callRoom.localParticipant!,
|
||||||
videoTrack: t.track as VideoTrack,
|
videoTrack: t.track as VideoTrack,
|
||||||
isScreenShare: false,
|
isScreenShare: true,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
userMediaTracks.add(ParticipantTrack(
|
localTrack.videoTrack = t.track;
|
||||||
participant: _callRoom.localParticipant!,
|
}
|
||||||
videoTrack: null,
|
|
||||||
isScreenShare: false,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var checklistIdx = List<String>.empty(growable: true);
|
|
||||||
userMediaTracks = userMediaTracks.where((element) {
|
|
||||||
if(checklistIdx.contains(element.participant.sid)) return false;
|
|
||||||
checklistIdx.add(element.participant.sid);
|
|
||||||
return true;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_participantTracks = [...screenTracks, ...userMediaTracks];
|
_participantTracks = [...screenTracks, localTrack, ...userMediaTrackList];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user