コード例 #1
0
ファイル: Carl.cs プロジェクト: QuinnDamerell/mixer-carl
        public async Task <bool> SendWhisper(int channelId, string targetUserName, string message)
        {
            ChatConnector connector = GetChatConnector(channelId);

            if (connector == null)
            {
                return(false);
            }
            return(await connector.SendWhisper(targetUserName, message));
        }
コード例 #2
0
ファイル: Carl.cs プロジェクト: QuinnDamerell/mixer-carl
        public async Task <bool> SendChatMessage(int channelId, string message)
        {
            ChatConnector connector = GetChatConnector(channelId);

            if (connector == null)
            {
                return(false);
            }
            return(await connector.SendChatMessage(message));
        }
コード例 #3
0
ファイル: Carl.cs プロジェクト: QuinnDamerell/mixer-carl
 private void Chat_OnChatWsStateChanged(ChatConnector sender, ChatState newState, bool wasError)
 {
     // If the socket closed removed the channel.
     if (newState == ChatState.Disconnected)
     {
         int channelId = sender.GetChannelId();
         var _ignored  = Task.Run(async() =>
         {
             Logger.Error($"Chat ws disconnected due to ws error for channel {channelId}");
             await RemoveChannel(channelId, "websocket error.");
         }).ConfigureAwait(false);
     }
 }
コード例 #4
0
ファイル: Carl.cs プロジェクト: QuinnDamerell/mixer-carl
        private async void WorkerThread()
        {
            while (true)
            {
                // Get a channel id to work on.
                int channelId = -1;
                lock (m_channelProcessQueue)
                {
                    foreach (KeyValuePair <int, bool> entry in m_channelProcessQueue)
                    {
                        // Skip already processing channel ids.
                        if (entry.Value)
                        {
                            continue;
                        }

                        // Claim this channel id.
                        channelId = entry.Key;
                        m_channelProcessQueue[channelId] = true;
                        break;
                    }
                }

                if (channelId == -1)
                {
                    // No work to do, sleep.
                    Thread.Sleep(100);
                    continue;
                }

                // We have a channel id we should connect, try to do it.
                ChatConnector conn = new ChatConnector(m_chatBotUserId, channelId, this);

                bool added = false;
                if ((await conn.Connect()))
                {
                    // We succeeded, add the connection to the channel.
                    lock (m_channelMap)
                    {
                        if (m_channelMap.ContainsKey(channelId))
                        {
                            m_channelMap[channelId].Chat = conn;
                            conn.OnChatWsStateChanged   += Chat_OnChatWsStateChanged;
                            added = true;
                        }
                    }
                }

                // If we failed to connect or didn't add the chat, disconnect.
                if (!added)
                {
                    await conn.Disconnect();
                }
                else
                {
                    OnChatConnectionChanged(channelId, ChatConnectionState.Connected);
                }

                // Remove the channel from the processing map.
                lock (m_channelProcessQueue)
                {
                    m_channelProcessQueue.Remove(channelId);
                }
            }
        }