コード例 #1
0
        public async Task ListenAsync()
        {
            using (var reader = new StreamReader(_client.GetStream())) {
                while (true)
                {
                    var message = await ReadMessageAsync(reader);

                    switch (message.Action)
                    {
                    case Action.MemberJoin:
                        MemberJoins.OnNext(message.Parse <string>());
                        break;

                    case Action.SendMembers:
                        MembersOnline.OnNext(message.Parse <IReadOnlyList <string> >());
                        break;

                    case Action.ChatMessage:
                        var memberMessage = message.Parse <ChatMessage>();
                        MessageRecieved.OnNext($"{memberMessage.UserName}: {memberMessage.Message}");
                        break;

                    case Action.Message:
                        break;

                    case Action.Status:
                        break;

                    case Action.MemberDisconnect:
                        MemberDisconnects.OnNext(message.Parse <string>());
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }