Ejemplo n.º 1
0
        public void GetUpdate_AppendOneUpdate_ReturnUpdate()
        {
            // arrange
            var aggregator = Create();

            var update = new SfuConferenceInfoUpdate(new Dictionary <string, string> {
                { "participant1", "room1" }
            },
                                                     new Dictionary <string, SfuParticipantPermissions>
            {
                { "participant2", new SfuParticipantPermissions(false, true, true) },
            }, new[] { "participant3" });

            aggregator.Append(update);

            // act
            var result = aggregator.GetUpdate();

            // assert
            Assert.Single(result.RemovedParticipants, "participant3");
            Assert.Single(result.ParticipantPermissions,
                          new KeyValuePair <string, SfuParticipantPermissions>("participant2",
                                                                               new SfuParticipantPermissions(false, true, true)));
            Assert.Single(result.ParticipantToRoom, new KeyValuePair <string, string>("participant1", "room1"));
        }
Ejemplo n.º 2
0
        public async Task Handle(ParticipantsRoomChangedNotification notification, CancellationToken cancellationToken)
        {
            var updatedParticipants = notification.Participants.Where(x => x.Value.TargetRoom != null)
                                      .ToDictionary(x => x.Key.Id, x => x.Value.TargetRoom !);

            var participantsLeft = notification.Participants.Where(x => x.Value.TargetRoom == null)
                                   .Select(x => x.Key.Id).ToList();

            var update = new SfuConferenceInfoUpdate(updatedParticipants,
                                                     ImmutableDictionary <string, SfuParticipantPermissions> .Empty, participantsLeft);

            await _notifier.Update(notification.ConferenceId, update);
        }
Ejemplo n.º 3
0
        public async Task Handle(ParticipantPermissionsUpdatedNotification notification,
                                 CancellationToken cancellationToken)
        {
            var updatedPermissions = new Dictionary <string, SfuParticipantPermissions>();

            foreach (var(participant, permissions) in notification.UpdatedPermissions)
            {
                var sfuPermissions = await SfuPermissionUtils.MapToSfuPermissions(permissions);

                updatedPermissions.Add(participant.Id, sfuPermissions);
            }

            var conferenceId = notification.UpdatedPermissions.First().Key.ConferenceId;
            var updated      = new SfuConferenceInfoUpdate(ImmutableDictionary <string, string> .Empty, updatedPermissions,
                                                           ImmutableList <string> .Empty);

            await _notifier.Update(conferenceId, updated);
        }
Ejemplo n.º 4
0
        private static SfuConferenceInfo ApplyUpdate(SfuConferenceInfo current, SfuConferenceInfoUpdate update)
        {
            var newPermissions  = current.ParticipantPermissions.ToDictionary(x => x.Key, x => x.Value);
            var newParticipants = current.ParticipantToRoom.ToDictionary(x => x.Key, x => x.Value);

            foreach (var updatePermission in update.ParticipantPermissions)
            {
                newPermissions[updatePermission.Key] = updatePermission.Value;
            }

            foreach (var(participantId, roomId) in update.ParticipantToRoom)
            {
                newParticipants[participantId] = roomId;
            }

            foreach (var removedParticipantId in update.RemovedParticipants)
            {
                newPermissions.Remove(removedParticipantId);
                newParticipants.Remove(removedParticipantId);
            }

            return(new SfuConferenceInfo(newParticipants, newPermissions));
        }
Ejemplo n.º 5
0
 public async Task Update(string conferenceId, SfuConferenceInfoUpdate value)
 {
     await _publishEndpoint.Publish <MediaStateChanged>(
         new { ConferenceId = conferenceId, Type = "Update", Payload = value },
         context => SetupContext(context, conferenceId));
 }