Esempio n. 1
0
 public ChatConnector(int userId, int channelId, ICarl callback)
 {
     m_channelId = channelId;
     m_userId    = userId;
     m_callback  = callback;
     m_rand      = new Random(DateTime.Now.Millisecond);
 }
Esempio n. 2
0
        public Firehose(ICarl callback)
        {
            Random rand = new Random(DateTime.Now.Millisecond);

            m_uniqueId = rand.Next();
            m_callback = callback;
        }
Esempio n. 3
0
 public CommandDan(ICarl commandCallback, IFirehose firehose)
     : base(firehose)
 {
     m_client.DefaultRequestHeaders.Add("Client-ID", "Karl");
     m_commandCallback = commandCallback;
     m_firehose.SubChatMessages(this);
 }
Esempio n. 4
0
 public CreeperCarl(ICarl carl)
 {
     s_instance    = this;
     m_carl        = carl;
     m_userChecker = new Thread(ChannelUserCheckerThread);
     m_userChecker.IsBackground = false;
     m_userChecker.Start();
 }
Esempio n. 5
0
        private void HandleUserActivity(JObject jObject)
        {
            //            {
            //                {
            //                    "type": "event",
            //  "event": "UserJoin",
            //  "data": {
            //                        "originatingChannel": 160788,
            //    "username": "******",
            //    "roles": [
            //      "VerifiedPartner",
            //      "Pro",
            //      "User"
            //    ],
            //    "id": 756604
            //  }
            //}}

            bool isJoin = jObject["event"].Value <string>().Equals("UserJoin");

            JToken dataObj = jObject["data"];

            if (dataObj != null)
            {
                JToken userIdValue = dataObj["id"];
                if (userIdValue == null)
                {
                    return;
                }
                JToken channelValue = dataObj["originatingChannel"];
                if (channelValue == null)
                {
                    return;
                }

                // Filter out any messages that aren't from this channel. This will happen when people co stream.
                // The message will be picked up by another socket.
                int channelId = channelValue.Value <int>();
                if (channelId != m_channelId)
                {
                    return;
                }

                ICarl callback = m_callback;
                if (callback != null)
                {
                    callback.OnUserActivity(new UserActivity()
                    {
                        ChannelId = channelValue.Value <int>(),
                        IsJoin    = isJoin,
                        UserId    = userIdValue.Value <int>(),
                    });
                }
            }
        }
Esempio n. 6
0
        public async Task Disconnect()
        {
            UpdateStatus(ChatState.Disconnected, false);
            SimpleWebySocket ws = m_ws;

            if (ws != null)
            {
                await ws.Disconnect();
            }
            m_callback = null;
        }
Esempio n. 7
0
        private void HandleChatMessage(JObject jObject)
        {
            // { "type":"event","event":"ChatMessage","data":{ "channel":26685532,"id":"7d98a800-8ec8-11e8-9beb-85ac1e129a1f",
            //   "user_name":"jo1e","user_id":48924287,"user_roles":["Mod","User"],"user_level":21,
            //   "user_avatar":"https://uploads.mixer.com/avatar/46c0tc85-48924287.jpg",
            //   "message":{"message":[{"type":"text","data":"","text":""},
            //      { "text":"@GodsofAeon","type":"tag","username":"******","id":52198890},
            //      { "type":"text","data":" There's a lot of tutorials online to follow on how to get started and setting it up overall. ","text":" There's a lot of tutorials online to follow on how to get started and setting it up overall. "}],"meta":{}}}}

            ChatMessage msg = new ChatMessage();

            JToken dataObj = jObject["data"];

            if (dataObj != null)
            {
                JToken channelValue = dataObj["channel"];
                if (channelValue != null)
                {
                    msg.ChannelId = channelValue.Value <int>();
                }

                // Filter out any messages that aren't from this channel. This will happen when people co stream.
                // The message will be picked up by another socket.
                if (msg.ChannelId != m_channelId)
                {
                    return;
                }

                JToken messageVal = dataObj["message"];
                if (messageVal != null)
                {
                    msg.Text = String.Empty;
                    JToken msgVal = messageVal["message"];
                    foreach (var child in msgVal.Children())
                    {
                        JToken text = child["text"];
                        if (text != null)
                        {
                            msg.Text += text.Value <string>();
                        }
                    }
                }
                JToken metaVal = messageVal["meta"];
                if (metaVal != null)
                {
                    msg.IsWhisper = (metaVal["whisper"] != null);
                }
                JToken userNameValue = dataObj["user_name"];
                if (userNameValue != null)
                {
                    msg.UserName = userNameValue.Value <string>();
                }
                JToken userIdValue = dataObj["user_id"];
                if (userIdValue != null)
                {
                    msg.UserId = userIdValue.Value <int>();
                }

                // Validate we got everything.
                if (msg.UserId == 0 || msg.UserName == null || msg.Text == null || msg.ChannelId == 0)
                {
                    return;
                }

                // Fire off the message
                ICarl callback = m_callback;
                if (callback != null)
                {
                    callback.OnChatMessage(msg);
                }
            }
        }