Exemple #1
0
        internal VoiceNextClient(VoiceNextConfiguration config)
        {
            this.Configuration = config;

            this.ActiveConnections  = new ConcurrentDictionary <ulong, VoiceNextConnection>();
            this.VoiceStateUpdates  = new ConcurrentDictionary <ulong, TaskCompletionSource <VoiceStateUpdateEventArgs> >();
            this.VoiceServerUpdates = new ConcurrentDictionary <ulong, TaskCompletionSource <VoiceServerUpdateEventArgs> >();
        }
Exemple #2
0
 // Token: 0x060000A8 RID: 168 RVA: 0x000037B0 File Offset: 0x000019B0
 internal VoiceNextExtension(VoiceNextConfiguration config)
 {
     this.Configuration      = new VoiceNextConfiguration(config);
     this.IsIncomingEnabled  = config.EnableIncoming;
     this.ActiveConnections  = new ConcurrentDictionary <ulong, VoiceNextConnection>();
     this.VoiceStateUpdates  = new ConcurrentDictionary <ulong, TaskCompletionSource <VoiceStateUpdateEventArgs> >();
     this.VoiceServerUpdates = new ConcurrentDictionary <ulong, TaskCompletionSource <VoiceServerUpdateEventArgs> >();
 }
Exemple #3
0
        internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state)
        {
            Discord = client;
            Guild   = guild;
            Channel = channel;

            TransmittingSSRCs = new ConcurrentDictionary <uint, AudioSender>();
            _userSpeaking     = new AsyncEvent <UserSpeakingEventArgs>(Discord.EventErrorHandler, "VNEXT_USER_SPEAKING");
            _userJoined       = new AsyncEvent <VoiceUserJoinEventArgs>(Discord.EventErrorHandler, "VNEXT_USER_JOINED");
            _userLeft         = new AsyncEvent <VoiceUserLeaveEventArgs>(Discord.EventErrorHandler, "VNEXT_USER_LEFT");
            _voiceReceived    = new AsyncEvent <VoiceReceiveEventArgs>(Discord.EventErrorHandler, "VNEXT_VOICE_RECEIVED");
            _voiceSocketError = new AsyncEvent <SocketErrorEventArgs>(Discord.EventErrorHandler, "VNEXT_WS_ERROR");
            TokenSource       = new CancellationTokenSource();

            Configuration = config;
            Opus          = new Opus(AudioFormat);
            //this.Sodium = new Sodium();
            Rtp = new Rtp();

            ServerData = server;
            StateData  = state;

            var eps = ServerData.Endpoint;
            var epi = eps.LastIndexOf(':');
            var eph = string.Empty;
            var epp = 80;

            if (epi != -1)
            {
                eph = eps.Substring(0, epi);
                epp = int.Parse(eps.Substring(epi + 1));
            }
            else
            {
                eph = eps;
            }
            ConnectionEndpoint = new ConnectionEndpoint {
                Hostname = eph, Port = epp
            };

            ReadyWait     = new TaskCompletionSource <bool>();
            IsInitialized = false;
            IsDisposed    = false;

            PlayingWait         = null;
            PacketQueue         = new ConcurrentQueue <VoicePacket>();
            KeepaliveTimestamps = new ConcurrentDictionary <ulong, long>();

            UdpClient                = Discord.Configuration.UdpClientFactory();
            VoiceWs                  = Discord.Configuration.WebSocketClientFactory(Discord.Configuration.Proxy);
            VoiceWs.Disconnected    += VoiceWS_SocketClosed;
            VoiceWs.MessageRecieved += VoiceWS_SocketMessage;
            VoiceWs.Connected       += VoiceWS_SocketOpened;
            VoiceWs.Errored         += VoiceWs_SocketErrored;
        }
        internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state)
        {
            Discord = client;
            Guild   = guild;
            Channel = channel;
            SSRCMap = new ConcurrentDictionary <uint, ulong>();

            _userSpeaking = new AsyncEvent <UserSpeakingEventArgs>(Discord.EventErrorHandler, "USER_SPEAKING");
            _userLeft     = new AsyncEvent <VoiceUserLeaveEventArgs>(Discord.EventErrorHandler, "USER_LEFT");
#if !NETSTANDARD1_1
            _voiceReceived = new AsyncEvent <VoiceReceiveEventArgs>(Discord.EventErrorHandler, "VOICE_RECEIVED");
#endif
            _voiceSocketError = new AsyncEvent <SocketErrorEventArgs>(Discord.EventErrorHandler, "VOICE_WS_ERROR");
            TokenSource       = new CancellationTokenSource();

            Configuration = config;
            Opus          = new OpusCodec(48000, 2, Configuration.VoiceApplication);
            Sodium        = new SodiumCodec();
            Rtp           = new RtpCodec();

            ServerData = server;
            StateData  = state;

            var eps = ServerData.Endpoint;
            var epi = eps.LastIndexOf(':');
            var eph = string.Empty;
            var epp = 80;
            if (epi != -1)
            {
                eph = eps.Substring(0, epi);
                epp = int.Parse(eps.Substring(epi + 1));
            }
            else
            {
                eph = eps;
            }
            ConnectionEndpoint = new ConnectionEndpoint {
                Hostname = eph, Port = epp
            };

            ReadyWait     = new TaskCompletionSource <bool>();
            IsInitialized = false;
            IsDisposed    = false;

            PlayingWait       = null;
            PlaybackSemaphore = new SemaphoreSlim(1, 1);

            UdpClient             = Discord.Configuration.UdpClientFactory();
            VoiceWs               = Discord.Configuration.WebSocketClientFactory(Discord.Configuration.Proxy);
            VoiceWs.OnDisconnect += VoiceWS_SocketClosed;
            VoiceWs.OnMessage    += VoiceWS_SocketMessage;
            VoiceWs.OnConnect    += VoiceWS_SocketOpened;
            VoiceWs.OnError      += VoiceWs_SocketErrored;
        }
        /// <summary>
        /// Creates a new VoiceNext client with specified settings.
        /// </summary>
        /// <param name="client">Discord client to create VoiceNext instance for.</param>
        /// <param name="config">Configuration for the VoiceNext client.</param>
        /// <returns>VoiceNext client instance.</returns>
        // Token: 0x06000012 RID: 18 RVA: 0x00002268 File Offset: 0x00000468
        public static VoiceNextExtension UseVoiceNext(this DiscordClient client, VoiceNextConfiguration config)
        {
            if (client.GetExtension <VoiceNextExtension>() != null)
            {
                throw new InvalidOperationException("VoiceNext is already enabled for that client.");
            }
            VoiceNextExtension voiceNextExtension = new VoiceNextExtension(config);

            client.AddExtension(voiceNextExtension);
            return(voiceNextExtension);
        }
Exemple #6
0
        internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state)
        {
            this.Discord           = client;
            this.Guild             = guild;
            this.TargetChannel     = channel;
            this.TransmittingSSRCs = new ConcurrentDictionary <uint, AudioSender>();

            this._userSpeaking     = new AsyncEvent <VoiceNextConnection, UserSpeakingEventArgs>("VNEXT_USER_SPEAKING", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._userJoined       = new AsyncEvent <VoiceNextConnection, VoiceUserJoinEventArgs>("VNEXT_USER_JOINED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._userLeft         = new AsyncEvent <VoiceNextConnection, VoiceUserLeaveEventArgs>("VNEXT_USER_LEFT", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._voiceReceived    = new AsyncEvent <VoiceNextConnection, VoiceReceiveEventArgs>("VNEXT_VOICE_RECEIVED", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this._voiceSocketError = new AsyncEvent <VoiceNextConnection, SocketErrorEventArgs>("VNEXT_WS_ERROR", TimeSpan.Zero, this.Discord.EventErrorHandler);
            this.TokenSource       = new CancellationTokenSource();

            this.Configuration = config;
            this.Opus          = new Opus(this.AudioFormat);
            //this.Sodium = new Sodium();
            this.Rtp = new Rtp();

            this.ServerData = server;
            this.StateData  = state;

            var eps = this.ServerData.Endpoint;
            var epi = eps.LastIndexOf(':');
            var eph = string.Empty;
            var epp = 443;

            if (epi != -1)
            {
                eph = eps.Substring(0, epi);
                epp = int.Parse(eps.Substring(epi + 1));
            }
            else
            {
                eph = eps;
            }
            this.WebSocketEndpoint = new ConnectionEndpoint {
                Hostname = eph, Port = epp
            };

            this.ReadyWait     = new TaskCompletionSource <bool>();
            this.IsInitialized = false;
            this.IsDisposed    = false;

            this.PlayingWait         = null;
            this.TransmitChannel     = Channel.CreateBounded <RawVoicePacket>(new BoundedChannelOptions(Configuration.PacketQueueSize));
            this.KeepaliveTimestamps = new ConcurrentDictionary <ulong, long>();
            this.PauseEvent          = new AsyncManualResetEvent(true);

            this.UdpClient                = this.Discord.Configuration.UdpClientFactory();
            this.VoiceWs                  = this.Discord.Configuration.WebSocketClientFactory(this.Discord.Configuration.Proxy);
            this.VoiceWs.Disconnected    += this.VoiceWS_SocketClosed;
            this.VoiceWs.MessageReceived += this.VoiceWS_SocketMessage;
            this.VoiceWs.Connected       += this.VoiceWS_SocketOpened;
            this.VoiceWs.ExceptionThrown += this.VoiceWs_SocketException;
        }
Exemple #7
0
        /// <summary>
        /// Creates new VoiceNext clients on all shards in a given sharded client.
        /// </summary>
        /// <param name="client">Discord sharded client to create VoiceNext instances for.</param>
        /// <param name="config">Configuration for the VoiceNext clients.</param>
        /// <returns>A dictionary of created VoiceNext clients.</returns>
        public static async Task <IReadOnlyDictionary <int, VoiceNextExtension> > UseVoiceNextAsync(this DiscordShardedClient client, VoiceNextConfiguration config)
        {
            var modules = new Dictionary <int, VoiceNextExtension>();
            await client.InitializeShardsAsync().ConfigureAwait(false);

            foreach (var shard in client.ShardClients.Select(xkvp => xkvp.Value))
            {
                var vnext = shard.GetExtension <VoiceNextExtension>();
                if (vnext == null)
                {
                    vnext = shard.UseVoiceNext(config);
                }

                modules[shard.ShardId] = vnext;
            }

            return(new ReadOnlyDictionary <int, VoiceNextExtension>(modules));
        }
Exemple #8
0
        /// <summary>
        /// Creates new VoiceNext clients on all shards in a given sharded client.
        /// </summary>
        /// <param name="client">Discord sharded client to create VoiceNext instances for.</param>
        /// <param name="config">Configuration for the VoiceNext clients.</param>
        /// <returns>A dictionary of created VoiceNext clients.</returns>
        public static IReadOnlyDictionary <int, VoiceNextExtension> UseVoiceNext(this DiscordShardedClient client, VoiceNextConfiguration config)
        {
            var modules = new Dictionary <int, VoiceNextExtension>();

            client.InitializeShardsAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            foreach (var shard in client.ShardClients.Select(xkvp => xkvp.Value))
            {
                var cnext = shard.GetExtension <VoiceNextExtension>();
                if (cnext == null)
                {
                    cnext = shard.UseVoiceNext(config);
                }

                modules.Add(shard.ShardId, cnext);
            }

            return(new ReadOnlyDictionary <int, VoiceNextExtension>(modules));
        }
Exemple #9
0
 /// <summary>
 /// Creates a new instance of <see cref="VoiceNextConfiguration"/>, copying the properties of another configuration.
 /// </summary>
 /// <param name="other">Configuration the properties of which are to be copied.</param>
 public VoiceNextConfiguration(VoiceNextConfiguration other)
 {
     VoiceApplication = other.VoiceApplication;
     EnableIncoming   = other.EnableIncoming;
 }
        internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state)
        {
            this.Discord = client;
            this.Guild   = guild;
            this.Channel = channel;

            this.Configuration = config;
            this.Opus          = new OpusCodec(48000, 2, this.Configuration.VoiceApplication);
            this.Sodium        = new SodiumCodec();
            this.RTP           = new RtpCodec();
            this.Synchronizer  = new Stopwatch();
            this.UdpLatency    = TimeSpan.FromMilliseconds(0.5);

            this.ServerData = server;
            this.StateData  = state;

            var eps = this.ServerData.Endpoint;
            var epi = eps.LastIndexOf(':');
            var eph = string.Empty;
            var epp = 80;

            if (epi != -1)
            {
                eph = eps.Substring(0, epi);
                epp = int.Parse(eps.Substring(epi + 1));
            }
            else
            {
                eph = eps;
            }
            this.ConnectionEndpoint = new DnsEndPoint(eph, epp);

            this.ReadyWait     = new TaskCompletionSource <bool>();
            this.IsInitialized = false;
            this.IsDisposed    = false;

            this.UdpClient             = new UdpClient();
            this.VoiceWs               = WebSocketWrapper.Create($"wss://{this.ConnectionEndpoint.Host}");
            this.VoiceWs.OnDisconnect += this.VoiceWS_SocketClosed;
            this.VoiceWs.OnMessage    += this.VoiceWS_SocketMessage;
            this.VoiceWs.OnConnect    += this.VoiceWS_SocketOpened;
        }
        internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state)
        {
            this.Discord = client;
            this.Guild   = guild;
            this.Channel = channel;
            this.SSRCMap = new ConcurrentDictionary <uint, ulong>();

            this._user_speaking = new AsyncEvent <UserSpeakingEventArgs>(this.Discord.EventErrorHandler, "USER_SPEAKING");
#if !NETSTANDARD1_1
            this._voice_received = new AsyncEvent <VoiceReceiveEventArgs>(this.Discord.EventErrorHandler, "VOICE_RECEIVED");
#endif
            this._voice_socket_error = new AsyncEvent <SocketErrorEventArgs>(this.Discord.EventErrorHandler, "VOICE_WS_ERROR");
            this.TokenSource         = new CancellationTokenSource();

            this.Configuration = config;
            this.Opus          = new OpusCodec(48000, 2, this.Configuration.VoiceApplication);
            this.Sodium        = new SodiumCodec();
            this.Rtp           = new RtpCodec();
            this.UdpLatency    = TimeSpan.FromMilliseconds(0.1);

            this.ServerData = server;
            this.StateData  = state;

            var eps = this.ServerData.Endpoint;
            var epi = eps.LastIndexOf(':');
            var eph = string.Empty;
            var epp = 80;
            if (epi != -1)
            {
                eph = eps.Substring(0, epi);
                epp = int.Parse(eps.Substring(epi + 1));
            }
            else
            {
                eph = eps;
            }
            this.ConnectionEndpoint = new ConnectionEndpoint {
                Hostname = eph, Port = epp
            };

            this.ReadyWait     = new TaskCompletionSource <bool>();
            this.IsInitialized = false;
            this.IsDisposed    = false;

            this.PlayingWait       = null;
            this.PlaybackSemaphore = new SemaphoreSlim(1, 1);

            this.UdpClient             = BaseUdpClient.Create();
            this.VoiceWs               = BaseWebSocketClient.Create();
            this.VoiceWs.OnDisconnect += this.VoiceWS_SocketClosed;
            this.VoiceWs.OnMessage    += this.VoiceWS_SocketMessage;
            this.VoiceWs.OnConnect    += this.VoiceWS_SocketOpened;
            this.VoiceWs.OnError      += this.VoiceWs_SocketErrored;
        }
 /// <summary>
 /// Creates new VoiceNext clients on all shards in a given sharded client.
 /// </summary>
 /// <param name="client">Discord sharded client to create VoiceNext instances for.</param>
 /// <param name="config">Configuration for the VoiceNext clients.</param>
 /// <returns>A dictionary of created VoiceNext clients.</returns>
 // Token: 0x06000013 RID: 19 RVA: 0x00002298 File Offset: 0x00000498
 public static Task <IReadOnlyDictionary <int, VoiceNextExtension> > UseVoiceNextAsync(this DiscordShardedClient client, VoiceNextConfiguration config)
 {
     DiscordClientExtensions.< UseVoiceNextAsync > d__2 <UseVoiceNextAsync> d__;
        // Token: 0x0600007E RID: 126 RVA: 0x000027F4 File Offset: 0x000009F4
        internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state)
        {
            this.Discord           = client;
            this.Guild             = guild;
            this.Channel           = channel;
            this.TransmittingSSRCs = new ConcurrentDictionary <uint, AudioSender>();
            this._userSpeaking     = new AsyncEvent <UserSpeakingEventArgs>(new Action <string, Exception>(this.Discord.EventErrorHandler), "VNEXT_USER_SPEAKING");
            this._userJoined       = new AsyncEvent <VoiceUserJoinEventArgs>(new Action <string, Exception>(this.Discord.EventErrorHandler), "VNEXT_USER_JOINED");
            this._userLeft         = new AsyncEvent <VoiceUserLeaveEventArgs>(new Action <string, Exception>(this.Discord.EventErrorHandler), "VNEXT_USER_LEFT");
            this._voiceReceived    = new AsyncEvent <VoiceReceiveEventArgs>(new Action <string, Exception>(this.Discord.EventErrorHandler), "VNEXT_VOICE_RECEIVED");
            this._voiceSocketError = new AsyncEvent <SocketErrorEventArgs>(new Action <string, Exception>(this.Discord.EventErrorHandler), "VNEXT_WS_ERROR");
            this.TokenSource       = new CancellationTokenSource();
            this.Configuration     = config;
            this.Opus       = new Opus(this.AudioFormat);
            this.Rtp        = new Rtp();
            this.ServerData = server;
            this.StateData  = state;
            string endpoint = this.ServerData.Endpoint;
            int    num      = endpoint.LastIndexOf(':');
            string hostname = string.Empty;
            int    port     = 80;

            if (num != -1)
            {
                hostname = endpoint.Substring(0, num);
                port     = int.Parse(endpoint.Substring(num + 1));
            }
            else
            {
                hostname = endpoint;
            }
            ConnectionEndpoint webSocketEndpoint = default(ConnectionEndpoint);

            webSocketEndpoint.Hostname = hostname;
            webSocketEndpoint.Port     = port;
            this.WebSocketEndpoint     = webSocketEndpoint;
            this.ReadyWait             = new TaskCompletionSource <bool>();
            this.IsInitialized         = false;
            this.IsDisposed            = false;
            this.PlayingWait           = null;
            this.PacketQueue           = new ConcurrentQueue <VoicePacket>();
            this.KeepaliveTimestamps   = new ConcurrentDictionary <ulong, long>();
            this.PauseEvent            = new AsyncManualResetEvent(true);
            this.UdpClient             = this.Discord.Configuration.UdpClientFactory.Invoke();
            this.VoiceWs = this.Discord.Configuration.WebSocketClientFactory.Invoke(this.Discord.Configuration.Proxy);
            this.VoiceWs.Disconnected    += new AsyncEventHandler <SocketCloseEventArgs>(this.VoiceWS_SocketClosed);
            this.VoiceWs.MessageReceived += new AsyncEventHandler <SocketMessageEventArgs>(this.VoiceWS_SocketMessage);
            this.VoiceWs.Connected       += new AsyncEventHandler(this.VoiceWS_SocketOpened);
            this.VoiceWs.ExceptionThrown += new AsyncEventHandler <SocketErrorEventArgs>(this.VoiceWs_SocketException);
        }
 /// <summary>
 /// Creates a new VoiceNext client with specified settings.
 /// </summary>
 /// <param name="client">Discord client to create VoiceNext instance for.</param>
 /// <param name="config">Configuration for the VoiceNext client.</param>
 /// <returns>VoiceNext client instance.</returns>
 public static VoiceNextExtension UseVoiceNext(this DiscordClient client, VoiceNextConfiguration config)
 {
     ClientInstance = new VoiceNextExtension(config);
     client.AddModule(ClientInstance);
     return(ClientInstance);
 }