Exemple #1
0
        void HandlePacket(byte[] buffer, int ammountRead, IPEndPoint endPoint)
        {
            var data = new Span <byte>(buffer, 0, ammountRead);

            switch ((RopuPacketType)data[0])
            {
            case RopuPacketType.Registration:
            {
                uint userId = data.Slice(1).ParseUint();
                _messageHandler?.Registration(userId, endPoint);
                break;
            }

            case RopuPacketType.Deregister:
            {
                uint userId = data.Slice(1).ParseUint();
                _messageHandler?.Deregister(userId, endPoint);
                break;
            }

            case RopuPacketType.Heartbeat:
            {
                uint userId = data.Slice(1).ParseUint();
                _messageHandler?.Heartbeat(userId, endPoint);
                break;
            }

            case RopuPacketType.StartGroupCall:
            case RopuPacketType.FloorReleased:
            {
                Console.WriteLine("Got Start Group Call Message");
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.HandleCallControllerMessage(groupId, buffer, ammountRead);
                break;
            }

            case RopuPacketType.FloorRequest:
            {
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.HandleCallControllerMessage(groupId, buffer, ammountRead);
                break;
            }

            case RopuPacketType.CallEnded:
            {
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.HandleCallEnded(groupId, buffer, ammountRead, endPoint);
                break;
            }

            case RopuPacketType.FloorTaken:
            {
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.ForwardFloorTaken(groupId, buffer, ammountRead, endPoint);
                break;
            }

            case RopuPacketType.FloorIdle:
            {
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.ForwardFloorIdle(groupId, buffer, ammountRead, endPoint);
                break;
            }

            case RopuPacketType.MediaPacketGroupCallClient:
            {
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.ForwardClientMediaPacket(groupId, buffer, ammountRead, endPoint);
                break;
            }

            case RopuPacketType.MediaPacketGroupCallServingNode:
            {
                ushort groupId = data.Slice(1).ParseUshort();
                _messageHandler?.ForwardPacketToClients(groupId, buffer, ammountRead, endPoint);
                break;
            }

            default:
            {
                Console.Error.WriteLine($"Received unknown packet, packet type {data[0]}");
                break;
            }
            }
        }