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>
        /// Emits an event on the sever asyn
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task <Response <T> > EmitAsync <T>(string eventName, object data)
        {
            m_log.Information("Emit {EventName} {@Data}", eventName, data);

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

            return(await SendRequestAsync <T>(request));
        }
Exemplo n.º 3
0
        internal async Task SubscribeChannelAsync(string channelName, CancellationToken cancellation)
        {
            m_log.Information("SubscribeChannel {ChannelName}", channelName);

            SocketRequest request = new SocketRequest(GetNextCallId())
            {
                EventName = "#subscribe",
                Data      = new
                {
                    ChannelName = channelName,
                }
            };


            await SendRequestAsync <object>(request);
        }
Exemplo n.º 4
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.º 5
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);
        });