Repository navigation
Expand file tree
/
Copy pathStaticClass.cs
More file actions
58 lines (40 loc) · 1.85 KB
/
Copy pathStaticClass.cs
File metadata and controls
58 lines (40 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace BlazorWebSocketHelper
{
public static class StaticClass
{
public static List<WebSocketHelper> webSocketHelpers_List = new List<WebSocketHelper>();
public static IJSUnmarshalledRuntime _jsUnmarshalledRuntime;
//1/21/2019 after suchiman's recomendation solved problem how to get byte array from js in dotnet
//https://github.com/aspnet/AspNetCore/blob/master/src/Components/Blazor/Blazor/src/Http/WebAssemblyHttpMessageHandler.cs
//https://github.com/aspnet/AspNetCore/blob/master/src/Components/Browser.JS/src/Services/Http.ts
//https://github.com/aspnet/AspNetCore/blob/master/src/Components/Browser.JS/src/Platform/Mono/MonoPlatform.ts
//1/23/2019 mono unmarshaled fixed fast transfer from dotnet to js
//test websocket server
//http://demos.kaazing.com/echo/
//https://www.websocket.org/echo.html
[JSInvokable]
public static void AllocateArray(int length, string a)
{
byte[] b = new byte[length];
_jsUnmarshalledRuntime.InvokeUnmarshalled<byte[], bool>("BwsJsFunctions.GetBinaryData", b);
HandleMessageBinary(b, a);
}
[JSInvokable]
public static void HandleMessageBinary(byte[] par_message, string wsID)
{
if (webSocketHelpers_List.Any())
{
if (webSocketHelpers_List.Any(x => x._id.Equals(wsID, StringComparison.InvariantCultureIgnoreCase)))
{
webSocketHelpers_List.Single(x => x._id.Equals(wsID, StringComparison.InvariantCultureIgnoreCase)).InvokeOnMessageBinary(par_message);
}
}
}
}
}