Exemplo n.º 1
0
        public bool Start()
        {
            Log.WriteInfo("Starting Last.fm service... ");

            lock ( startStopLock )
            {
                if (Config == null)
                {
                    Log.WriteError("LastFM can't start without config!");
                    return(false);
                }
                if (Status.IsStarting &&
                    !Status.IsLoggedIn &&
                    !Status.IsLoginFailed)
                {
                    return(false);
                }

                MusicTrackInfo.Album    = "Connecting to last.fm...";
                MusicTrackInfo.Artist   = "";
                MusicTrackInfo.Title    = "";
                MusicTrackInfo.ImageURL = null;

                Status.IsStarting   = true;
                Status.IsConnecting = true;
                if (!authenticate())
                {
                    MusicTrackInfo.Album = "Authentication failure!";
                    Log.WriteError("Couldn't authenticate on Last.fm. Check credentials!");
                    Status.ResetToDefault();
                    Status.IsLoginFailed = true;
                    if (AfterStart != null)
                    {
                        AfterStart();
                    }
                    return(false);
                }
                pollTimer.Change(0, Timeout.Infinite);
                Status.IsStarting  = false;
                Status.IsLoggedIn  = true;
                Status.IsConnected = true;
                if (AfterStart != null)
                {
                    AfterStart();
                }
                return(true);
            }
        }
Exemplo n.º 2
0
        private void Connect()
        {
            if (obsRemoteWebSocket != null && !obsRemoteWebSocket.IsClosed)
            {
                obsRemoteWebSocket.Disconnect();
                obsRemoteWebSocket = null;
            }

            obsRemoteWebSocket = new WebSocketBase()
            {
                Host                  = Config.GetParameterValue("Host") as string,
                Port                  = "4444",
                SubProtocol           = "obsapi",
                Origin                = "http://client.obsremote.com",
                Path                  = String.Empty,
                ReceiveMessageHandler = HandleOBSRemoteMessage,
            };

            obsRemoteWebSocket.ConnectHandler = () =>
            {
                Status.IsConnected  = true;
                Status.IsConnecting = false;
                if (!Login())
                {
                    Status.IsLoginFailed = true;
                }
                else
                {
                    Status.IsLoggedIn = true;
                    GetVersion();
                    GetAuthRequired();
                    Status.IsStarting = false;
                    //GetSceneList();
                    //GetStreamingStatus();
                    //GetVolumes();
                }
            };

            obsRemoteWebSocket.DisconnectHandler = () =>
            {
                Log.WriteWarning("OBS socket disconnected!");
                if (!Status.IsStopping)
                {
                    if (Status.IsLoginFailed)
                    {
                        return;
                    }

                    Status.ResetToDefault();
                    Thread.Sleep(1000);
                    Start();
                }

                else
                {
                    Status.ResetToDefault();
                }
            };

            Status.IsConnecting = true;
            obsRemoteWebSocket.Connect();
        }
Exemplo n.º 3
0
        public virtual void JoinChannels()
        {
            if (Status.IsStopping || CreateChannel == null)
            {
                return;
            }

            var channels = Config.Parameters.StringArrayValue("Channels").Select(chan => "#" +
                                                                                 (!IsChannelCaseSensitive ? chan.ToLower() : chan).Replace("#", "")
                                                                                 ).ToArray();

            if (!String.IsNullOrWhiteSpace(NickName) &&
                !String.IsNullOrWhiteSpace(Config.GetParameterValue("Username") as string))
            {
                if (!channels.Contains("#" + (!IsChannelCaseSensitive ? NickName.ToLower() : NickName)))
                {
                    channels = channels.Union(new String[] { (!IsChannelCaseSensitive ? NickName.ToLower(): NickName) }).ToArray();
                }
            }

            foreach (var channel in channels)
            {
                var chatChannel = CreateChannel();
                chatChannel.ReadMessage   = ReadMessage;
                chatChannel.LeaveCallback = (leaveChannel) =>
                {
                    Log.WriteInfo("{0} leaving channel {1}", Config.ChatName, channel);

                    leaveChannel.ChannelStats.ViewersCount = 0;
                    leaveChannel.Chat.UpdateStats();

                    if (Status.IsLoginFailed)
                    {
                        IsAnonymous = true;
                    }

                    lock (toolTipLock)
                    {
                        UI.Dispatch(() => Status.ToolTips.RemoveAll(tooltip => tooltip.Header == channel));
                    }

                    lock (channelsLock)
                    {
                        ChatChannels.RemoveAll(chan => chan == null);
                        ChatChannels.RemoveAll(item => item.ChannelName == leaveChannel.ChannelName);
                    }

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

                    if (Status.IsStopping)
                    {
                        return;
                    }

                    lock ( channelsLock  )
                    {
                        if (ChatChannels.Count <= 0)
                        {
                            Status.ResetToDefault();
                            Status.IsConnected  = false;
                            Status.IsConnecting = true;
                        }
                    }
                    Thread.Sleep(1000);
                    lock (joinLock)
                        JoinChannel(chatChannel, channel);
                };
                lock (joinLock)
                    Task.Run(() => JoinChannel(chatChannel, channel));
            }
        }