Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match against some ignored voice values #509

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/nostrum/voice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ defmodule Nostrum.Voice do
voice = get_voice(guild_id)

if VoiceState.ready_for_rtp?(voice) do
Audio.send_frames(frames, voice)
{_voice, _done?} = Audio.send_frames(frames, voice)
:ok
else
{:error, "Must be connected to voice channel to send frames."}
Expand All @@ -573,7 +573,7 @@ defmodule Nostrum.Voice do

cond do
VoiceState.ready_for_ws?(voice) ->
VoiceSupervisor.create_session(voice)
{:ok, _pid} = VoiceSupervisor.create_session(voice)
:ok

is_nil(voice) ->
Expand Down
19 changes: 10 additions & 9 deletions lib/nostrum/voice/audio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ defmodule Nostrum.Voice.Audio do
wait = if(init?, do: Application.get_env(:nostrum, :audio_timeout, 20_000), else: 500)
{:ok, watchdog} = :timer.apply_after(wait, __MODULE__, :on_stall, [voice, self()])

{voice, done} =
{voice, done?} =
voice
|> get_source()
|> Enum.take(frames_per_burst())
|> send_frames(voice)

:timer.cancel(watchdog)
{:ok, :cancel} = :timer.cancel(watchdog)

if done,
if done?,
do: on_complete(voice, init?),
else: voice
end
Expand All @@ -136,12 +136,13 @@ defmodule Nostrum.Voice.Audio do
def send_frames(frames, %VoiceState{} = voice) do
voice =
Enum.reduce(frames, voice, fn f, v ->
:gen_udp.send(
v.udp_socket,
v.ip |> ip_to_tuple(),
v.port,
encrypt_packet(v, f)
)
:ok =
:gen_udp.send(
v.udp_socket,
v.ip |> ip_to_tuple(),
v.port,
encrypt_packet(v, f)
)

%{
v
Expand Down
4 changes: 1 addition & 3 deletions lib/nostrum/voice/ports.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ defmodule Nostrum.Voice.Ports do
end
end

alias Nostrum.Voice.Ports.State

require Logger

use GenServer
Expand All @@ -41,7 +39,7 @@ defmodule Nostrum.Voice.Ports do

# Spawn process to asynchronously send input to port
unless is_nil(input) do
Task.start(fn -> send_input(port, input) end)
{:ok, _pid} = Task.start(fn -> send_input(port, input) end)
end

# Store reference if input is another process
Expand Down