コード例 #1
0
        private static bool FireEvent <T>(VoiceSocketFrame frame, Action <T> eventHandler)
        {
            var eventArgs = ((VoiceSocketFrame <T>)frame).Payload;

            eventHandler(eventArgs);
            return(true);
        }
コード例 #2
0
        private async Task SendMessageAsync <T>(VoiceOperation op, T payload)
        {
            var frame = new VoiceSocketFrame <T>
            {
                Operation = op,
                Payload   = payload,
            };

            await _socket !.SendMessageAsync(frame);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 private void HandleMessage(VoiceSocketFrame frame)
 {
     ProcessEvents(frame);
 }