Exemplo n.º 1
0
 private Task ReceiveVoiceTask(CancellationToken token)
 {
     VoiceDebugLogger.Log("Setting up for voice receive.");
     return(Task.Run(async() =>
     {
         while (!token.IsCancellationRequested)
         {
             UdpReceiveResult receivedResult = await _udp.ReceiveAsync().ConfigureAwait(false);
             byte[] receivedBytes = receivedResult.Buffer;
             if (receivedBytes.Length > 0)
             {
                 DiscordAudioPacket packet = new DiscordAudioPacket(receivedBytes);
                 if (PacketReceived != null)
                 {
                     DiscordMember memberSpeaking = Me;
                     foreach (var dictItem in SsrcDictionary)
                     {
                         if (dictItem.Value == packet.SSRC)
                         {
                             memberSpeaking = dictItem.Key;
                         }
                     }
                     if (memberSpeaking.ID != Me.ID)
                     {
                         byte[] pcmPacket = new byte[48 * VoiceConfig.Channels * VoiceConfig.FrameLengthMs];
                         OpusDecoders[0].DecodeFrame(packet.AsRawPacket(), 0, packet.AsRawPacket().Length, pcmPacket);
                         PacketReceived(this, new DiscordAudioPacketEventArgs {
                             Channel = this.Channel, FromUser = memberSpeaking, PCMPacket = pcmPacket
                         });
                     }
                 }
             }
         }
     }));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a given DiscordAudioPacket over the UDP client..
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public async Task SendPacket(DiscordAudioPacket packet)
        {
            if (_udp != null && VoiceWebSocket.State == WebSocketState.Open)
            {
                await _udp.SendAsync(packet.AsRawPacket(), packet.AsRawPacket().Length).ConfigureAwait(false);

                VoiceDebugLogger.Log("Sent packet through SendPacket task.", MessageLevel.Unecessary);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Echoes a received audio packet back.
 /// </summary>
 /// <param name="packet"></param>
 public void EchoPacket(DiscordAudioPacket packet)
 {
     if (VoiceClient != null && ConnectedToVoice())
         VoiceClient.EchoPacket(packet).Wait();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Echos a given DiscordAudioPacket.
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 public async Task EchoPacket(DiscordAudioPacket packet)
 {
     await SendPacket(DiscordAudioPacket.EchoPacket(packet.AsRawPacket(), Params.ssrc)).ConfigureAwait(false);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Sends a given DiscordAudioPacket over the UDP client..
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 public async Task SendPacket(DiscordAudioPacket packet)
 {
     if (_udp != null && VoiceWebSocket.State == WebSocketState.Open)
     {
         await _udp.SendAsync(packet.AsRawPacket(), packet.AsRawPacket().Length).ConfigureAwait(false);
         VoiceDebugLogger.Log("Sent packet through SendPacket task.", MessageLevel.Unecessary);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Echos a given DiscordAudioPacket.
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 public async Task EchoPacket(DiscordAudioPacket packet)
 {
     await SendPacket(DiscordAudioPacket.EchoPacket(packet.AsRawPacket(), Params.ssrc)).ConfigureAwait(false);
 }