private static bool FireEvent <T>(VoiceSocketFrame frame, Action <T> eventHandler)
        {
            var eventArgs = ((VoiceSocketFrame <T>)frame).Payload;

            eventHandler(eventArgs);
            return(true);
        }
        private async Task SendMessageAsync <T>(VoiceOperation op, T payload)
        {
            var frame = new VoiceSocketFrame <T>
            {
                Operation = op,
                Payload   = payload,
            };

            await _socket !.SendMessageAsync(frame);
        }
        protected void ProcessEvents(VoiceSocketFrame frame)
        {
            bool succeeded = frame switch
            {
                UnknownOperationVoiceSocketFrame osf => FireEvent(osf.Operation, UnknownOperationEncountered),
                _ => frame.Operation switch
                {
                    VoiceOperation.Hello => OnHello((VoiceSocketFrame <VoiceHello>)frame),
                    VoiceOperation.Ready => OnReady((VoiceSocketFrame <VoiceReady>)frame),
                    VoiceOperation.SessionDescription => FireEvent(frame, SessionDescription),
                    VoiceOperation.Heartbeat => OnHeartbeatAck(),
                    VoiceOperation.Speaking => FireEvent(frame, Speaking),
                    VoiceOperation.Video => FireEvent(frame, Video),

                    _ => FireEvent(frame.Operation, UnhandledOperationEncountered),
                }
            };

            if (!succeeded)
            {
                FireEvent(new SocketFrameException("Failed to handle socket frame.", (int?)frame.Operation), UnhandledMessageEncountered);
            }
        }
 private void HandleMessage(VoiceSocketFrame frame)
 {
     ProcessEvents(frame);
 }