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); } }
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); } }
public void Join(Participant participant) { participant.JoinRoom(this); participant.MessageReceived += OnParticipantMessageReceived; participant.Disconnected += OnParticipantDisconnected; this.participants.Add(participant); }
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); } }