Skip to content
Draft
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ require (
)

require golang.org/x/sys v0.41.0 // indirect

replace github.com/disgoorg/godave => ../godave
4 changes: 4 additions & 0 deletions voice/audio_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func (s *defaultAudioSender) send() {
if s.opusProvider == nil {
return
}

if !s.conn.DaveSession().Ready() {
return
}
opus, err := s.opusProvider.ProvideOpusFrame()
if err != nil && err != io.EOF {
s.logger.Error("error while reading opus frame", slog.Any("err", err))
Expand Down
14 changes: 12 additions & 2 deletions voice/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type (
// UDP returns the voice UDPConn conn used by the voice Conn.
UDP() UDPConn

// DaveSession returns the godave.Session used by the voice Conn to
// encrypt and decrypt media frames.
DaveSession() godave.Session

// ChannelID returns the ID of the voice channel the voice Conn is openedChan to.
ChannelID() *snowflake.ID

Expand Down Expand Up @@ -77,6 +81,7 @@ func NewConn(guildID snowflake.ID, userID snowflake.ID, voiceStateUpdateFunc Sta
}

daveSession := cfg.DaveSessionCreate(cfg.DaveSessionLogger, godave.UserID(userID.String()), conn)
conn.daveSession = daveSession
conn.gateway = cfg.GatewayCreateFunc(daveSession, conn.handleMessage, conn.handleGatewayClose, append([]GatewayConfigOpt{WithGatewayLogger(cfg.Logger)}, cfg.GatewayConfigOpts...)...)
conn.udp = cfg.UDPConnCreateFunc(daveSession, conn.UserIDBySSRC, append([]UDPConnConfigOpt{WithUDPConnLogger(cfg.Logger)}, cfg.UDPConnConfigOpts...)...)

Expand All @@ -91,8 +96,9 @@ type connImpl struct {
state State
stateMu sync.Mutex

gateway Gateway
udp UDPConn
gateway Gateway
udp UDPConn
daveSession godave.Session

audioSender AudioSender
audioReceiver AudioReceiver
Expand Down Expand Up @@ -148,6 +154,10 @@ func (c *connImpl) UDP() UDPConn {
return c.udp
}

func (c *connImpl) DaveSession() godave.Session {
return c.daveSession
}

func (c *connImpl) SetOpusFrameProvider(provider OpusFrameProvider) {
if c.audioSender != nil {
c.audioSender.Close()
Expand Down
2 changes: 1 addition & 1 deletion voice/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (g *gatewayImpl) doReconnect(ctx context.Context, state State) error {
return nil
}

if errors.Is(err, discord.ErrGatewayAlreadyConnected) {
if errors.Is(err, ErrGatewayAlreadyConnected) {
return err
}

Expand Down
Loading