Exemple #1
0
 private void OnDataChannelAdded(DataChannel channel)
 {
     Logger.Log($"Added data channel '{channel.Label}' (#{channel.ID}).");
     ThreadHelper.RunOnMainThread(() =>
     {
         var chat = new ChatChannelModel(channel);
         ChatChannels.Add(chat);
     });
 }
Exemple #2
0
        private void JoinChannel(IChatChannel chatChannel, string channel)
        {
            lock ( channelsLock )
            {
                if (!ChatChannels.Any(c => c.ChannelName == channel) &&
                    !channel.Replace("#", "").Equals(AnonymousNickName, StringComparison.InvariantCultureIgnoreCase))
                {
                    Log.WriteInfo("{0} joining {1}", Config.ChatName, channel);

                    if (RemoveChannel != null)
                    {
                        RemoveChannel(chatChannel.ChannelName, this);
                    }

                    ChatChannels.Add(chatChannel);

                    chatChannel.Join((joinChannel) =>
                    {
                        lock ( joinLock )
                        {
                            Log.WriteInfo("{0} joined {1}", Config.ChatName, channel);

                            UpdateStats();
                            if (AddChannel != null)
                            {
                                AddChannel(joinChannel.ChannelName, this);
                            }

                            if (Status.IsStopping)
                            {
                                return;
                            }

                            lock (toolTipLock)
                            {
                                if (!Status.ToolTips.ToList().Any(t => t.Header == channel))
                                {
                                    UI.Dispatch(() => Status.ToolTips.Add(new ToolTip(channel, joinChannel.ChannelStats.ViewersCount.ToString())));
                                }
                            }
                            Status.IsConnecting = false;
                            Status.IsConnected  = true;
                        }
                    }, channel);
                }
            }
        }
        private void LoadChatChannels()
        {
            var chatChannelTypes = typeof(ChatChannelManagerService).GetTypeInfo().Assembly.DefinedTypes
                                   .Where(typeInfo => typeof(ChatChannel).GetTypeInfo().IsAssignableFrom(typeInfo) &&
                                          !typeInfo.IsDefined(typeof(ChatChannelDisableAutoLoadAttribute), true) &&
                                          !typeInfo.IsAbstract);

            foreach (var chatChannel in chatChannelTypes.Where(type => type != typeof(ScriptChatChannel).GetTypeInfo()).Select(type => (ChatChannel)Activator.CreateInstance(type.AsType())))
            {
                ChatChannels.Add(chatChannel);
            }

            var scriptChatChannelLoaderTypes = typeof(ChatChannelManagerService).GetTypeInfo().Assembly.DefinedTypes
                                               .Where(typeInfo => typeof(ScriptChatChannelLoader).GetTypeInfo().IsAssignableFrom(typeInfo) &&
                                                      !typeInfo.IsDefined(typeof(ChatChannelDisableAutoLoadAttribute), true) &&
                                                      !typeInfo.IsAbstract);

            foreach (var scriptChatChannelLoader in scriptChatChannelLoaderTypes.Where(type => type != typeof(ScriptChatChannelLoader).GetTypeInfo()).Select(type => (ScriptChatChannelLoader)Activator.CreateInstance(type.AsType())))
            {
                ChatChannels.AddRange(scriptChatChannelLoader.LoadChatChannels());
            }
        }
Exemple #4
0
        public void StartAllChats()
        {
            steamChat = (SteamChat)GetChat(SettingsRegistry.ChatTitleSteam);
            if (historyService.Config.Enabled)
            {
                historyService.Start();
            }

            //Accumulate messages and update ViewModel periodically
            receiveTimer.Interval = TimeSpan.FromMilliseconds(1500);
            receiveTimer.Tick    += receiveTimer_Tick;
            receiveTimer.Start();

            timerUpdateDatabase = new Timer((o) => { UpdateDatabase(); }, this, 0, 60000);

            int waitChatStatus = 5000;

            Chats.ForEach(chat =>
            {
                chat.MessageReceived += chat_MessageReceived;
                chat.AddChannel       = (channel, fromChat) =>
                {
                    lock ( channelsLock )
                    {
                        UI.Dispatch(() => {
                            lock (channelsLock)
                            {
                                if (!ChatChannels.Any(c => c.ChannelName == channel && c.ChatName == fromChat.ChatName))
                                {
                                    ChatChannels.Add(new ChatChannel()
                                    {
                                        ChatName = fromChat.ChatName, ChannelName = channel, ChatIconURL = fromChat.IconURL
                                    });
                                }
                            }
                        });
                    }
                };
                chat.RemoveChannel = (channel, fromChat) =>
                {
                    UI.Dispatch(() =>
                    {
                        lock (channelsLock)
                        {
                            var searchItem = ChatChannels.FirstOrDefault(item => item.ChatName == fromChat.ChatName && item.ChannelName == channel && item.ChatIconURL == fromChat.IconURL);
                            if (searchItem != null)
                            {
                                ChatChannels.Remove(searchItem);
                            }

                            if (ChatChannels.Count <= 0)
                            {
                                if (!chat.Status.IsStopping)
                                {
                                    chat.Status.IsConnected = false;
                                    chat.Status.IsLoggedIn  = false;
                                    chat.Restart();
                                }
                            }
                        }
                    });
                };
                if (chat.Enabled)
                {
                    Task.Factory.StartNew(() => {
                        var c = chat;
                        c.Start();

                        while (ChatStatusHandler == null && waitChatStatus > 0)
                        {
                            waitChatStatus -= 50;
                            Thread.Sleep(100);
                        }

                        if (ChatStatusHandler != null)
                        {
                            ChatStatusHandler(c);
                        }
                    });
                }
            });
        }