Example #1
0
 private void OnParticipantMessageReceived(Participant participant, string message)
 {
     var data = new { Name = participant.Name, Body = message };
     foreach (var otherParticipant in participants.Except(new[] { participant }))
     {
         otherParticipant.SendMessage(data);
     }
 }
Example #2
0
 private void OnParticipantDisconnected(Participant participant)
 {
     var message = new { Name = participant.Name, Body = "So long and thanks for all of the shoes!" };
     foreach (var otherParticipant in participants.Except(new[] { participant }))
     {
         otherParticipant.SendMessage(message);
     }
 }
Example #3
0
        public void Join(Participant participant)
        {
            participant.JoinRoom(this);
            participant.MessageReceived += OnParticipantMessageReceived;
            participant.Disconnected += OnParticipantDisconnected;

            this.participants.Add(participant);
        }
Example #4
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.IsWebSocketRequest)
            {
                var name = context.Request.QueryString["Name"];
                var participant = new Participant(name);
                participant.MessageReceived += OnParticipantMessageReceived;
                participant.Disconnected += OnParticipantDisconnected;

                participants.Add(participant);

                context.AcceptWebSocketRequest(participant.Receiver);
            }
        }