public override async Task OnConnected() { string name = Context.User.Identity.Name; string type = ""; if (Context.User.Identity.Name == null) { name = Context.QueryString["Name"]; type = Context.QueryString["Type"]; Clients.All.userConnected(String.Format("Connected : {0} - {1}", Context.ConnectionId, _connections.Count)); } else { type = "User"; } _connections.Add(name, Context.ConnectionId); Logger.LogInformation(String.Format("Connected : {0} - {1}", name, type)); Clients.Caller.userConnected(String.Format("Connected : {0} - {1}", name, type)); Clients.All.userConnected(String.Format("Connected : {0} - {1}", Context.ConnectionId, _connections.Count)); await base.OnConnected(); }
public override Task OnConnected() { if (_contextService.CurrentUserAccountId != null) { _connections.Add(_contextService.CurrentUserAccountId.ToString(), Context.ConnectionId); } return(base.OnConnected()); }
public override Task OnConnected() { string name = Context.User.Identity.Name; _connections.Add(name, Context.ConnectionId); return(base.OnConnected()); }
public override Task OnConnected() { string name = Context.User.Identity.Name; string userId = ApplicationUserExtension.GetUserId(name); _connections.Add(userId, Context.ConnectionId); return(base.OnConnected()); }
public override Task OnConnected() { //string name = Context.User.Identity.Name; var name = Context.QueryString["UserName"]; _connections.Add(name, Context.ConnectionId); return(base.OnConnected()); }
public async override Task OnConnectedAsync() { string group = Context.GetHttpContext().Request.Query["group"]; CodeEditorUser user = new CodeEditorUser(Context.ConnectionId); if (string.IsNullOrEmpty(group) || group == "null") { string groupName = Convert.ToBase64String(guid.ToByteArray()); groupName = groupName.Replace("=", ""); groupName = groupName.Replace("+", ""); groupName = groupName.Replace("/", ""); user.Role = CodeEditorRole.Driver; user.GroupName = groupName; _groups.Add(groupName, user); await Groups.AddToGroupAsync(Context.ConnectionId, groupName); await Clients.Client(Context.ConnectionId).ReceiveGroup(groupName); } else { user.GroupName = group; if (CanJoinGroup(group)) { CodeEditorUser partner = _groups.GetConnections(group).First(); if (partner.Role == CodeEditorRole.Driver) { user.Role = CodeEditorRole.Navigator; } else { user.Role = CodeEditorRole.Driver; } _groups.Add(group, user); await Groups.AddToGroupAsync(Context.ConnectionId, group); } else { await Clients.Client(Context.ConnectionId).ReceiveError(); return; } } await Clients.Client(Context.ConnectionId).ReceiveRole(user.Role); ReadCodeResult code = await _queryDispatcher.DisptachAsync <ReadCodeQuery, ReadCodeResult>(new ReadCodeQuery(_groups.FindKeys(Context.ConnectionId).First())); await Clients.Client(Context.ConnectionId).ReceiveCodeUpdate(code.Lines); await base.OnConnectedAsync(); }
public override Task OnConnected() { if (Context.User.IsInRole(RoleName.Student)) { int studentId = AccountCredentials.GetStudentId((ClaimsIdentity)Context.User.Identity); Connections.Add(studentId, Context.ConnectionId); } return(base.OnConnected()); }
public override Task OnConnected() { Guid jobid = GetJobId(); //var version = Context.QueryString["orgid"]; Connections.Add(jobid, Context.ConnectionId); return(base.OnConnected()); }
public override Task OnConnected() { if (Authorization.IsLoggedIn) { var user = (UserDefinition)Authorization.UserDefinition; _connections.Add(Convert.ToInt32(user.Id), Context.ConnectionId); Groups.Add(Context.ConnectionId, user.TenantId.ToString()); } return(base.OnConnected()); }
public override async Task OnConnected() { string name = Context.User.Identity.Name; messaging($"Connected: {name} - {Context.ConnectionId}"); _connections.Add(name, Context.ConnectionId); broadcastUsers(); await base.OnConnected(); }
public override Task OnConnected() { // this will only work if the user is logged in string name = Context.User.Identity.Name; //var user = db.Users.First(u => u.UserName == name); //user.Online = "online"; //db.SaveChanges(); _connections.Add(name, Context.ConnectionId); Groups.Add(Context.ConnectionId, name); Clients.Others.login(name); Clients.Caller.displayOnline(_connections.UsersOnline()); return(base.OnConnected()); }
public void RegisterClient(string name) { Player player = AddPlayer(name); _connections.Add(player.id.ToString(), Context.ConnectionId); Clients.Client(Context.ConnectionId).SendAsync("registered"); }
public override Task OnConnected() { string name = Context.User.Identity.Name; if (!_connections.ContainsKey(name)) { context.Clients.All.connected(name); } _connections.Add(name, Context.ConnectionId); RoomModel room = new RoomModel { Name = "lobby", Password = string.Empty }; if (GroupsMapping.ContainsKey(room.Name)) { List <string> clientsInThisGroup = GroupsMapping[room.Name]; clientsInThisGroup.Add(Context.ConnectionId); } else { var clientsInThisGroup = new List <string>(); clientsInThisGroup.Add(Context.ConnectionId); GroupsMapping.Add(room.Name, clientsInThisGroup); } Clients.OthersInGroup(room.Name).userJoinedThisRoom(name); Groups.Add(Context.ConnectionId, room.Name); return(base.OnConnected()); }
public override Task OnConnectedAsync() { string email = Context.GetHttpContext().Request.Query["email"]; _connectionMapping.Add(email, Context.ConnectionId); return(base.OnConnectedAsync()); }
public override System.Threading.Tasks.Task OnConnected() { //Create an instance of the Repository class string name = Context.User.Identity.GetUserId(); var user = _db.Users.Find(name); var usersFollowing = user.UserFollow.Select(e => e.UserBeingFollowedUserId).ToArray(); var followingEachOther = _db.UserFollow.Where(e => usersFollowing.Contains(e.UserId)) .Where(e => e.UserBeingFollowedUserId == user.Id).Select(id => id.UserId).ToArray(); List <OnlineUsersViewModel> model = new List <OnlineUsersViewModel>(); List <string> connectionIds = new List <string>(); foreach (var connection in followingEachOther) { var connectionid = _connections.GetConnections(connection.ToString()); var enumerable = connectionid.ToList(); if (enumerable.Any()) { connectionIds.Add(enumerable.First()); var onlineUser = _db.Users.Find(connection); OnlineUsersViewModel temp = new OnlineUsersViewModel { UserId = onlineUser.Id, UserName = onlineUser.UserFirstName + " " + onlineUser.UserSurname, UserProfilePhoto = onlineUser.UserProfilePhoto }; model.Add(temp); } } _connections.Add(name, Context.ConnectionId); dynamic client = null; foreach (var connectionId in _connections.GetConnections(name.ToString())) { client = Clients.Client(connectionId); } Clients.Clients(connectionIds).updateOnlineUsers(new OnlineUsersViewModel() { UserId = user.Id, UserName = user.UserFirstName + " " + user.UserSurname, UserProfilePhoto = user.UserProfilePhoto }); client.onlineUsers(model); return(base.OnConnected()); }
public void HandMakeConnection(string username) { UserContext.UserName = username; Connections.Add(UserContext.UserName, Context.ConnectionId); Console.WriteLine(UserContext.UserName + " : " + Context.ConnectionId); }
public override Task OnConnected() { var messageId = Guid.Parse(Context.QueryString["threadId"]); var message = _ms.View(Context.User, messageId); if (message == null) { throw new UnauthorizedAccessException(); } string connectionId = Context.ConnectionId; string name = Context.User.Identity.Name; Groups.Add(connectionId, messageId.ToString()); _connections.Add(name, connectionId); return(base.OnConnected()); }
public override Task OnConnected() { string name = Context.QueryString["username"]; ConnectionMapping <string> .Add(name, Context.ConnectionId); Clients.All.userJoinOrLeave(ConnectionMapping <string> .GetConnections()); return(base.OnConnected()); }
public override Task OnConnectedAsync() { var userid = Context.GetContextHeaderValue("userid"); var connectionKey = userid.ConvertTo <TConnectionKey>(); _connections.Add(connectionKey, Context.ConnectionId); return(base.OnConnectedAsync()); }
public void PlayerJoined(string name) { _connections.Add(name, Context.ConnectionId); int[] Position = Program.map.GetFreePosition(); Clients.Caller.SendAsync("ReceiveObjects", Position, Program.tanks.ToArray(), Program.utilities.ToArray()); Program.AddTank(Position, name); Clients.AllExcept(Context.ConnectionId).SendAsync("ReceiveOpponentCoords", name, Position); }
public override Task OnConnectedAsync() { this.Clients.Caller.SendAsync("ReceiveOnlineUsers", Connections.GetOnlineUsers()); var name = this.Context.User.Identity.Name; this.Clients.Others.SendAsync("UserLoggedIn", name); Connections.Add(name, this.Context.ConnectionId); this.logger.LogInformation($"{name} connected with id {this.Context.ConnectionId}"); return(base.OnConnectedAsync()); }
public override async Task OnConnectedAsync() { var id = Context.ConnectionId; CurrentConnections.Add(id); await Clients.All.SendAsync("Online", CurrentConnections.Count); _connections.Add(id, Context.ConnectionId); await base.OnConnectedAsync(); }
public void ConnectionMappingAddMultipleTest() { ConnectionMapping <string> groups = new ConnectionMapping <string>(); string firstGroup = "group_1"; CodeEditorUser g1FirstUser = new CodeEditorUser("g1_connection_1"); CodeEditorUser g1SecondUser = new CodeEditorUser("g1_connection_2"); string secondGroup = "group_2"; CodeEditorUser g2FirstUser = new CodeEditorUser("g2_connection_1"); groups.Add(firstGroup, g1FirstUser); groups.Add(firstGroup, g1SecondUser); groups.Add(secondGroup, g2FirstUser); Assert.True(groups.Count == 2); Assert.Equal(2, groups.GetConnections(firstGroup).ToList <CodeEditorUser>().Count); Assert.Equal(g1FirstUser, groups.GetConnections(firstGroup).ElementAtOrDefault(0)); Assert.Equal(g1SecondUser, groups.GetConnections(firstGroup).ElementAtOrDefault(1)); Assert.Equal(g2FirstUser, groups.GetConnections(secondGroup).ElementAtOrDefault(0)); return; }
public override async Task OnConnectedAsync() { var httpContext = Context.GetHttpContext(); var name = httpContext.Request.Query["name"]; _connections.Add(name, Context.ConnectionId); SignalRUsers.Add(new Users { UserName = name, ConnectionId = Context.ConnectionId }); await Clients.All.SendAsync("UpdateUserList", _connections.ToJson()); }
public override Task OnConnected() { // We show all currently connected users var currentUsers = _connections.AllConnectedUsers(); foreach (var user in currentUsers) { if (user != _username) { Clients.Client(Context.ConnectionId).userConnected(user); } } _connections.Add(_username, Context.ConnectionId); // We inform all other users that current user has connected Clients.AllExcept(Context.ConnectionId).userConnected(_username); return(base.OnConnected()); }
public override Task OnConnectedAsync() { var httpContext = Context.GetHttpContext(); var queryStr = httpContext.Request.Query["name"]; if (queryStr.Count != 0) { _connections.Add(queryStr.First(), Context.ConnectionId); } return(base.OnConnectedAsync()); }
public override System.Threading.Tasks.Task OnConnected() { //Create an instance of the Repository class NotificationRepository objRepository = new NotificationRepository(); string name = Context.User.Identity.GetUserId(); _connections.Add(name, Context.ConnectionId); //refreshNotification is the client side method which will be writing in the future section. GetLogin() is a static extensions extract just the login name scrapping the domain name // Clients.User(Context.User.Identity.GetUserId()).refreshNotification(objRepository.GetUserNotifications(Convert.ToInt32(Context.User.Identity.GetUserId()))); dynamic client = null; foreach (var connectionId in _connections.GetConnections(name.ToString())) { client = Clients.Client(connectionId); } List <UserNotifications> notifications = objRepository.GetUserNotifications(name); client.refreshNotification(notifications); return(base.OnConnected()); }
public override Task OnConnectedAsync() { string name = Context.User.Identity.Name; if (!_connections.GetConnections(name).Contains(Context.ConnectionId)) { var conn = Context.ConnectionId; _connections.Add(name, conn); } return(base.OnConnectedAsync()); }
public override async Task OnConnectedAsync() { //string name = Context.User.Identity.Name; string name = "testUser"; _connections.Add(name, Context.ConnectionId); await RegisterGroupAsync(name); await RegisterGroupAsync(Constants.GROUP_SIGNALR); await base.OnConnectedAsync(); }
public void ConnectionMappingRemoveTest() { ConnectionMapping <string> groups = new ConnectionMapping <string>(); string firstGroup = "group_1"; CodeEditorUser g1FirstUser = new CodeEditorUser("g1_connection_1"); CodeEditorUser g1SecondUser = new CodeEditorUser("g1_connection2"); groups.Add(firstGroup, g1FirstUser); groups.Add(firstGroup, g1SecondUser); Assert.True(groups.Count == 1); Assert.Equal(2, groups.GetConnections(firstGroup).ToList <CodeEditorUser>().Count); Assert.Equal(g1FirstUser, groups.GetConnections(firstGroup).ElementAtOrDefault(0)); Assert.Equal(g1SecondUser, groups.GetConnections(firstGroup).ElementAtOrDefault(1)); groups.Remove(firstGroup, "g1_connection_1"); Assert.True(groups.Count == 1); Assert.Single(groups.GetConnections(firstGroup).ToList <CodeEditorUser>()); Assert.Equal(g1SecondUser, groups.GetConnections(firstGroup).ElementAtOrDefault(0)); return; }