This commit consists of these smaller commits:
Gateway: SessionID to be a method for thread safety
This commit breaks the SessionID field of the Gateway struct to
be thread-safe by wrapping its access with a read-write mutex.
As this is a bug fix, it is reasonable of a breaking change
Heart: Allow later binding of event channel
Voice: Use the new Heart API
Heart: Fixed data races
Heart: Allow changing pace, thread-safe Heartbeat
This commit gets rid of all the code that previously managed different
voice sessions in different guilds. This is because there is rarely ever
a need for this, and most bots that need this could do their own
keeping.
This change, although removes some features off of the package, adds a
lot of clarity on what to do exactly when it comes to connecting to a
voice channel.
In order to make the migration process a bit easier, an example has been
added which guides through using the voice.Session API.
* Resolve issue with copied v1 struct
* Speaking event patches, support Client Connect/Disconnect events
* Remove extra debug in heart.go
* Initial voice packet reading
* Resolve unallocated slices, use a static slice/array for decryption, split version/type
* Use separate slice for recvOpus, check return of secretbox.Open, and use constant for header size
* Update missing reference to packetHeaderSize
* Resolve decryption issues, add ReadPacket to session
* Update documentation for recvBuf/recvOpus
* Update comment for recvPacket's array
This commit refactors both wsutil, the normal Gateway and the Voice
Gateway to have better closing behavior, which should assume less and
cover edge cases completely.
This commit fixes race conditions in both package voice, package
voicegateway and package gateway.
Originally, several race conditions exist when both the user's and the
pacemaker's goroutines both want to do several things to the websocket
connection. For example, the user's goroutine could be writing, and the
pacemaker's goroutine could trigger a reconnection. This is racey.
This issue is partially fixed by removing the pacer loop from package
heart and combining the ticker into the event (pacemaker) loop itself.
Technically, a race condition could still be triggered with care, but
the API itself never guaranteed any of those. As events are handled
using an internal loop into a channel, a race condition will not be
triggered just by handling events and writing to the websocket.