< Summary

Class:DCLWebSocketService
Assembly:WebSocketCommunication
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/WebSocketCommunication/DCLWebSocketService.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:80
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SendMessageToWeb(...)0%12300%
ToString()0%2100%
OnMessage(...)0%6200%
OnError(...)0%2100%
OnClose(...)0%2100%
OnOpen()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/WebSocketCommunication/DCLWebSocketService.cs

#LineLine coverage
 1using System;
 2using DCL.Interface;
 3using System.Collections.Generic;
 4using System.Net;
 5using System.Net.NetworkInformation;
 6using System.Threading;
 7using DCL;
 8using UnityEditor;
 9using UnityEngine;
 10using WebSocketSharp;
 11using WebSocketSharp.Server;
 12
 13public class DCLWebSocketService : WebSocketBehavior
 14{
 15    public static bool VERBOSE = false;
 16
 17    private void SendMessageToWeb(string type, string message)
 18    {
 19#if (UNITY_EDITOR || UNITY_STANDALONE)
 020        var x = new Message()
 21        {
 22            type = type,
 23            payload = message
 24        };
 25
 026        if (ConnectionState == WebSocketState.Open)
 27        {
 028            Send(Newtonsoft.Json.JsonConvert.SerializeObject(x));
 29
 030            if (VERBOSE)
 31            {
 032                Debug.Log("SendMessageToWeb: " + type);
 33            }
 34        }
 35#endif
 036    }
 37
 38    public class Message
 39    {
 40        public string type;
 41        public string payload;
 42
 043        public override string ToString() { return string.Format("type = {0}... payload = {1}...", type, payload); }
 44    }
 45
 46    protected override void OnMessage(MessageEventArgs e)
 47    {
 048        base.OnMessage(e);
 49
 050        lock (WebSocketCommunication.queuedMessages)
 51        {
 052            Message finalMessage = JsonUtility.FromJson<Message>(e.Data);
 53
 054            WebSocketCommunication.queuedMessages.Enqueue(finalMessage);
 055            WebSocketCommunication.queuedMessagesDirty = true;
 056        }
 057    }
 58
 59    protected override void OnError(ErrorEventArgs e)
 60    {
 061        Debug.LogError(e.Message);
 062        base.OnError(e);
 063    }
 64
 65    protected override void OnClose(CloseEventArgs e)
 66    {
 067        base.OnClose(e);
 068        WebInterface.OnMessageFromEngine -= SendMessageToWeb;
 069        DataStore.i.wsCommunication.communicationEstablished.Set(false);
 070    }
 71
 72    protected override void OnOpen()
 73    {
 074        Debug.Log("WebSocket Communication Established");
 075        base.OnOpen();
 76
 077        WebInterface.OnMessageFromEngine += SendMessageToWeb;
 078        DataStore.i.wsCommunication.communicationEstablished.Set(true);
 079    }
 80}