< Summary

Class:DCL.DCLVoiceChatController
Assembly:VoiceChatController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/VoiceChat/DCLVoiceChatController.cs
Covered lines:18
Uncovered lines:33
Coverable lines:51
Total lines:122
Line coverage:35.2% (18 of 51)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DCLVoiceChatController()0%110100%
Awake()0%330100%
OnDestroy()0%110100%
OnKernelConfigChanged(...)0%2100%
EnableVoiceChat(...)0%110100%
IsVoiceChatRecordingChanged(...)0%56700%
ToggleVoiceChatRecording()0%12300%
CreateSocialAnalyticsIfNeeded()0%6200%
SendFirstTimeMetricIfNeeded()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/VoiceChat/DCLVoiceChatController.cs

#LineLine coverage
 1using UnityEngine;
 2using SocialFeaturesAnalytics;
 3using System.Collections.Generic;
 4
 5namespace DCL
 6{
 7    public class DCLVoiceChatController : MonoBehaviour
 8    {
 9        [Header("InputActions")]
 10        public InputAction_Hold voiceChatAction;
 11        public InputAction_Trigger voiceChatToggleAction;
 12
 13        private InputAction_Hold.Started voiceChatStartedDelegate;
 14        private InputAction_Hold.Finished voiceChatFinishedDelegate;
 15        private InputAction_Trigger.Triggered voiceChatToggleDelegate;
 16
 59617        private bool firstTimeVoiceRecorded = true;
 18        private ISocialAnalytics socialAnalytics;
 19        private UserProfileWebInterfaceBridge userProfileWebInterfaceBridge;
 20        private double voiceMessageStartTime = 0;
 21        private bool isVoiceChatToggledOn = false;
 22
 23        void Awake()
 24        {
 58325            userProfileWebInterfaceBridge = new UserProfileWebInterfaceBridge();
 26
 58327            voiceChatStartedDelegate = (action) => DataStore.i.voiceChat.isRecording.Set(new KeyValuePair<bool, bool>(tr
 58328            voiceChatFinishedDelegate = (action) => DataStore.i.voiceChat.isRecording.Set(new KeyValuePair<bool, bool>(f
 58329            voiceChatToggleDelegate = (action) => ToggleVoiceChatRecording();
 58330            voiceChatAction.OnStarted += voiceChatStartedDelegate;
 58331            voiceChatAction.OnFinished += voiceChatFinishedDelegate;
 58332            voiceChatToggleAction.OnTriggered += voiceChatToggleDelegate;
 33
 75634            KernelConfig.i.EnsureConfigInitialized().Then(config => EnableVoiceChat(config.comms.voiceChatEnabled));
 58335            KernelConfig.i.OnChange += OnKernelConfigChanged;
 58336            DataStore.i.voiceChat.isRecording.OnChange += IsVoiceChatRecordingChanged;
 58337        }
 38
 39        void OnDestroy()
 40        {
 58341            voiceChatAction.OnStarted -= voiceChatStartedDelegate;
 58342            voiceChatAction.OnFinished -= voiceChatFinishedDelegate;
 58343            KernelConfig.i.OnChange -= OnKernelConfigChanged;
 58344            DataStore.i.voiceChat.isRecording.OnChange -= IsVoiceChatRecordingChanged;
 58345        }
 46
 047        void OnKernelConfigChanged(KernelConfigModel current, KernelConfigModel previous) { EnableVoiceChat(current.comm
 48
 34649        void EnableVoiceChat(bool enable) { CommonScriptableObjects.voiceChatDisabled.Set(!enable); }
 50
 51        private void IsVoiceChatRecordingChanged(KeyValuePair<bool, bool> current, KeyValuePair<bool, bool> previous)
 52        {
 053            if (!DataStore.i.voiceChat.isJoinedToVoiceChat.Get())
 054                return;
 55
 056            CreateSocialAnalyticsIfNeeded();
 57
 058            if (current.Key)
 59            {
 060                if (!isVoiceChatToggledOn)
 61                {
 062                    Interface.WebInterface.SendSetVoiceChatRecording(true);
 063                    SendFirstTimeMetricIfNeeded();
 064                    voiceMessageStartTime = Time.realtimeSinceStartup;
 65                }
 066            }
 67            else
 68            {
 069                Interface.WebInterface.SendSetVoiceChatRecording(false);
 70
 071                socialAnalytics.SendVoiceMessage(
 72                    Time.realtimeSinceStartup - voiceMessageStartTime,
 73                    (current.Value || isVoiceChatToggledOn) ? VoiceMessageSource.Shortcut : VoiceMessageSource.Button,
 74                    userProfileWebInterfaceBridge.GetOwn().userId);
 75
 076                isVoiceChatToggledOn = false;
 77            }
 078        }
 79
 80        private void ToggleVoiceChatRecording()
 81        {
 082            if (!DataStore.i.voiceChat.isJoinedToVoiceChat.Get())
 083                return;
 84
 085            Interface.WebInterface.ToggleVoiceChatRecording();
 086            isVoiceChatToggledOn = !isVoiceChatToggledOn;
 87
 088            if (isVoiceChatToggledOn)
 89            {
 090                SendFirstTimeMetricIfNeeded();
 091                voiceMessageStartTime = Time.realtimeSinceStartup;
 092            }
 93            else
 94            {
 095                socialAnalytics.SendVoiceMessage(
 96                    Time.realtimeSinceStartup - voiceMessageStartTime,
 97                    VoiceMessageSource.Shortcut,
 98                    userProfileWebInterfaceBridge.GetOwn().userId);
 99            }
 0100        }
 101
 102        private void CreateSocialAnalyticsIfNeeded()
 103        {
 0104            if (socialAnalytics != null)
 0105                return;
 106
 0107            socialAnalytics = new SocialAnalytics(
 108                Environment.i.platform.serviceProviders.analytics,
 109                userProfileWebInterfaceBridge);
 0110        }
 111
 112        private void SendFirstTimeMetricIfNeeded()
 113        {
 0114            if (firstTimeVoiceRecorded)
 115            {
 0116                CreateSocialAnalyticsIfNeeded();
 0117                socialAnalytics.SendVoiceMessageStartedByFirstTime();
 0118                firstTimeVoiceRecorded = false;
 119            }
 0120        }
 121    }
 122}