< Summary

Class:DCL.LoadingScreen.LoadingScreenTimeoutController
Assembly:DCL.LoadingScreen
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreen/Scripts/LoadingScreenTimeoutController.cs
Covered lines:0
Uncovered lines:37
Coverable lines:37
Total lines:112
Line coverage:0% (0 of 37)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadingScreenTimeoutController(...)0%12300%
StartTimeoutCounter()0%20400%
DoTimeout()0%90900%
StartTimeout(...)0%2100%
StopTimeout()0%2100%
ExitClicked()0%2100%
GoBackHomeClicked()0%2100%
Dispose()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreen/Scripts/LoadingScreenTimeoutController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Controllers;
 3using DCL.Helpers;
 4using DCL.Interface;
 5using DCL.NotificationModel;
 6using DCL.Tasks;
 7using System;
 8using System.Collections.Generic;
 9using System.Threading;
 10using UnityEngine;
 11using Type = System.Type;
 12
 13namespace DCL.LoadingScreen
 14{
 15    public class LoadingScreenTimeoutController : IDisposable
 16    {
 17        private const int LOAD_SCENE_TIMEOUT = 120000;
 18        private const int WEBSOCKET_TIMEOUT = 15000;
 19
 20        internal int currentEvaluatedTimeout;
 21
 22        private LoadingScreenController loadingScreenController;
 23        private CancellationTokenSource timeoutCTS;
 24        internal ILoadingScreenTimeoutView view;
 25        private IWorldState worldState;
 26        private Vector2Int currentDestination;
 27
 28        internal bool goHomeRequested;
 29
 030        public LoadingScreenTimeoutController(ILoadingScreenTimeoutView loadingScreenTimeoutView, IWorldState worldState
 31        {
 032            this.view = loadingScreenTimeoutView;
 033            this.loadingScreenController = loadingScreenController;
 34
 035            view.OnExitButtonClicked += ExitClicked;
 036            view.OnJumpHomeButtonClicked += GoBackHomeClicked;
 37
 038            this.worldState = worldState;
 39
 040            currentEvaluatedTimeout = Application.platform == RuntimePlatform.WebGLPlayer ? LOAD_SCENE_TIMEOUT : WEBSOCK
 041        }
 42
 43        private async UniTaskVoid StartTimeoutCounter(CancellationToken ct)
 44        {
 045            if (!await UniTask.Delay(TimeSpan.FromMilliseconds(currentEvaluatedTimeout), cancellationToken: ct).Suppress
 046                DoTimeout();
 047        }
 48
 49        private void DoTimeout()
 50        {
 051            IParcelScene destinationScene = worldState.GetScene(worldState.GetSceneNumberByCoords(currentDestination));
 52
 053            if (destinationScene != null)
 54            {
 055                Dictionary<string, string> variables = new Dictionary<string, string>
 56                {
 57                    { "sceneID", destinationScene.sceneData?.id },
 58                    { "contentServer", destinationScene.contentProvider?.baseUrl },
 59                    { "contentServerBundlesUrl", destinationScene.contentProvider?.assetBundlesBaseUrl },
 60                };
 61
 062                GenericAnalytics.SendAnalytic("scene_loading_failed", variables);
 63            }
 64
 065            if (goHomeRequested)
 066                loadingScreenController.RandomPositionRequested();
 67            else
 068                view.ShowSceneTimeout();
 69
 070            goHomeRequested = false;
 071        }
 72
 73        public void StartTimeout(Vector2Int newDestination)
 74        {
 075            timeoutCTS = timeoutCTS.SafeRestart();
 076            currentDestination = newDestination;
 077            StartTimeoutCounter(timeoutCTS.Token).Forget();
 078        }
 79
 80        public void StopTimeout()
 81        {
 82            //Once the websocket has connected and the first fadeout has been done, its always LOAD_SCENE_TIMEOUT
 083            currentEvaluatedTimeout = LOAD_SCENE_TIMEOUT;
 84
 085            view.HideSceneTimeout();
 086            timeoutCTS.SafeCancelAndDispose();
 087        }
 88
 89        private void ExitClicked()
 90        {
 091            Utils.QuitApplication();
 092        }
 93
 94        internal void GoBackHomeClicked()
 95        {
 096            WebInterface.SendChatMessage(new ChatMessage
 97            {
 98                messageType = ChatMessage.Type.NONE,
 99                recipient = string.Empty,
 100                body = "/goto home",
 101            });
 0102            goHomeRequested = true;
 0103            view.HideSceneTimeout();
 0104        }
 105
 106        public void Dispose()
 107        {
 0108            timeoutCTS?.SafeCancelAndDispose();
 0109            view.Dispose();
 0110        }
 111    }
 112}