Пример #1
0
        public override void Parse()
        {
            base.Parse();

            if (ChannelName.Contains("#"))
            {
                Type = MessageType.ChannelMessage;
            }
            else
            {
                // todo check if there need user message
                Type        = MessageType.UserMessage;
                ChannelName = null;
                NickName    = _cmdParams[0];
            }
            Message = _longParam;
        }
Пример #2
0
        public override void Join(Action <IChatChannel> callback, string channel)
        {
            ChannelName = "#" + channel.Replace("#", "");

            if (ChannelName.Contains("@"))
            {
                return;
            }

            string sid = String.Empty;

            using (WebClientBase webClient = new WebClientBase())
            {
                webClient.Cookies = (Chat as ConnectcastChat).LoginWebClient.Cookies;
                channelToken      = this.With(x => webClient.Download(String.Format("http://connectcast.tv/chat/{0}", ChannelName.Replace("#", ""))))
                                    .With(x => Re.GetSubString(x, "token[^']*'(.*?)'"));

                sid = this.With(x => webClient.Download(
                                    String.Format("https://chat.connectcast.tv:3000/socket.io/?EIO=3&transport=polling&t=", Time.UnixTimestamp())))
                      .With(x => Re.GetSubString(x, @"""sid"":""(.*?)"""));

                if (String.IsNullOrWhiteSpace(channelToken) ||
                    channelToken.Equals("NOTOKEN", StringComparison.InvariantCultureIgnoreCase))
                {
                    channelToken = "NOTOKEN";
                }
                else
                {
                    Chat.Status.IsLoggedIn = true;
                }
            }

            if (String.IsNullOrWhiteSpace(sid) && LeaveCallback != null)
            {
                LeaveCallback(this);
                return;
            }


            webSocket = new WebSocketBase();
            webSocket.PingInterval = 0;

            JoinCallback = callback;

            webSocket.DisconnectHandler = () =>
            {
                if (pingTimer != null)
                {
                    pingTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                Leave();
            };

            webSocket.ReceiveMessageHandler = ReadRawMessage;

            webSocket.Path     = String.Format("/socket.io/?EIO=3&transport=websocket&sid={0}", sid);
            webSocket.Port     = "3000";
            webSocket.IsSecure = true;
            webSocket.Origin   = "http://connectcast.tv";
            webSocket.Cookies  = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("io", sid)
            };
            webSocket.Host           = "chat.connectcast.tv";
            webSocket.ConnectHandler = () =>
            {
                if (pingTimer != null)
                {
                    pingTimer.Change(PING_INTERVAL, PING_INTERVAL);
                }

                if (disconnectTimer != null)
                {
                    disconnectTimer.Change(PING_INTERVAL * 2, Timeout.Infinite);
                }

                webSocket.Send("2probe");
            };
            SetupStatsWatcher();
            webSocket.Connect();
        }