< Summary

Class:NativeBridgeCommunication
Assembly:NativeBridgeCommunication
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/KernelCommunication/NativeBridgeCommunication/NativeBridgeCommunication.cs
Covered lines:80
Uncovered lines:14
Coverable lines:94
Total lines:376
Line coverage:85.1% (80 of 94)
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%110100%
SetSceneId(...)0%2100%
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 int currentSceneNumber;
 10    private static string currentTag;
 11
 12    private static IMessageQueueHandler queueHandler;
 13
 14    delegate void JS_Delegate_VI(int a);
 15
 16    delegate void JS_Delegate_VIS(int a, string b);
 17
 18    delegate void JS_Delegate_VSS(string a, string b);
 19
 20    delegate void JS_Delegate_VSSS(string a, string b, string c);
 21
 22    delegate void JS_Delegate_VS(string a);
 23
 24    delegate void JS_Delegate_Query(Protocol.QueryPayload a);
 25
 26    delegate void JS_Delegate_V();
 27
 528    public NativeBridgeCommunication(IMessageQueueHandler queueHandler)
 29    {
 530        NativeBridgeCommunication.queueHandler = queueHandler;
 31#if UNITY_WEBGL && !UNITY_EDITOR
 32        SetCallback_CreateEntity(CreateEntity);
 33        SetCallback_RemoveEntity(RemoveEntity);
 34        SetCallback_SceneReady(SceneReady);
 35
 36        SetCallback_SetEntityId(SetEntityId);
 37        // @deprecated use SetSceneNumber
 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                sceneNumber = currentSceneNumber
 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))]
 12254    internal static void SetEntityId(string id) { currentEntityId = id; }
 255
 256    // @deprecated use SetSceneNumber
 257    [MonoPInvokeCallback(typeof(JS_Delegate_VI))]
 0258    internal static void SetSceneId(string _) { }
 259
 260    [MonoPInvokeCallback(typeof(JS_Delegate_VI))]
 10261    internal static void SetSceneNumber(int sceneNumber) { currentSceneNumber = sceneNumber; }
 262
 263    [MonoPInvokeCallback(typeof(JS_Delegate_VS))]
 10264    internal static void SetTag(string id) { currentTag = id; }
 265
 266    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 267    internal static void CreateEntity()
 268    {
 4269        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 270
 4271        Protocol.CreateEntity payload =
 272            new Protocol.CreateEntity
 273            {
 274                entityId = currentEntityId
 275            };
 276
 4277        queuedMessage.payload = payload;
 4278        queuedMessage.method = MessagingTypes.ENTITY_CREATE;
 279
 4280        queueHandler.EnqueueSceneMessage(queuedMessage);
 4281    }
 282
 283    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 284    internal static void RemoveEntity()
 285    {
 2286        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 2287        Protocol.RemoveEntity payload =
 288            new Protocol.RemoveEntity()
 289            {
 290                entityId = currentEntityId
 291            };
 292
 2293        queuedMessage.payload = payload;
 2294        queuedMessage.method = MessagingTypes.ENTITY_DESTROY;
 295
 2296        queueHandler.EnqueueSceneMessage(queuedMessage);
 2297    }
 298
 299    [MonoPInvokeCallback(typeof(JS_Delegate_V))]
 300    internal static void SceneReady()
 301    {
 1302        QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance();
 1303        queuedMessage.method = MessagingTypes.INIT_DONE;
 1304        queuedMessage.payload = new Protocol.SceneReady();
 305
 1306        queueHandler.EnqueueSceneMessage(queuedMessage);
 1307    }
 308
 309    internal static QueuedSceneMessage_Scene GetSceneMessageInstance()
 310    {
 15311        var sceneMessagesPool = queueHandler.sceneMessagesPool;
 312
 15313        if (!sceneMessagesPool.TryDequeue(out QueuedSceneMessage_Scene message))
 314        {
 15315            message = new QueuedSceneMessage_Scene();
 316        }
 317
 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    // @deprecated use SetSceneNumber
 338    [DllImport("__Internal")]
 339    private static extern void SetCallback_SetSceneId(JS_Delegate_VS callback);
 340
 341    [DllImport("__Internal")]
 342    private static extern void SetCallback_SetSceneNumber(JS_Delegate_VI callback);
 343
 344    [DllImport("__Internal")]
 345    private static extern void SetCallback_SetEntityParent(JS_Delegate_VS callback);
 346
 347    [DllImport("__Internal")]
 348    private static extern void SetCallback_EntityComponentCreateOrUpdate(JS_Delegate_VIS callback);
 349
 350    [DllImport("__Internal")]
 351    private static extern void SetCallback_SharedComponentAttach(JS_Delegate_VSS callback);
 352
 353    [DllImport("__Internal")]
 354    private static extern void SetCallback_EntityComponentDestroy(JS_Delegate_VS callback);
 355
 356    [DllImport("__Internal")]
 357    private static extern void SetCallback_OpenExternalUrl(JS_Delegate_VS callback);
 358
 359    [DllImport("__Internal")]
 360    private static extern void SetCallback_OpenNftDialog(JS_Delegate_VSSS callback);
 361
 362    [DllImport("__Internal")]
 363    private static extern void SetCallback_SharedComponentUpdate(JS_Delegate_VSS callback);
 364
 365    [DllImport("__Internal")]
 366    private static extern void SetCallback_SharedComponentDispose(JS_Delegate_VS callback);
 367
 368    [DllImport("__Internal")]
 369    private static extern void SetCallback_SharedComponentCreate(JS_Delegate_VIS callback);
 370
 371    [DllImport("__Internal")]
 372    private static extern void SetCallback_SetTag(JS_Delegate_VS callback);
 373
 374    [DllImport("__Internal")]
 375    private static extern void SetCallback_Query(JS_Delegate_Query callback);
 376}