示例#1
0
        public async Task Send(IdentityHash destination, ChatMessageDto messageDto)
        {
            ChatRoomContext chatroomContext;

            if (!chatRoomTable.TryLookup(destination, out chatroomContext))
            {
                throw new InvalidStateException("Cannot send message to undiscovered chatroom/user.");
            }

            var messageDtoBytes = CampfireChatSerializer.GetBytes(messageDto);

            if (chatroomContext.IsUnicast)
            {
                Console.WriteLine("Unicast messaging");
                await client.UnicastAsync(destination, messageDtoBytes);
            }
            else if (destination.Bytes.Any(v => v != 0))
            {
                Console.WriteLine("Multicast messaging");
                await client.MulticastAsync(destination, messageDtoBytes);
            }
            else
            {
                Console.WriteLine("Broadcast messaging");
                await client.BroadcastAsync(messageDtoBytes);
            }
        }
示例#2
0
        private void HandleClientMessageReceivedOrSent(MessageReceivedEventArgs e)
        {
            Console.WriteLine("Starting handle");
            var dto = CampfireChatSerializer.Deserialize(e);

            switch (dto.GetType().Name)
            {
            case nameof(ChatMessageDto):
                var message = (ChatMessageDto)dto;
                Console.WriteLine("Calling handle now");
                ChatRoomTable.GetOrCreate(message.BroadcastMessage.DestinationId).HandleMessageReceived(message);
                break;
            }
        }