Example #1
0
        public DiscordSocket()
        {
            SocketListener = new SocketListener();
            SocketHeart    = new SocketHeart();

            SocketListener.PayloadReceived += async(p) =>
            {
                switch ((Opcodes)p.Opcode)
                {
                case Opcodes.Heartbeat:
                    await SocketHeart.Beat();

                    break;

                case Opcodes.Hello:
                    Hello hello = Deserialize <Hello>(p.Data.ToString());
                    SocketHeart.HeartbeatInterval = hello.HeartbeatInterval;
                    SocketHeart.Start();
                    break;
                }
            };
            SocketHeart.HeartStarted += () =>
            {
                Console.WriteLine("Heart Started");
            };
            SocketHeart.HeartbeatSent += (a) =>
            {
                if (a == false)
                {
                    Console.WriteLine($"Something went wrong, heartbeat not acknowledged!");
                }
            };
        }
Example #2
0
        public DiscordSocket()
        {
            SocketListener = new SocketListener();
            SocketHeart    = new SocketHeart();

            SocketListener.GatewayReceived += (p) =>
            {
                //Console.WriteLine(p);

                switch ((Opcodes)p.Opcode)
                {
                case Opcodes.HeartbeatACK:
                    Console.WriteLine("Heartbeat ACK");
                    break;

                case Opcodes.Heartbeat:
                    SocketHeart.Beat();
                    break;

                case Opcodes.Hello:
                    Console.WriteLine("Hello Received");
                    Hello hello = Deserialize <Hello>(p.Data.ToString());
                    SocketHeart.HeartbeatInterval = hello.HeartbeatInterval;
                    SocketHeart.Start();
                    break;

                default:
                    //Console.WriteLine("Gateway received, No actions taken");
                    Console.WriteLine(p);
                    break;
                }
            };
            SocketHeart.HeartStarted += () =>
            {
                Console.WriteLine("Heart Started");
            };
            SocketHeart.HeartbeatSent += (a) =>
            {
                if (a == false)
                {
                    Console.WriteLine($"Something went wrong, heartbeat not acknowledged!");
                }
            };
        }