public override void ComponentStateChangeFiring <T>(ComponentStateChange <T> componentStateChange) { var isApplianceState = typeof(T) != typeof(ThermocoupleState); var isServerState = typeof(T) == typeof(ConnectionState); componentStateChange.FromUserName = _applicationConfig.UserName; if (_connection.IsConnected() && ((isApplianceState && _applicationConfig.IsAppliance()) || (isServerState && _applicationConfig.IsServer())) ) { _connection.InvokeAsync("ComponentStateChangeBroadcasted", componentStateChange.FromUserName, componentStateChange.GetType().ToString(), componentStateChange.ToJson()); } base.ComponentStateChangeFiring(componentStateChange); }
public override async Task OnConnectedAsync() { UserHandler.ConnectedIds.Add(Context.ConnectionId); var userName = Context.User.Identity.Name; if (UserHandler.UserNames.Add(userName)) { var componentStateChange = new ComponentStateChange <ConnectionState> { FromUserName = userName, CurrentState = new ConnectionState { Status = ConnectionStatus.Connected } }; logger.LogInformation($"User connected: {userName} : {UserHandler.UserNames.Count} : {UserHandler.ConnectedIds.Count}"); await Clients.All.SendAsync("ComponentStateChangeReceived", userName, componentStateChange.GetType().ToString(), componentStateChange.ToJson()); } }