From 5ccc165c7bab62f3f5ad53c1abf4b093a22d5d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Bra=C5=BCewicz?= Date: Thu, 21 Dec 2023 16:05:23 +0100 Subject: [PATCH] add custom data to call participants (#560) * add custom data to call participants * changelog --- .../lib/src/call/state/mixins/state_coordinator_mixin.dart | 1 + .../lib/src/call/state/mixins/state_lifecycle_mixin.dart | 1 + .../lib/src/call/state/mixins/state_sfu_mixin.dart | 2 ++ packages/stream_video/lib/src/call_state.dart | 1 + .../stream_video/lib/src/models/call_participant_state.dart | 5 +++++ .../src/sfu/data/events/sfu_event_mapper_extensions.dart | 1 + .../lib/src/sfu/data/models/sfu_goaway_reason.dart | 2 +- .../lib/src/sfu/data/models/sfu_participant.dart | 5 +++++ .../test/call_participant_state_sorting_test.dart | 6 ++++++ packages/stream_video_flutter/CHANGELOG.md | 4 ++++ 10 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/stream_video/lib/src/call/state/mixins/state_coordinator_mixin.dart b/packages/stream_video/lib/src/call/state/mixins/state_coordinator_mixin.dart index 6692c5bd2..80c763b39 100644 --- a/packages/stream_video/lib/src/call/state/mixins/state_coordinator_mixin.dart +++ b/packages/stream_video/lib/src/call/state/mixins/state_coordinator_mixin.dart @@ -280,6 +280,7 @@ mixin StateCoordinatorMixin on StateNotifier { userId: e.userId, role: e.role, name: e.name, + custom: e.custom, sessionId: e.sessionId, trackIdPrefix: e.trackIdPrefix, image: e.image, diff --git a/packages/stream_video/lib/src/call/state/mixins/state_lifecycle_mixin.dart b/packages/stream_video/lib/src/call/state/mixins/state_lifecycle_mixin.dart index 8d3ed2701..57db5bd80 100644 --- a/packages/stream_video/lib/src/call/state/mixins/state_lifecycle_mixin.dart +++ b/packages/stream_video/lib/src/call/state/mixins/state_lifecycle_mixin.dart @@ -276,6 +276,7 @@ extension on CallMetadata { userId: userId, role: member?.role ?? user?.role ?? '', name: user?.name ?? '', + custom: user?.custom ?? {}, image: user?.image ?? '', sessionId: '', trackIdPrefix: '', diff --git a/packages/stream_video/lib/src/call/state/mixins/state_sfu_mixin.dart b/packages/stream_video/lib/src/call/state/mixins/state_sfu_mixin.dart index 01be8f387..d75ee848c 100644 --- a/packages/stream_video/lib/src/call/state/mixins/state_sfu_mixin.dart +++ b/packages/stream_video/lib/src/call/state/mixins/state_sfu_mixin.dart @@ -59,6 +59,7 @@ mixin StateSfuMixin on StateNotifier { userId: aParticipant.userId, role: existingRole, name: aParticipant.userName.ifEmpty(() => existingName), + custom: aParticipant.custom, image: aParticipant.userImage.ifEmpty(() => existingImage), sessionId: aParticipant.sessionId, trackIdPrefix: aParticipant.trackLookupPrefix, @@ -208,6 +209,7 @@ mixin StateSfuMixin on StateNotifier { userId: event.participant.userId, role: '', name: event.participant.userName, + custom: event.participant.custom, image: event.participant.userImage, sessionId: event.participant.sessionId, trackIdPrefix: event.participant.trackLookupPrefix, diff --git a/packages/stream_video/lib/src/call_state.dart b/packages/stream_video/lib/src/call_state.dart index 1c2e374b8..c5a07f355 100644 --- a/packages/stream_video/lib/src/call_state.dart +++ b/packages/stream_video/lib/src/call_state.dart @@ -258,6 +258,7 @@ extension on CallMetadata { userId: userId, role: member?.role ?? user?.role ?? '', name: user?.name ?? '', + custom: user?.custom ?? {}, image: user?.image ?? '', sessionId: '', trackIdPrefix: '', diff --git a/packages/stream_video/lib/src/models/call_participant_state.dart b/packages/stream_video/lib/src/models/call_participant_state.dart index 9e376e855..6833eca42 100644 --- a/packages/stream_video/lib/src/models/call_participant_state.dart +++ b/packages/stream_video/lib/src/models/call_participant_state.dart @@ -16,6 +16,7 @@ class CallParticipantState required this.userId, required this.role, required this.name, + required this.custom, this.image, required this.sessionId, required this.trackIdPrefix, @@ -34,6 +35,7 @@ class CallParticipantState final String userId; final String role; final String name; + final Map custom; final String? image; final String sessionId; final String trackIdPrefix; @@ -54,6 +56,7 @@ class CallParticipantState String? userId, String? role, String? name, + Map? custom, String? image, String? sessionId, String? trackIdPrefix, @@ -72,6 +75,7 @@ class CallParticipantState userId: userId ?? this.userId, role: role ?? this.role, name: name ?? this.name, + custom: custom ?? this.custom, image: image ?? this.image, sessionId: sessionId ?? this.sessionId, trackIdPrefix: trackIdPrefix ?? this.trackIdPrefix, @@ -123,6 +127,7 @@ class CallParticipantState userId, role, name, + custom, image, sessionId, trackIdPrefix, diff --git a/packages/stream_video/lib/src/sfu/data/events/sfu_event_mapper_extensions.dart b/packages/stream_video/lib/src/sfu/data/events/sfu_event_mapper_extensions.dart index 60fe32128..9a05882d3 100644 --- a/packages/stream_video/lib/src/sfu/data/events/sfu_event_mapper_extensions.dart +++ b/packages/stream_video/lib/src/sfu/data/events/sfu_event_mapper_extensions.dart @@ -178,6 +178,7 @@ extension SfuParticipantExtension on sfu_models.Participant { userName: name, userImage: image, sessionId: sessionId, + custom: custom.fields, publishedTracks: publishedTracks .map( (track) => track.toDomain(), diff --git a/packages/stream_video/lib/src/sfu/data/models/sfu_goaway_reason.dart b/packages/stream_video/lib/src/sfu/data/models/sfu_goaway_reason.dart index 0530a6fb1..79a6fbda1 100644 --- a/packages/stream_video/lib/src/sfu/data/models/sfu_goaway_reason.dart +++ b/packages/stream_video/lib/src/sfu/data/models/sfu_goaway_reason.dart @@ -7,4 +7,4 @@ enum SfuGoAwayReason { String toString() { return name; } -} \ No newline at end of file +} diff --git a/packages/stream_video/lib/src/sfu/data/models/sfu_participant.dart b/packages/stream_video/lib/src/sfu/data/models/sfu_participant.dart index 06653ac6d..1abf52918 100644 --- a/packages/stream_video/lib/src/sfu/data/models/sfu_participant.dart +++ b/packages/stream_video/lib/src/sfu/data/models/sfu_participant.dart @@ -9,6 +9,7 @@ class SfuParticipant with EquatableMixin { required this.userName, required this.userImage, required this.sessionId, + required this.custom, required this.publishedTracks, required this.joinedAt, required this.trackLookupPrefix, @@ -23,6 +24,7 @@ class SfuParticipant with EquatableMixin { final String userName; final String userImage; final String sessionId; + final Map custom; final List publishedTracks; final DateTime joinedAt; final String trackLookupPrefix; @@ -37,6 +39,7 @@ class SfuParticipant with EquatableMixin { String? userName, String? userImage, String? sessionId, + Map? custom, List? publishedTracks, DateTime? joinedAt, String? trackLookupPrefix, @@ -51,6 +54,7 @@ class SfuParticipant with EquatableMixin { userName: userId ?? this.userName, userImage: userId ?? this.userImage, sessionId: sessionId ?? this.sessionId, + custom: custom ?? this.custom, publishedTracks: publishedTracks ?? this.publishedTracks, joinedAt: joinedAt ?? this.joinedAt, trackLookupPrefix: trackLookupPrefix ?? this.trackLookupPrefix, @@ -78,6 +82,7 @@ class SfuParticipant with EquatableMixin { userName, userImage, sessionId, + custom, publishedTracks, joinedAt, trackLookupPrefix, diff --git a/packages/stream_video/test/call_participant_state_sorting_test.dart b/packages/stream_video/test/call_participant_state_sorting_test.dart index d61e11571..df270e0d2 100644 --- a/packages/stream_video/test/call_participant_state_sorting_test.dart +++ b/packages/stream_video/test/call_participant_state_sorting_test.dart @@ -14,6 +14,7 @@ void main() { name: 'A', userId: '1', sessionId: '1', + custom: const {}, role: 'admin', trackIdPrefix: '123', publishedTracks: { @@ -33,6 +34,7 @@ void main() { name: 'B', userId: '2', sessionId: '2', + custom: const {}, role: 'admin', trackIdPrefix: '123', publishedTracks: { @@ -53,6 +55,7 @@ void main() { name: 'C', userId: '3', sessionId: '3', + custom: {}, role: 'admin', trackIdPrefix: '123', publishedTracks: {}, @@ -69,6 +72,7 @@ void main() { name: 'D', userId: '4', sessionId: '4', + custom: const {}, role: 'admin', trackIdPrefix: '123', publishedTracks: {SfuTrackType.audio: TrackState.remote()}, @@ -85,6 +89,7 @@ void main() { name: 'E', userId: '5', sessionId: '5', + custom: const {}, role: 'admin', trackIdPrefix: '123', publishedTracks: {SfuTrackType.screenShare: TrackState.remote()}, @@ -101,6 +106,7 @@ void main() { name: 'F', userId: '6', sessionId: '6', + custom: const {}, role: 'admin', trackIdPrefix: '123', publishedTracks: { diff --git a/packages/stream_video_flutter/CHANGELOG.md b/packages/stream_video_flutter/CHANGELOG.md index f57d30f3d..21e808541 100644 --- a/packages/stream_video_flutter/CHANGELOG.md +++ b/packages/stream_video_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## Upcoming + +* Added `custom` field to `CallParticipantState` with custom user data. + ## 0.3.1 * Important: Fixes crash for CallKit on iOS.