Пример #1
0
        private void OnVoiceStateUpdated(JsonVoiceState arg)
        {
            if (arg.UserId == Self.CurrentUser?.Id)
            {
                Voice.UpdateSelfVoiceState(arg);
            }

            Voice.UpdateVoiceState(arg);
        }
Пример #2
0
        internal void Update(JsonVoiceState json)
        {
            Guard.IsEqualTo(json.UserId, User.Id, nameof(json.UserId));

            ServerMute  = json.Mute;
            ServerDeaf  = json.Deaf;
            SelfMute    = json.SelfMute;
            SelfDeaf    = json.SelfDeaf;
            Suppress    = json.Suppress;
            HasVideo    = json.SelfVideo;
            IsStreaming = json.SelfStream ?? false;

            GetChannel(json.ChannelId);
        }
Пример #3
0
        internal VoiceState(JsonVoiceState json, QuarrelClient context) :
            base(context)
        {
            var user = context.Users.GetUser(json.UserId);

            Guard.IsNotNull(user, nameof(user));
            User = user;

            ServerMute  = json.Mute;
            ServerDeaf  = json.Deaf;
            SelfMute    = json.SelfMute;
            SelfDeaf    = json.SelfDeaf;
            Suppress    = json.Suppress;
            HasVideo    = json.SelfVideo;
            IsStreaming = json.SelfStream ?? false;

            GetChannel(json.ChannelId);
        }
Пример #4
0
            internal void UpdateSelfVoiceState(JsonVoiceState state)
            {
                lock (_stateLock)
                {
                    _selfState = state;

                    if (_selfState.ChannelId == null)
                    {
                        _voiceConnection?.Disconnect();
                        Disconnected?.Invoke();
                        _voiceConnection   = null;
                        _selfState         = null;
                        _voiceServerConfig = null;
                    }
                    else if (_voiceServerConfig != null)
                    {
                        _ = ConnectToVoice();
                    }
                }
            }
Пример #5
0
            internal void UpdateVoiceState(JsonVoiceState state)
            {
                StatusChange change = StatusChange.Added;

                if (_stateDictionary.TryGetValue(state.UserId, out VoiceState voiceState))
                {
                    if (state.ChannelId != voiceState.Channel?.Id)
                    {
                        change = StatusChange.Updated;
                    }
                    else if (!state.ChannelId.HasValue)
                    {
                        change = StatusChange.Removed;
                    }
                    else
                    {
                        change = StatusChange.Moved;
                    }
                }

                IAudioChannel?channel = state.ChannelId.HasValue ? (IAudioChannel?)_client.Channels.GetChannel(state.ChannelId.Value) : null;

                void AddState()
                {
                    _stateDictionary.Add(state.UserId, voiceState);
                    channel?.AddVoiceMember(state.UserId);
                    _client.VoiceStateAdded?.Invoke(_client, voiceState);
                }

                void RemoveState()
                {
                    _stateDictionary.Remove(state.UserId);
                    channel?.RemoveVoiceMember(state.UserId);
                    _client.VoiceStateRemoved?.Invoke(_client, voiceState);
                }

                switch (change)
                {
                case StatusChange.Added:
                    voiceState = new VoiceState(state, _client);
                    AddState();
                    break;

                case StatusChange.Removed:
                    voiceState !.Update(state);
                    RemoveState();
                    break;

                case StatusChange.Moved:
                    voiceState !.Update(state);
                    RemoveState();
                    AddState();
                    break;

                case StatusChange.Updated:
                    voiceState !.Update(state);
                    break;
                }

                _client.VoiceStateUpdated?.Invoke(_client, voiceState);
            }