Beispiel #1
0
 private ChatMessage FormatUserChatMessage(ChatMessageDTO chatDto)
 {
     if (_userMap.ContainsKey(chatDto.user_id))
     {
         UserInfo user = _userMap[chatDto.user_id];
         return(new ChatMessage {
             Username = user.name, Body = chatDto.body
         });
     }
     return(new ChatMessage {
         Username = chatDto.user_id.ToString(), Body = chatDto.body
     });
 }
Beispiel #2
0
        private async void StartStreaming()
        {
            string         url     = string.Format("{0}streaming.campfirenow.com/room/{1}/live.json", Scheme, _roomId);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "GET";
            request.Accept = "application/json";
            request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", EncodedAuthToken);

            HttpWebResponse response = null;

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
            }

            LogHttpWebResponse("Streaming", response);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());

                while (true)
                {
                    string line = await reader.ReadLineAsync();

                    ChatMessageDTO chatMessage = await ParseChatMessage(line);

                    if (chatMessage != null)
                    {
                        //Ensure we have the details for this user
                        GetUserInfo(chatMessage.user_id);
                        DataEmitted(FormatUserChatMessage(chatMessage));
                    }
                }
            }
        }
Beispiel #3
0
 private ChatMessage FormatUserChatMessage(ChatMessageDTO chatDto)
 {
     if (_userMap.ContainsKey(chatDto.user_id))
     {
         UserInfo user = _userMap[chatDto.user_id];
         return new ChatMessage { Username = user.name, Body = chatDto.body };
     }
     return new ChatMessage { Username = chatDto.user_id.ToString(), Body = chatDto.body };
 }