< 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:24
Coverable lines:24
Total lines:74
Line coverage:0% (0 of 24)
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 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        };
 025        Send(Newtonsoft.Json.JsonConvert.SerializeObject(x));
 026        if (VERBOSE)
 27        {
 028            Debug.Log("SendMessageToWeb: " + type);
 29        }
 30#endif
 031    }
 32
 33    public class Message
 34    {
 35        public string type;
 36        public string payload;
 37
 038        public override string ToString() { return string.Format("type = {0}... payload = {1}...", type, payload); }
 39    }
 40
 41    protected override void OnMessage(MessageEventArgs e)
 42    {
 043        base.OnMessage(e);
 44
 045        lock (WebSocketCommunication.queuedMessages)
 46        {
 047            Message finalMessage = JsonUtility.FromJson<Message>(e.Data);
 48
 049            WebSocketCommunication.queuedMessages.Enqueue(finalMessage);
 050            WebSocketCommunication.queuedMessagesDirty = true;
 051        }
 052    }
 53
 54    protected override void OnError(ErrorEventArgs e)
 55    {
 056        Debug.LogError(e.Message);
 057        base.OnError(e);
 058    }
 59
 60    protected override void OnClose(CloseEventArgs e)
 61    {
 062        base.OnClose(e);
 063        WebInterface.OnMessageFromEngine -= SendMessageToWeb;
 064        DataStore.i.wsCommunication.communicationEstablished.Set(false);
 065    }
 66
 67    protected override void OnOpen()
 68    {
 069        base.OnOpen();
 70
 071        WebInterface.OnMessageFromEngine += SendMessageToWeb;
 072        DataStore.i.wsCommunication.communicationEstablished.Set(true);
 073    }
 74}