Пример #1
0
        async public Task <object> preConnect([FromForm] Guid?websocketId)
        {
            if (websocketId == null)
            {
                websocketId = Guid.NewGuid();
            }
            var server = WebChatHelper.GetServer(websocketId.Value);
            var token  = $"{Guid.NewGuid()}{Guid.NewGuid()}{Guid.NewGuid()}{Guid.NewGuid()}".Replace("-", "");
            await RedisHelper.SetAsync($"webchat_token_{token}", Newtonsoft.Json.JsonConvert.SerializeObject((websocketId, this.Ip)), 10);

            return(new {
                code = 0,
                server = $"ws://{server}/ws?token={token}",
                websocketId = websocketId
            });
        }
Пример #2
0
    public static void SendMsg(Guid senderId, Guid[] receiveIds, object message, bool receipt = false)
    {
        receiveIds = receiveIds.Distinct().ToArray();
        Dictionary <string, List <Guid> > redata = new Dictionary <string, List <Guid> >();

        foreach (var uid in receiveIds)
        {
            string server = WebChatHelper.GetServer(uid);
            if (redata.ContainsKey(server) == false)
            {
                redata.Add(server, new List <Guid>());
            }
            redata[server].Add(uid);
        }
        foreach (string channel in redata.Keys)
        {
            RedisHelper.Publish($"webchat_{channel}", new WebChatMessage {
                Type = WebChatMessageType.发送消息,
                Data = (senderId, redata[channel], JsonConvert.SerializeObject(message), receipt)