Ejemplo n.º 1
0
 private async Task SendDataToSocket <T>(string methodName, HubSocket socket, T data)
 {
     var hubData = new HubData()
     {
         Data       = data,
         MethodName = methodName,
         PromiseId  = -1
     };
     await socket.SendData(hubData);
 }
Ejemplo n.º 2
0
        public async Task AddSocket(WebSocket webSocket)
        {
            using var hubSocket = new HubSocket(Guid.NewGuid(), webSocket);

            hubSocketRepository.AddOrUpdate(hubSocket.ID, hubSocket);
            hubSocket.DataReceived += DataReceived;

            DataReceived(this, new HubSocketEventArgs()
            {
                Data = JsonConvert.SerializeObject(new HubData()
                {
                    MethodName = nameof(Hub.OnConnectedAsync)
                }),
                HubSocket = hubSocket
            });

            HubData hubSocketConnected = new HubData()
            {
                Data       = hubSocket.ID,
                MethodName = "HubSocketConnected"
            };
            await hubSocket.SendData(hubSocketConnected);

            await hubSocket.ListenLoop(); // infinite loop until socket closed.

            RemoveSocket(hubSocket.ID);

            DataReceived(this, new HubSocketEventArgs()
            {
                Data = JsonConvert.SerializeObject(new HubData()
                {
                    MethodName = nameof(Hub.OnDisconnectedAsync)
                }),
                HubSocket = hubSocket
            });
        }
Ejemplo n.º 3
0
 public HubSocketContext(HubSocket hubSocket)
 {
     HubSocket = hubSocket ?? throw new ArgumentNullException(nameof(hubSocket));
 }