Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup and refactoring #32

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixed error in filter value. 24 is not the same as "24"
RobSchoenaker committed May 17, 2017
commit 21f0b7215d11bd3371986a393895366e8274a98c
75 changes: 38 additions & 37 deletions samples/ChatApplication/ChatHandler.cs
Original file line number Diff line number Diff line change
@@ -6,44 +6,45 @@

namespace ChatApplication
{
public class ChatHandler : WebSocketHandler
public class ChatHandler : WebSocketHandler
{
public ChatHandler(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager)
{
public ChatHandler(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager)
{
}

public override async Task OnConnected(WebSocket socket, HttpContext context)
{
await base.OnConnected(socket, context);

var socketId = WebSocketConnectionManager.GetId(socket);

var message = new Message()
{
MessageType = MessageType.Text,
Data = $"{socketId} is now connected"
};

await SendMessageToAllAsync(message, x => x.Query["age"].Equals(24));
}

public async Task SendMessage(string socketId, string message)
{
await InvokeClientMethodToAllAsync("receiveMessage", socketId, message);
}

public override async Task OnDisconnected(WebSocket socket)
{
var socketId = WebSocketConnectionManager.GetId(socket);

await base.OnDisconnected(socket);

var message = new Message()
{
MessageType = MessageType.Text,
Data = $"{socketId} disconnected"
};
await SendMessageToAllAsync(message, x => x.Query["age"].Equals(24));
}

public override async Task OnConnected(WebSocket socket, HttpContext context)
{
await base.OnConnected(socket, context);

var socketId = WebSocketConnectionManager.GetId(socket);

var message = new Message()
{
MessageType = MessageType.Text,
Data = $"{socketId} is now connected"
};

await SendMessageToAllAsync(message, x => x.Query["age"] == "24");

}

public async Task SendMessage(string socketId, string message)
{
await InvokeClientMethodToAllAsync("receiveMessage", socketId, message);
}

public override async Task OnDisconnected(WebSocket socket)
{
var socketId = WebSocketConnectionManager.GetId(socket);

await base.OnDisconnected(socket);

var message = new Message()
{
MessageType = MessageType.Text,
Data = $"{socketId} disconnected"
};
await SendMessageToAllAsync(message, x => x.Query["age"] == "24");
}
}
}