Exemplo n.º 1
0
        public void Emit(string eventName, object data)
        {
            m_log.Information("Emit {EventName} {@Data}", eventName, data);

            SocketRequest request = new SocketRequest(GetNextCallId())
            {
                Data      = data,
                EventName = eventName,
            };

            request.Send(m_socket);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enqueues a new result object and waits for the servers response
        /// </summary>
        private async Task <Response <T> > SendRequestAsync <T>(SocketRequest request)
        {
            TaskCompletionSource <JToken> result = new TaskCompletionSource <JToken>();

            m_pendingResponses.Add(request.CallId, result);

            request.Send(m_socket);

            JObject response = (JObject)await result.Task;

            int    responseId = response["rid"].ToObject <int>();
            bool   okay       = !response.ContainsKey("error");
            string error      = okay ? "" : response["error"]["message"].ToString();
            T      value      = okay ? response["data"].ToObject <T>() : default(T);

            return(new Response <T>(responseId, value, okay, error));
        }
Exemplo n.º 3
0
        private void OnSocketOpened(object sender, EventArgs e)
        => Task.Run(async() =>
        {
            m_log.Information("Socket Closed");
            m_nextCallId = 0;

            SocketRequest request = new SocketRequest(GetNextCallId())
            {
                EventName = "#handshake",
            };

            Response <Authentication> response = await SendRequestAsync <Authentication>(request);

            request.Send(m_socket);

            m_connectedCompletionSource.SetResult(response);
        });