/// <summary> /// 处理组消息发送 /// </summary> /// <param name="cm">发送消息</param> /// <param name="hc">上下文</param> /// <param name="Clients">连接客户端对象</param> public static ActionResultVM HandleMessageToGroup(ChatMessageVM cm, HttpContext hc, IHubClients Clients) { var vm = new ActionResultVM(); var pmax = GlobalTo.GetValue <int>("NetnrChat:BatchPushGroupMax"); var rme = GlobalTo.GetValue("NetnrChat:ReceiveMessage"); if (cm == null) { vm.Set(ARTag.lack); vm.Msg = "消息主体不能为空"; } else if (string.IsNullOrWhiteSpace(cm.CmFromId)) { vm.Set(ARTag.lack); vm.Msg = "发送用户ID不能为空"; } else if (cm.CmContent == null) { vm.Set(ARTag.lack); vm.Msg = "发送内容不能为空"; } else if (!Enum.TryParse(cm.CmType, true, out MessageType mt)) { vm.Set(ARTag.lack); vm.Msg = "消息类型有误"; } else if (cm.CmToIds == null || cm.CmToIds.Count == 0) { vm.Set(ARTag.lack); vm.Msg = "接收组ID不能为空"; } else if (cm.CmToIds.Count > pmax) { vm.Set(ARTag.refuse); vm.Msg = $"接收组限制为最多{pmax}"; } else { //接收用户 var groups = FindGroup(cm.CmToIds); if (groups.Count > 0) { cm.CmId = NewMessageId(); cm.CmType = mt.ToString(); cm.CmTime = DateTime.Now; cm.CmWhich = "Group"; //用户连接信息 var cu = GetChatUserInfo(hc); cm.CmFromConn = cu?.Conns.Values.FirstOrDefault(); //发送消息 var groupids = groups.Select(x => x.GroupId).ToList(); Clients.Groups(groupids).SendAsync(rme, cm); //写入消息 var wcm = SaveAsGroupMessage(cm); AddMessage(wcm); //发送成功,返回消息ID vm.Data = cm.CmId; vm.Set(ARTag.success); } else { vm.Set(ARTag.invalid); vm.Msg = "接收组ID无效"; } } return(vm); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections in all of the specified groups. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="group1">The first group to include.</param> /// <param name="group2">The second group to include.</param> /// <param name="group3">The third group to include.</param> /// <param name="group4">The fourth group to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Groups <T>(this IHubClients <T> hubClients, string group1, string group2, string group3, string group4) { return(hubClients.Groups(new[] { group1, group2, group3, group4 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections in all of the specified groups. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="groupNames">The group names.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Groups <T>(this IHubClients <T> hubClients, IEnumerable <string> groupNames) { return(hubClients.Groups(groupNames.ToList())); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="connection1">The first connection to include.</param> /// <param name="connection2">The second connection to include.</param> /// <param name="connection3">The third connection to include.</param> /// <param name="connection4">The fourth connection to include.</param> /// <param name="connection5">The fifth connection to include.</param> /// <param name="connection6">The sixth connection to include.</param> /// <param name="connection7">The seventh connection to include.</param> /// <param name="connection8">The eighth connection to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Clients <T>(this IHubClients <T> hubClients, string connection1, string connection2, string connection3, string connection4, string connection5, string connection6, string connection7, string connection8) { return(hubClients.Clients(new[] { connection1, connection2, connection3, connection4, connection5, connection6, connection7, connection8 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections in all of the specified groups. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="group1">The first group to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Groups <T>(this IHubClients <T> hubClients, string group1) { return(hubClients.Groups(new[] { group1 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all clients connected to the hub excluding the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="excludedConnectionId1">The first connection to exclude.</param> /// <param name="excludedConnectionId2">The second connection to exclude.</param> /// <param name="excludedConnectionId3">The third connection to exclude.</param> /// <param name="excludedConnectionId4">The fourth connection to exclude.</param> /// <param name="excludedConnectionId5">The fifth connection to exclude.</param> /// <param name="excludedConnectionId6">The sixth connection to exclude.</param> /// <param name="excludedConnectionId7">The seventh connection to exclude.</param> /// <param name="excludedConnectionId8">The eighth connection to exclude.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T AllExcept <T>(this IHubClients <T> hubClients, string excludedConnectionId1, string excludedConnectionId2, string excludedConnectionId3, string excludedConnectionId4, string excludedConnectionId5, string excludedConnectionId6, string excludedConnectionId7, string excludedConnectionId8) { return(hubClients.AllExcept(new[] { excludedConnectionId1, excludedConnectionId2, excludedConnectionId3, excludedConnectionId4, excludedConnectionId5, excludedConnectionId6, excludedConnectionId7, excludedConnectionId8 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="connection1">The first connection to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Clients <T>(this IHubClients <T> hubClients, string connection1) { return(hubClients.Clients(new[] { connection1 })); }
public static T Players <T>(this IHubClients <T> clients, IEnumerable <Player> players) { return(clients.Players(players.Where(p => p.Role != UserRole.Bot).Select(p => p.Id))); }
public ServiceHubContextImpl(ServiceHubContext baseHubContext, IHubContext <Hub <T>, T> typedHubContext) { _baseHubContext = baseHubContext; Clients = typedHubContext.Clients; }
public SignalRUserEventSubscriber(IHubContext <UsersHub> context) { _clients = context.Clients; }
public static T Players <T>(this IHubClients <T> clients, IEnumerable <Guid> playerIds) { return(clients.Users(playerIds.Select(x => x.ToString()).ToList())); }
public static async Task SendUpdate(IHubClients clients, Guid id, GameResponse game) { var message = JsonConvert.SerializeObject(game); await clients.Group(id.ToString()).SendAsync("UpdateGame", message); }
public UpdateSignaler(IHubContext <UsersHub> context) { _clients = context.Clients; }
/// <summary> /// 处理用户消息发送 /// </summary> /// <param name="cm">发送消息</param> /// <param name="hc">上下文</param> /// <param name="Clients">连接客户端对象</param> public static ActionResultVM HandleMessageToUsers(ChatMessageVM cm, HttpContext hc, IHubClients Clients) { var vm = new ActionResultVM(); var pmax = GlobalTo.GetValue <int>("NetnrChat:BatchPushUserMax"); var rme = GlobalTo.GetValue("NetnrChat:ReceiveMessage"); if (cm == null) { vm.Set(ARTag.lack); vm.Msg = "消息主体不能为空"; } else if (string.IsNullOrWhiteSpace(cm.CmFromId)) { vm.Set(ARTag.lack); vm.Msg = "发送用户ID不能为空"; } else if (cm.CmContent == null) { vm.Set(ARTag.lack); vm.Msg = "发送内容不能为空"; } else if (!Enum.TryParse(cm.CmType, true, out MessageType mt)) { vm.Set(ARTag.lack); vm.Msg = "消息类型有误"; } else if (cm.CmToIds == null || cm.CmToIds.Count == 0) { vm.Set(ARTag.lack); vm.Msg = "接收用户ID不能为空"; } else if (cm.CmToIds.Count > pmax) { vm.Set(ARTag.refuse); vm.Msg = $"接收用户限制为最多{pmax}"; } else { //接收用户 var users = FindUsers(cm.CmToIds); if (users.Count > 0) { cm.CmId = NewMessageId(); cm.CmType = mt.ToString(); cm.CmTime = DateTime.Now; cm.CmWhich = "User"; //用户连接信息 var cu = GetChatUserInfo(hc); cm.CmFromConn = cu?.Conns.Values.FirstOrDefault(); //开始推送 foreach (var user in users) { var isonline = user.Conns.Count > 0; //在线 if (isonline) { Clients.User(user.UserId).SendAsync(rme, cm); } //写入消息 var cs = isonline ? 2 : 1; var wcm = SaveAsUserMessage(cm); wcm.ForEach(x => x.CmuStatus = cs); AddMessage(wcm); } //发送成功,返回消息ID vm.Data = cm.CmId; vm.Set(ARTag.success); } else { vm.Set(ARTag.invalid); vm.Msg = "接收用户ID无效"; } } return(vm); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections associated with all of the specified users. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="user1">The first user to include.</param> /// <param name="user2">The second user to include.</param> /// <param name="user3">The third user to include.</param> /// <param name="user4">The fourth user to include.</param> /// <param name="user5">The fifth user to include.</param> /// <param name="user6">The sixth user to include.</param> /// <param name="user7">The seventh user to include.</param> /// <param name="user8">The eighth user to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Users <T>(this IHubClients <T> hubClients, string user1, string user2, string user3, string user4, string user5, string user6, string user7, string user8) { return(hubClients.Users(new [] { user1, user2, user3, user4, user5, user6, user7, user8 })); }
public HubContext(HubLifetimeManager <THub> lifetimeManager) { _lifetimeManager = lifetimeManager; _clients = new HubClients <THub, T>(_lifetimeManager); Groups = new GroupManager <THub>(lifetimeManager); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections associated with all of the specified users. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="userIds">The user IDs.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Users <T>(this IHubClients <T> hubClients, IEnumerable <string> userIds) { return(hubClients.Users(userIds.ToList())); }
/// <summary> /// Creates a new instance of <see cref="StreamConnector"/>. /// </summary> /// <param name="clients"></param> /// <param name="sourceSettings">Optional settings used to configure the <see cref="Source"/>.</param> /// <param name="sinkSettings">Optional settings used to configure the <see cref="Sink"/>.</param> protected StreamConnector(IHubClients clients, ConnectionSourceSettings sourceSettings = null, ConnectionSinkSettings sinkSettings = null) { Sink = Dsl.Sink.FromGraph(new SignalRSinkStage(clients, sinkSettings ?? ConnectionSinkSettings.Default)); Source = Dsl.Source.FromGraph(new SignalRSourceStage(this, sourceSettings ?? ConnectionSourceSettings.Default)); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all clients connected to the hub excluding the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="excludedConnectionIds">The connection IDs to exclude.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T AllExcept <T>(this IHubClients <T> hubClients, IEnumerable <string> excludedConnectionIds) { return(hubClients.AllExcept(excludedConnectionIds.ToList())); }
public static ClientProxyGroup ByIds(this IHubClients clients, IEnumerable <string> ids) { return(new ClientProxyGroup(ids.Select(clients.Client).ToArray())); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="connection1">The first connection to include.</param> /// <param name="connection2">The second connection to include.</param> /// <param name="connection3">The third connection to include.</param> /// <param name="connection4">The fourth connection to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Clients <T>(this IHubClients <T> hubClients, string connection1, string connection2, string connection3, string connection4) { return(hubClients.Clients(new[] { connection1, connection2, connection3, connection4 })); }
public HubCallerClients(IHubClients hubClients, string connectionId) { _connectionId = connectionId; _hubClients = hubClients; _currentConnectionId = new[] { _connectionId }; }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="connectionIds">The connection IDs.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Clients <T>(this IHubClients <T> hubClients, IEnumerable <string> connectionIds) { return(hubClients.Clients(connectionIds.ToList())); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections in the specified group excluding the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="groupName">The group name.</param> /// <param name="excludedConnectionIds">The connection IDs to exclude.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T GroupExcept <T>(this IHubClients <T> hubClients, string groupName, IEnumerable <string> excludedConnectionIds) { return(hubClients.GroupExcept(groupName, excludedConnectionIds.ToList())); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all clients connected to the hub excluding the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="excludedConnectionId1">The first connection to exclude.</param> /// <param name="excludedConnectionId2">The second connection to exclude.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T AllExcept <T>(this IHubClients <T> hubClients, string excludedConnectionId1, string excludedConnectionId2) { return(hubClients.AllExcept(new[] { excludedConnectionId1, excludedConnectionId2 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections associated with all of the specified users. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="user1">The first user to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Users <T>(this IHubClients <T> hubClients, string user1) { return(hubClients.Users(new [] { user1 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections in all of the specified groups. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="group1">The first group to include.</param> /// <param name="group2">The second group to include.</param> /// <param name="group3">The third group to include.</param> /// <param name="group4">The fourth group to include.</param> /// <param name="group5">The fifth group to include.</param> /// <param name="group6">The sixth group to include.</param> /// <param name="group7">The seventh group to include.</param> /// <param name="group8">The eighth group to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Groups <T>(this IHubClients <T> hubClients, string group1, string group2, string group3, string group4, string group5, string group6, string group7, string group8) { return(hubClients.Groups(new[] { group1, group2, group3, group4, group5, group6, group7, group8 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections associated with all of the specified users. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="user1">The first user to include.</param> /// <param name="user2">The second user to include.</param> /// <param name="user3">The third user to include.</param> /// <param name="user4">The fourth user to include.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T Users <T>(this IHubClients <T> hubClients, string user1, string user2, string user3, string user4) { return(hubClients.Users(new [] { user1, user2, user3, user4 })); }
/// <summary> /// Gets a <typeparamref name="T" /> that can be used to invoke methods on all connections in the specified group excluding the specified connections. /// </summary> /// <param name="hubClients">The abstraction that provides access to connections.</param> /// <param name="groupName">The group name.</param> /// <param name="excludedConnectionId1">The first connection to exclude.</param> /// <param name="excludedConnectionId2">The second connection to exclude.</param> /// <param name="excludedConnectionId3">The third connection to exclude.</param> /// <returns>A <typeparamref name="T" /> representing the methods that can be invoked on the clients.</returns> public static T GroupExcept <T>(this IHubClients <T> hubClients, string groupName, string excludedConnectionId1, string excludedConnectionId2, string excludedConnectionId3) { return(hubClients.GroupExcept(groupName, new[] { excludedConnectionId1, excludedConnectionId2, excludedConnectionId3 })); }
public MessagingListener(IHubContext <CompetitionHub, ICompetitionClient> hubContext, ILiveRaceResultsService liveRaceResultsService, ILogger <MessagingListener> logger) { _clients = hubContext.Clients; _liveRaceResultsService = liveRaceResultsService; _logger = logger; }