public UserManager(WebSocketServerWrapper webSocketServer)
{
webSocketServer.OnConnected += (s, context) =>
{
Trace.TraceInformation("Connection From : {0}", context.UserContext.ClientAddress);
AddNewUser(context.UserContext);
};
webSocketServer.OnDisconnect += (s, context) =>
{
Trace.TraceInformation("{0} disconnected", context.UserContext.ClientAddress);
RemoveUser(context.UserContext);
};
webSocketServer.OnReceive += (s, context) =>
{
Trace.TraceInformation("Received {0} from {1}", context.UserContext.DataFrame.ToString(), context.UserContext.ClientAddress);
string command = context.UserContext.DataFrame.ToString();
UserContextData data = null;
if (!_activeUsers.TryGetValue(context.UserContext, out data))
{
data = AddNewUser(context.UserContext);
}
switch (command)
{
case "subscribe":
data.State = UserContextState.SubscribeToFeed;
break;
case "unsubscribe":
data.State = UserContextState.None;
break;
default:
data.StateArgs = command;
break;
}
data.LastRequest = command;
};
}