mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-12-02 20:02:53 +00:00
diamondburned
c8f72547f7
This commit refactors a lot of voice's internals to be more stable and handle more edge cases from Discord's voice servers. It should result in an overall more stable voice connection. A few helper functions have been added into voice.Session. Some fields will have been broken and changed to accomodate for the refactor, as well. Below are some commits that have been squashed in: voice: Fix Speaking() panic on closed voice: StopSpeaking should not error out The rationale is added as a comment into the Speaking() method. voice: Add TestKickedOut voice: Fix region change disconnecting
49 lines
934 B
Go
49 lines
934 B
Go
package testdata
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const Nico = "testdata/nico.dca"
|
|
|
|
// WriteOpus reads the given file containing the Opus frames into the give
|
|
// io.Writer.
|
|
func WriteOpus(w io.Writer, file string) error {
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to open "+file)
|
|
}
|
|
defer f.Close()
|
|
|
|
var lenbuf [4]byte
|
|
for {
|
|
_, err := io.ReadFull(f, lenbuf[:])
|
|
if err != nil {
|
|
if err == io.EOF {
|
|
return nil
|
|
}
|
|
return errors.Wrap(err, "failed to read "+file)
|
|
}
|
|
|
|
// Read the integer
|
|
framelen := int64(binary.LittleEndian.Uint32(lenbuf[:]))
|
|
|
|
// Copy the frame.
|
|
_, err = io.CopyN(w, f, framelen)
|
|
if err != nil && err != io.EOF {
|
|
return errors.Wrap(err, "failed to write")
|
|
}
|
|
}
|
|
}
|
|
|
|
// WriterFunc wraps f to be an io.Writer.
|
|
type WriterFunc func([]byte) (int, error)
|
|
|
|
func (w WriterFunc) Write(b []byte) (int, error) {
|
|
return w(b)
|
|
}
|