< Summary

Class:NativeBridgeCommunication
Assembly:NativeBridgeCommunication
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/NativeBridgeCommunication/NativeBridgeCommunication.cs
Covered lines:81
Uncovered lines:14
Coverable lines:95
Total lines:375
Line coverage:85.2% (81 of 95)
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%
SetSceneNumber(...)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 int currentSceneNumber;
 11    private static string currentTag;
 12
 13    private static IMessageQueueHandler queueHandler;
 14
 15    delegate void JS_Delegate_VI(int a);
 16
 17    delegate void JS_Delegate_VIS(int a, string b);
 18
 19    delegate void JS_Delegate_VSS(string a, string b);
 20
 21    delegate void JS_Delegate_VSSS(string a, string b, string c);
 22
 23    delegate void JS_Delegate_VS(string a);
 24
 25    delegate void JS_Delegate_Query(Protocol.QueryPayload a);
 26
 27    delegate void JS_Delegate_V();
 28
 529    public NativeBridgeCommunication(IMessageQueueHandler queueHandler)
 30    {
 531        NativeBridgeCommunication.queueHandler = queueHandler;
 32#if UNITY_WEBGL && !UNITY_EDITOR
 33        SetCallback_CreateEntity(CreateEntity);
 34        SetCallback_RemoveEntity(RemoveEntity);
 35        SetCallback_SceneReady(SceneReady);
 36
 37        SetCallback_SetEntityId(SetEntityId);
 38        SetCallback_SetSceneId(SetSceneId);
 39        SetCallback_SetSceneNumber(SetSceneNumber);
 40        SetCallback_SetTag(SetTag);
 41
 42        SetCallback_SetEntityParent(SetEntityParent);
 43
 44        SetCallback_EntityComponentCreateOrUpdate(EntityComponentCreateOrUpdate);
 45        SetCallback_EntityComponentDestroy(EntityComponentDestroy);
 46
 47        SetCallback_SharedComponentCreate(SharedComponentCreate);
 48        SetCallback_SharedComponentAttach(SharedComponentAttach);
 49        SetCallback_SharedComponentUpdate(SharedComponentUpdate);
 50        SetCallback_SharedComponentDispose(SharedComponentDispose);
 51
 52        SetCallback_OpenExternalUrl(OpenExternalUrl);
 53        SetCallback_OpenNftDialog(OpenNftDialog);
 54
 55        SetCallback_Query(Query);
 56#endif
 557    }
 58    public void Dispose()
 59    {
 60
 061    }
 62
 63    [MonoPInvokeCallback(typeof(JS_Delegate_VSSS))]
 64    internal static void OpenNftDialog(string contactAddress, string comment, string tokenId)
 65    {
 066        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 67
 068        Protocol.OpenNftDialog payload = new Protocol.OpenNftDialog
 69        {
 70            contactAddress = contactAddress,
 71            comment = comment,
 72            tokenId = tokenId
 73        };
 74
 075        queuedMessage.payload = payload;
 076        queuedMessage.method = MessagingTypes.OPEN_NFT_DIALOG;
 77
 078        queueHandler.EnqueueSceneMessage(queuedMessage);
 079    }
 80
 81    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 82    internal static void OpenExternalUrl(string url)
 83    {
 084        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 85
 086        Protocol.OpenExternalUrl payload = new Protocol.OpenExternalUrl
 87        {
 88            url = url
 89        };
 90
 091        queuedMessage.payload = payload;
 092        queuedMessage.method = MessagingTypes.OPEN_EXTERNAL_URL;
 93
 094        queueHandler.EnqueueSceneMessage(queuedMessage);
 095    }
 96
 97    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 98    internal static void EntityComponentDestroy(string name)
 99    {
 1100        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 101
 1102        Protocol.EntityComponentDestroy payload = new Protocol.EntityComponentDestroy
 103        {
 104            entityId = currentEntityId,
 105            name = name
 106        };
 107
 1108        queuedMessage.payload = payload;
 1109        queuedMessage.method = MessagingTypes.ENTITY_COMPONENT_DESTROY;
 110
 1111        queueHandler.EnqueueSceneMessage(queuedMessage);
 1112    }
 113
 114    [MonoPInvokeCallback(typeof(JS_Delegate_VSS))]
 115    internal static void SharedComponentAttach(string id, string name)
 116    {
 1117        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 118
 1119        Protocol.SharedComponentAttach payload = new Protocol.SharedComponentAttach
 120        {
 121            entityId = currentEntityId,
 122            id = id,
 123            name = name
 124        };
 125
 1126        queuedMessage.payload = payload;
 1127        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_ATTACH;
 128
 1129        queueHandler.EnqueueSceneMessage(queuedMessage);
 1130    }
 131
 132    [MonoPInvokeCallback(typeof(JS_Delegate_Query))]
 133    internal static void Query(Protocol.QueryPayload payload)
 134    {
 1135        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 136
 1137        string queryId = Convert.ToString(payload.raycastPayload.id);
 138
 1139        RaycastType raycastType = (RaycastType) payload.raycastPayload.raycastType;
 140
 1141        Ray ray = new Ray()
 142        {
 143            origin = payload.raycastPayload.origin,
 144            direction = payload.raycastPayload.direction,
 145            distance = payload.raycastPayload.distance
 146        };
 147
 1148        queuedMessage.method = MessagingTypes.QUERY;
 1149        queuedMessage.payload = new QueryMessage()
 150        {
 151            payload = new RaycastQuery()
 152            {
 153                id = queryId,
 154                raycastType = raycastType,
 155                ray = ray,
 156                sceneId = currentSceneId
 157            }
 158        };
 159
 1160        queueHandler.EnqueueSceneMessage(queuedMessage);
 1161    }
 162
 163    [MonoPInvokeCallback(typeof(JS_Delegate_VSS))]
 164    internal static void SharedComponentUpdate(string id, string json)
 165    {
 1166        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 167
 1168        Protocol.SharedComponentUpdate payload =
 169            new Protocol.SharedComponentUpdate
 170            {
 171                componentId = id,
 172                json = json
 173            };
 174
 1175        queuedMessage.payload = payload;
 1176        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_UPDATE;
 177
 1178        queueHandler.EnqueueSceneMessage(queuedMessage);
 1179    }
 180
 181    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 182    internal static void SharedComponentDispose(string id)
 183    {
 1184        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 185
 1186        Protocol.SharedComponentDispose payload =
 187            new Protocol.SharedComponentDispose
 188            {
 189                id = id
 190            };
 191
 1192        queuedMessage.payload = payload;
 1193        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_DISPOSE;
 194
 1195        queueHandler.EnqueueSceneMessage(queuedMessage);
 1196    }
 197
 198    [MonoPInvokeCallback(typeof(JS_Delegate_VIS))]
 199    internal static void SharedComponentCreate(int classId, string id)
 200    {
 1201        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 202
 1203        Protocol.SharedComponentCreate payload =
 204            new Protocol.SharedComponentCreate
 205            {
 206                id = id,
 207                classId = classId
 208            };
 209
 1210        queuedMessage.payload = payload;
 1211        queuedMessage.method = MessagingTypes.SHARED_COMPONENT_CREATE;
 212
 1213        queueHandler.EnqueueSceneMessage(queuedMessage);
 1214    }
 215
 216    [MonoPInvokeCallback(typeof(JS_Delegate_VIS))]
 217    internal static void EntityComponentCreateOrUpdate(int classId, string json)
 218    {
 1219        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 220
 1221        Protocol.EntityComponentCreateOrUpdate payload =
 222            new Protocol.EntityComponentCreateOrUpdate
 223            {
 224                entityId = currentEntityId,
 225                classId = classId,
 226                json = json
 227            };
 228
 1229        queuedMessage.payload = payload;
 1230        queuedMessage.method = MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE;
 231
 1232        queueHandler.EnqueueSceneMessage(queuedMessage);
 1233    }
 234
 235    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 236    internal static void SetEntityParent(string parentId)
 237    {
 1238        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 239
 1240        Protocol.SetEntityParent payload =
 241            new Protocol.SetEntityParent
 242            {
 243                entityId = currentEntityId,
 244                parentId = parentId
 245            };
 246
 1247        queuedMessage.payload = payload;
 1248        queuedMessage.method = MessagingTypes.ENTITY_REPARENT;
 249
 1250        queueHandler.EnqueueSceneMessage(queuedMessage);
 1251    }
 252
 253    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 0254    internal static void SetEntityId(string id) { currentEntityId = id; }
 255
 256    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 10257    internal static void SetSceneId(string id) { currentSceneId = id; }
 258
 259    [MonoPInvokeCallback(typeof(JS_Delegate_VI))]
 10260    internal static void SetSceneNumber(int sceneNumber) { currentSceneNumber = sceneNumber; }
 261
 262    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 10263    internal static void SetTag(string id) { currentTag = id; }
 264
 265    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 266    internal static void CreateEntity()
 267    {
 4268        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 269
 4270        Protocol.CreateEntity payload =
 271            new Protocol.CreateEntity
 272            {
 273                entityId = currentEntityId
 274            };
 275
 4276        queuedMessage.payload = payload;
 4277        queuedMessage.method = MessagingTypes.ENTITY_CREATE;
 278
 4279        queueHandler.EnqueueSceneMessage(queuedMessage);
 4280    }
 281
 282    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 283    internal static void RemoveEntity()
 284    {
 2285        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 2286        Protocol.RemoveEntity payload =
 287            new Protocol.RemoveEntity()
 288            {
 289                entityId = currentEntityId
 290            };
 291
 2292        queuedMessage.payload = payload;
 2293        queuedMessage.method = MessagingTypes.ENTITY_DESTROY;
 294
 2295        queueHandler.EnqueueSceneMessage(queuedMessage);
 2296    }
 297
 298    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 299    internal static void SceneReady()
 300    {
 1301        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 1302        queuedMessage.method = MessagingTypes.INIT_DONE;
 1303        queuedMessage.payload = new Protocol.SceneReady();
 304
 1305        queueHandler.EnqueueSceneMessage(queuedMessage);
 1306    }
 307
 308    internal static QueuedSceneMessage_Scene GetSceneMessageInstance()
 309    {
 15310        var sceneMessagesPool = queueHandler.sceneMessagesPool;
 311
 15312        if (!sceneMessagesPool.TryDequeue(out QueuedSceneMessage_Scene message))
 313        {
 15314            message = new QueuedSceneMessage_Scene();
 315        }
 316
 15317        message.sceneId = currentSceneId;
 15318        message.sceneNumber = currentSceneNumber;
 15319        message.tag = currentTag;
 15320        message.type = QueuedSceneMessage.Type.SCENE_MESSAGE;
 321
 15322        return message;
 323    }
 324
 325    [DllImport("__Internal")]
 326    private static extern void SetCallback_CreateEntity(JS_Delegate_V callback);
 327
 328    [DllImport("__Internal")]
 329    private static extern void SetCallback_RemoveEntity(JS_Delegate_V callback);
 330
 331    [DllImport("__Internal")]
 332    private static extern void SetCallback_SceneReady(JS_Delegate_V callback);
 333
 334    [DllImport("__Internal")]
 335    private static extern void SetCallback_SetEntityId(JS_Delegate_VS callback);
 336
 337    [DllImport("__Internal")]
 338    private static extern void SetCallback_SetSceneId(JS_Delegate_VS callback);
 339
 340    [DllImport("__Internal")]
 341    private static extern void SetCallback_SetSceneNumber(JS_Delegate_VI callback);
 342
 343    [DllImport("__Internal")]
 344    private static extern void SetCallback_SetEntityParent(JS_Delegate_VS callback);
 345
 346    [DllImport("__Internal")]
 347    private static extern void SetCallback_EntityComponentCreateOrUpdate(JS_Delegate_VIS callback);
 348
 349    [DllImport("__Internal")]
 350    private static extern void SetCallback_SharedComponentAttach(JS_Delegate_VSS callback);
 351
 352    [DllImport("__Internal")]
 353    private static extern void SetCallback_EntityComponentDestroy(JS_Delegate_VS callback);
 354
 355    [DllImport("__Internal")]
 356    private static extern void SetCallback_OpenExternalUrl(JS_Delegate_VS callback);
 357
 358    [DllImport("__Internal")]
 359    private static extern void SetCallback_OpenNftDialog(JS_Delegate_VSSS callback);
 360
 361    [DllImport("__Internal")]
 362    private static extern void SetCallback_SharedComponentUpdate(JS_Delegate_VSS callback);
 363
 364    [DllImport("__Internal")]
 365    private static extern void SetCallback_SharedComponentDispose(JS_Delegate_VS callback);
 366
 367    [DllImport("__Internal")]
 368    private static extern void SetCallback_SharedComponentCreate(JS_Delegate_VIS callback);
 369
 370    [DllImport("__Internal")]
 371    private static extern void SetCallback_SetTag(JS_Delegate_VS callback);
 372
 373    [DllImport("__Internal")]
 374    private static extern void SetCallback_Query(JS_Delegate_Query callback);
 375}