< 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:23
Coverable lines:23
Total lines:72
Line coverage:0% (0 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SendMessageToWeb(...)0%6200%
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 DCL;
 7using UnityEditor;
 8using UnityEngine;
 9using WebSocketSharp;
 10using WebSocketSharp.Server;
 11
 12public class DCLWebSocketService : WebSocketBehavior
 13{
 14    public static bool VERBOSE = false;
 15
 16    private void SendMessageToWeb(string type, string message)
 17    {
 18#if (UNITY_EDITOR || UNITY_STANDALONE)
 019        var x = new Message()
 20        {
 21            type = type,
 22            payload = message
 23        };
 024        Send(Newtonsoft.Json.JsonConvert.SerializeObject(x));
 025        if (VERBOSE)
 26        {
 027            Debug.Log("SendMessageToWeb: " + type);
 28        }
 29#endif
 030    }
 31
 32    public class Message
 33    {
 34        public string type;
 35        public string payload;
 36
 037        public override string ToString() { return string.Format("type = {0}... payload = {1}...", type, payload); }
 38    }
 39
 40    protected override void OnMessage(MessageEventArgs e)
 41    {
 042        base.OnMessage(e);
 43
 044        lock (WebSocketCommunication.queuedMessages)
 45        {
 46            Message finalMessage;
 047            finalMessage = JsonUtility.FromJson<Message>(e.Data);
 48
 049            WebSocketCommunication.queuedMessages.Enqueue(finalMessage);
 050            WebSocketCommunication.queuedMessagesDirty = true;
 051        }
 052    }
 53
 054    protected override void OnError(ErrorEventArgs e) { base.OnError(e); }
 55
 56    protected override void OnClose(CloseEventArgs e)
 57    {
 058        base.OnClose(e);
 059        WebInterface.OnMessageFromEngine -= SendMessageToWeb;
 060    }
 61
 62    protected override void OnOpen()
 63    {
 064        base.OnOpen();
 065        WebInterface.OnMessageFromEngine += SendMessageToWeb;
 66
 067        DataStore.i.wsCommunication.communicationEstablished.Set(true);
 68
 069        var callFromMainThread = new Action(WebInterface.SendSystemInfoReport); // `WebInterface.SendSystemInfoReport` c
 070        callFromMainThread.Invoke();
 071    }
 72}