Exemplo n.º 1
0
		internal virtual DataWebSocket CreateDataSocket()
		{
			var socket = new DataWebSocket(this);
			socket.Connected += (s, e) => 
			{
				if (_state == (int)DiscordClientState.Connecting)
					CompleteConnect(); }
			;
			socket.Disconnected += async (s, e) =>
			{
				RaiseDisconnected(e);
				if (e.WasUnexpected)
					await socket.Reconnect(_token);
			};

			if (!_config.VoiceOnly)
			{
				socket.LogMessage += (s, e) => RaiseOnLog(e.Severity, LogMessageSource.DataWebSocket, e.Message);
				if (_config.LogLevel >= LogMessageSeverity.Info)
				{
					socket.Connected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.DataWebSocket, "Connected");
					socket.Disconnected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.DataWebSocket, "Disconnected");
				}
			}

			socket.ReceivedEvent += (s, e) => OnReceivedEvent(e);
			return socket;
		}
Exemplo n.º 2
0
		/// <summary> Initializes a new instance of the DiscordClient class. </summary>
		public DiscordSimpleClient(DiscordClientConfig config = null)
		{
			_config = config ?? new DiscordClientConfig();
			_config.Lock();

			_enableVoice = config.VoiceMode != DiscordVoiceMode.Disabled && !config.EnableVoiceMultiserver;

			_state = (int)DiscordClientState.Disconnected;
			_cancelToken = new CancellationToken(true);
			_disconnectedEvent = new ManualResetEvent(true);
			_connectedEvent = new ManualResetEventSlim(false);
			
			_dataSocket = CreateDataSocket();
			if (_enableVoice)
				_voiceSocket = CreateVoiceSocket();
		}