< Summary

Class:NativeBridgeCommunication
Assembly:NativeBridgeCommunication
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/NativeBridgeCommunication/NativeBridgeCommunication.cs
Covered lines:79
Uncovered lines:14
Coverable lines:93
Total lines:364
Line coverage:84.9% (79 of 93)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NativeBridgeCommunication(...)0%110100%
Dispose()0%2100%
OpenNftDialog(...)0%2100%
OpenExternalUrl(...)0%2100%
EntityComponentDestroy(...)0%110100%
SharedComponentAttach(...)0%110100%
Query(...)0%110100%
SharedComponentUpdate(...)0%110100%
SharedComponentDispose(...)0%110100%
SharedComponentCreate(...)0%110100%
EntityComponentCreateOrUpdate(...)0%110100%
SetEntityParent(...)0%110100%
SetEntityId(...)0%2100%
SetSceneId(...)0%110100%
SetTag(...)0%110100%
CreateEntity()0%110100%
RemoveEntity()0%110100%
SceneReady()0%110100%
GetSceneMessageInstance()0%220100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Runtime.InteropServices;
 3using DCL;
 4using DCL.Models;
 5
 6public class NativeBridgeCommunication : IKernelCommunication
 7{
 8    private static string currentEntityId;
 9    private static string currentSceneId;
 10    private static string currentTag;
 11
 12    private static IMessageQueueHandler queueHandler;
 13
 14    delegate void JS_Delegate_VIS(int a, string b);
 15
 16    delegate void JS_Delegate_VSS(string a, string b);
 17
 18    delegate void JS_Delegate_VSSS(string a, string b, string c);
 19
 20    delegate void JS_Delegate_VS(string a);
 21
 22    delegate void JS_Delegate_Query(Protocol.QueryPayload a);
 23
 24    delegate void JS_Delegate_V();
 25
 526    public NativeBridgeCommunication(IMessageQueueHandler queueHandler)
 27    {
 528        NativeBridgeCommunication.queueHandler = queueHandler;
 29#if UNITY_WEBGL && !UNITY_EDITOR
 30        SetCallback_CreateEntity(CreateEntity);
 31        SetCallback_RemoveEntity(RemoveEntity);
 32        SetCallback_SceneReady(SceneReady);
 33
 34        SetCallback_SetEntityId(SetEntityId);
 35        SetCallback_SetSceneId(SetSceneId);
 36        SetCallback_SetTag(SetTag);
 37
 38        SetCallback_SetEntityParent(SetEntityParent);
 39
 40        SetCallback_EntityComponentCreateOrUpdate(EntityComponentCreateOrUpdate);
 41        SetCallback_EntityComponentDestroy(EntityComponentDestroy);
 42
 43        SetCallback_SharedComponentCreate(SharedComponentCreate);
 44        SetCallback_SharedComponentAttach(SharedComponentAttach);
 45        SetCallback_SharedComponentUpdate(SharedComponentUpdate);
 46        SetCallback_SharedComponentDispose(SharedComponentDispose);
 47
 48        SetCallback_OpenExternalUrl(OpenExternalUrl);
 49        SetCallback_OpenNftDialog(OpenNftDialog);
 50
 51        SetCallback_Query(Query);
 52#endif
 553    }
 54    public void Dispose()
 55    {
 56
 057    }
 58
 59    [MonoPInvokeCallback(typeof(JS_Delegate_VSSS))]
 60    internal static void OpenNftDialog(string contactAddress, string comment, string tokenId)
 61    {
 062        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 63
 064        Protocol.OpenNftDialog payload = new Protocol.OpenNftDialog
 65        {
 66            contactAddress = contactAddress,
 67            comment = comment,
 68            tokenId = tokenId
 69        };
 70
 071        queuedMessage.payload = payload;
 072        queuedMessage.method = MessagingTypes.OPEN_NFT_DIALOG;
 73
 074        queueHandler.EnqueueSceneMessage(queuedMessage);
 075    }
 76
 77    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 78    internal static void OpenExternalUrl(string url)
 79    {
 080        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 81
 082        Protocol.OpenExternalUrl payload = new Protocol.OpenExternalUrl
 83        {
 84            url = url
 85        };
 86
 087        queuedMessage.payload = payload;
 088        queuedMessage.method = MessagingTypes.OPEN_EXTERNAL_URL;
 89
 090        queueHandler.EnqueueSceneMessage(queuedMessage);
 091    }
 92
 93    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 94    internal static void EntityComponentDestroy(string name)
 95    {
 196        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 97
 198        Protocol.EntityComponentDestroy payload = new Protocol.EntityComponentDestroy
 99        {
 100            entityId = currentEntityId,
 101            name = name
 102        };
 103
 1104        queuedMessage.payload = payload;
 1105        queuedMessage.method = MessagingTypes.ENTITY_COMPONENT_DESTROY;
 106
 1107        queueHandler.EnqueueSceneMessage(queuedMessage);
 1108    }
 109
 110    [MonoPInvokeCallback(typeof(JS_Delegate_VSS))]
 111    internal static void SharedComponentAttach(string id, string name)
 112    {
 1113        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 114
 1115        Protocol.SharedComponentAttach payload = new Protocol.SharedComponentAttach
 116        {
 117            entityId = currentEntityId,
 118            id = id,
 119            name = name
 120        };
 121
 1122        queuedMessage.payload = payload;
 1123        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_ATTACH;
 124
 1125        queueHandler.EnqueueSceneMessage(queuedMessage);
 1126    }
 127
 128    [MonoPInvokeCallback(typeof(JS_Delegate_Query))]
 129    internal static void Query(Protocol.QueryPayload payload)
 130    {
 1131        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 132
 1133        string queryId = Convert.ToString(payload.raycastPayload.id);
 134
 1135        RaycastType raycastType = (RaycastType) payload.raycastPayload.raycastType;
 136
 1137        Ray ray = new Ray()
 138        {
 139            origin = payload.raycastPayload.origin,
 140            direction = payload.raycastPayload.direction,
 141            distance = payload.raycastPayload.distance
 142        };
 143
 1144        queuedMessage.method = MessagingTypes.QUERY;
 1145        queuedMessage.payload = new QueryMessage()
 146        {
 147            payload = new RaycastQuery()
 148            {
 149                id = queryId,
 150                raycastType = raycastType,
 151                ray = ray,
 152                sceneId = currentSceneId
 153            }
 154        };
 155
 1156        queueHandler.EnqueueSceneMessage(queuedMessage);
 1157    }
 158
 159    [MonoPInvokeCallback(typeof(JS_Delegate_VSS))]
 160    internal static void SharedComponentUpdate(string id, string json)
 161    {
 1162        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 163
 1164        Protocol.SharedComponentUpdate payload =
 165            new Protocol.SharedComponentUpdate
 166            {
 167                componentId = id,
 168                json = json
 169            };
 170
 1171        queuedMessage.payload = payload;
 1172        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_UPDATE;
 173
 1174        queueHandler.EnqueueSceneMessage(queuedMessage);
 1175    }
 176
 177    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 178    internal static void SharedComponentDispose(string id)
 179    {
 1180        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 181
 1182        Protocol.SharedComponentDispose payload =
 183            new Protocol.SharedComponentDispose
 184            {
 185                id = id
 186            };
 187
 1188        queuedMessage.payload = payload;
 1189        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_DISPOSE;
 190
 1191        queueHandler.EnqueueSceneMessage(queuedMessage);
 1192    }
 193
 194    [MonoPInvokeCallback(typeof(JS_Delegate_VIS))]
 195    internal static void SharedComponentCreate(int classId, string id)
 196    {
 1197        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 198
 1199        Protocol.SharedComponentCreate payload =
 200            new Protocol.SharedComponentCreate
 201            {
 202                id = id,
 203                classId = classId
 204            };
 205
 1206        queuedMessage.payload = payload;
 1207        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_CREATE;
 208
 1209        queueHandler.EnqueueSceneMessage(queuedMessage);
 1210    }
 211
 212    [MonoPInvokeCallback(typeof(JS_Delegate_VIS))]
 213    internal static void EntityComponentCreateOrUpdate(int classId, string json)
 214    {
 1215        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 216
 1217        Protocol.EntityComponentCreateOrUpdate payload =
 218            new Protocol.EntityComponentCreateOrUpdate
 219            {
 220                entityId = currentEntityId,
 221                classId = classId,
 222                json = json
 223            };
 224
 1225        queuedMessage.payload = payload;
 1226        queuedMessage.method = MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE;
 227
 1228        queueHandler.EnqueueSceneMessage(queuedMessage);
 1229    }
 230
 231    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 232    internal static void SetEntityParent(string parentId)
 233    {
 1234        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 235
 1236        Protocol.SetEntityParent payload =
 237            new Protocol.SetEntityParent
 238            {
 239                entityId = currentEntityId,
 240                parentId = parentId
 241            };
 242
 1243        queuedMessage.payload = payload;
 1244        queuedMessage.method = MessagingTypes.ENTITY_REPARENT;
 245
 1246        queueHandler.EnqueueSceneMessage(queuedMessage);
 1247    }
 248
 249    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 0250    internal static void SetEntityId(string id) { currentEntityId = id; }
 251
 252    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 10253    internal static void SetSceneId(string id) { currentSceneId = id; }
 254
 255    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 10256    internal static void SetTag(string id) { currentTag = id; }
 257
 258    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 259    internal static void CreateEntity()
 260    {
 4261        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 262
 4263        Protocol.CreateEntity payload =
 264            new Protocol.CreateEntity
 265            {
 266                entityId = currentEntityId
 267            };
 268
 4269        queuedMessage.payload = payload;
 4270        queuedMessage.method = MessagingTypes.ENTITY_CREATE;
 271
 4272        queueHandler.EnqueueSceneMessage(queuedMessage);
 4273    }
 274
 275    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 276    internal static void RemoveEntity()
 277    {
 2278        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 2279        Protocol.RemoveEntity payload =
 280            new Protocol.RemoveEntity()
 281            {
 282                entityId = currentEntityId
 283            };
 284
 2285        queuedMessage.payload = payload;
 2286        queuedMessage.method = MessagingTypes.ENTITY_DESTROY;
 287
 2288        queueHandler.EnqueueSceneMessage(queuedMessage);
 2289    }
 290
 291    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 292    internal static void SceneReady()
 293    {
 1294        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 1295        queuedMessage.method = MessagingTypes.INIT_DONE;
 1296        queuedMessage.payload = new Protocol.SceneReady();
 297
 1298        queueHandler.EnqueueSceneMessage(queuedMessage);
 1299    }
 300
 301    internal static QueuedSceneMessage_Scene GetSceneMessageInstance()
 302    {
 15303        var sceneMessagesPool = queueHandler.sceneMessagesPool;
 304
 15305        if (!sceneMessagesPool.TryDequeue(out QueuedSceneMessage_Scene message))
 306        {
 15307            message = new QueuedSceneMessage_Scene();
 308        }
 309
 15310        message.sceneId = currentSceneId;
 15311        message.tag = currentTag;
 15312        message.type = QueuedSceneMessage.Type.SCENE_MESSAGE;
 313
 15314        return message;
 315    }
 316
 317    [DllImport("__Internal")]
 318    private static extern void SetCallback_CreateEntity(JS_Delegate_V callback);
 319
 320    [DllImport("__Internal")]
 321    private static extern void SetCallback_RemoveEntity(JS_Delegate_V callback);
 322
 323    [DllImport("__Internal")]
 324    private static extern void SetCallback_SceneReady(JS_Delegate_V callback);
 325
 326    [DllImport("__Internal")]
 327    private static extern void SetCallback_SetEntityId(JS_Delegate_VS callback);
 328
 329    [DllImport("__Internal")]
 330    private static extern void SetCallback_SetSceneId(JS_Delegate_VS callback);
 331
 332    [DllImport("__Internal")]
 333    private static extern void SetCallback_SetEntityParent(JS_Delegate_VS callback);
 334
 335    [DllImport("__Internal")]
 336    private static extern void SetCallback_EntityComponentCreateOrUpdate(JS_Delegate_VIS callback);
 337
 338    [DllImport("__Internal")]
 339    private static extern void SetCallback_SharedComponentAttach(JS_Delegate_VSS callback);
 340
 341    [DllImport("__Internal")]
 342    private static extern void SetCallback_EntityComponentDestroy(JS_Delegate_VS callback);
 343
 344    [DllImport("__Internal")]
 345    private static extern void SetCallback_OpenExternalUrl(JS_Delegate_VS callback);
 346
 347    [DllImport("__Internal")]
 348    private static extern void SetCallback_OpenNftDialog(JS_Delegate_VSSS callback);
 349
 350    [DllImport("__Internal")]
 351    private static extern void SetCallback_SharedComponentUpdate(JS_Delegate_VSS callback);
 352
 353    [DllImport("__Internal")]
 354    private static extern void SetCallback_SharedComponentDispose(JS_Delegate_VS callback);
 355
 356    [DllImport("__Internal")]
 357    private static extern void SetCallback_SharedComponentCreate(JS_Delegate_VIS callback);
 358
 359    [DllImport("__Internal")]
 360    private static extern void SetCallback_SetTag(JS_Delegate_VS callback);
 361
 362    [DllImport("__Internal")]
 363    private static extern void SetCallback_Query(JS_Delegate_Query callback);
 364}