Skip to content

Commit 4776dc0

Browse files
authored
fixing call participants creation when receving call details (#613)
1 parent 9adbe5d commit 4776dc0

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

dogfooding/lib/screens/lobby_screen.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ class _LobbyScreenState extends State<LobbyScreen> {
2828
RtcLocalCameraTrack? _cameraTrack;
2929

3030
final _userAuthController = locator.get<UserAuthController>();
31+
bool _isJoiningCall = false;
3132

3233
void joinCallPressed() {
34+
_isJoiningCall = true;
35+
3336
var options = const CallConnectOptions();
3437

3538
final cameraTrack = _cameraTrack;
@@ -49,6 +52,19 @@ class _LobbyScreenState extends State<LobbyScreen> {
4952
widget.onJoinCallPressed(options);
5053
}
5154

55+
@override
56+
void dispose() {
57+
// Dispose tracks if we closed lobby screen without joining the call.
58+
if (!_isJoiningCall) {
59+
_cameraTrack?.stop();
60+
_microphoneTrack?.stop();
61+
}
62+
63+
_cameraTrack = null;
64+
_microphoneTrack = null;
65+
super.dispose();
66+
}
67+
5268
@override
5369
Widget build(BuildContext context) {
5470
final streamVideoTheme = StreamVideoTheme.of(context);

packages/stream_video/lib/src/call/call.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class Call {
233233

234234
StreamCallCid get callCid => state.value.callCid;
235235

236-
String get type => state.value.callType;
236+
StreamCallType get type => state.value.callType;
237237

238238
String get id => state.value.callId;
239239

@@ -533,14 +533,17 @@ class Call {
533533

534534
_logger.v(() => '[join] starting sfu session');
535535
final sessionResult = await _startSession(joinedResult.data);
536+
536537
if (sessionResult is! Success<None>) {
537538
_logger.w(() => '[join] sfu session start failed: $sessionResult');
538539
final error = (sessionResult as Failure).error;
539540
_stateManager.lifecycleCallConnectFailed(ConnectFailed(error));
540541
return sessionResult;
541542
}
543+
542544
_logger.v(() => '[join] started session');
543545
_stateManager.lifecycleCallConnected(const CallConnected());
546+
544547
await _applyConnectOptions();
545548

546549
_logger.v(() => '[join] completed');

packages/stream_video/lib/src/call/state/mixins/state_lifecycle_mixin.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:collection/collection.dart';
12
import 'package:state_notifier/state_notifier.dart';
23
import 'package:collection/collection.dart';
34

@@ -312,24 +313,39 @@ mixin StateLifecycleMixin on StateNotifier<CallState> {
312313
extension on CallMetadata {
313314
List<CallParticipantState> toCallParticipants(CallState state) {
314315
final result = <CallParticipantState>[];
315-
for (final userId in members.keys) {
316+
317+
for (final participant in session.participants.values) {
318+
final userId = participant.userId;
316319
final member = members[userId];
317320
final user = users[userId];
321+
final currentState =
322+
state.callParticipants.firstWhereOrNull((it) => it.userId == userId);
318323
final isLocal = state.currentUserId == userId;
324+
319325
result.add(
320-
CallParticipantState(
321-
userId: userId,
322-
role: member?.role ?? user?.role ?? '',
323-
name: user?.name ?? '',
324-
custom: user?.custom ?? {},
325-
image: user?.image ?? '',
326-
sessionId: '',
327-
trackIdPrefix: '',
328-
isLocal: isLocal,
329-
isOnline: !isLocal,
330-
),
326+
currentState?.copyWith(
327+
role: member?.role ?? user?.role ?? '',
328+
name: user?.name ?? '',
329+
custom: user?.custom ?? {},
330+
image: user?.image ?? '',
331+
sessionId: participant.userSessionId,
332+
isLocal: isLocal,
333+
isOnline: !isLocal,
334+
) ??
335+
CallParticipantState(
336+
userId: userId,
337+
role: member?.role ?? user?.role ?? '',
338+
name: user?.name ?? '',
339+
custom: user?.custom ?? {},
340+
image: user?.image ?? '',
341+
sessionId: participant.userSessionId,
342+
trackIdPrefix: '',
343+
isLocal: isLocal,
344+
isOnline: !isLocal,
345+
),
331346
);
332347
}
348+
333349
return result;
334350
}
335351
}

packages/stream_video/lib/src/call_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class CallState extends Equatable {
140140

141141
String get callId => callCid.id;
142142

143-
String get callType => callCid.id;
143+
StreamCallType get callType => callCid.type;
144144

145145
CallParticipantState? get localParticipant {
146146
return callParticipants.firstWhereOrNull((element) => element.isLocal);

0 commit comments

Comments
 (0)