|
@@ -29,24 +29,23 @@ func (s *ServerSentRouter) Notify() {
|
|
|
|
|
|
sessVal := s.Session().GetMultiple()
|
|
sessVal := s.Session().GetMultiple()
|
|
userId := common.ObjToString(sessVal["userId"])
|
|
userId := common.ObjToString(sessVal["userId"])
|
|
- logger.Info("message userId:", userId)
|
|
|
|
if userId == "" {
|
|
if userId == "" {
|
|
userId = common.InterfaceToStr(s.Session().Id())
|
|
userId = common.InterfaceToStr(s.Session().Id())
|
|
- logger.Info("params userId:", userId)
|
|
|
|
}
|
|
}
|
|
if userId != "" {
|
|
if userId != "" {
|
|
- userId = fmt.Sprintf("%s#%d", userId, time.Now().UnixMilli())
|
|
|
|
- logger.Info("new userId:", userId)
|
|
|
|
|
|
+ keys := fmt.Sprintf("%s#%d", userId, time.Now().UnixMilli())
|
|
|
|
+ logger.Info("new userId:", keys)
|
|
|
|
+ util.SetSseRedisCache(userId, keys)
|
|
// 创建用户专属的消息通道
|
|
// 创建用户专属的消息通道
|
|
messageChan := make(chan string)
|
|
messageChan := make(chan string)
|
|
// 注册当前连接
|
|
// 注册当前连接
|
|
util.SseClientsMu.Lock()
|
|
util.SseClientsMu.Lock()
|
|
- util.SseClients[userId] = messageChan
|
|
|
|
|
|
+ util.SseClients[keys] = messageChan
|
|
util.SseClientsMu.Unlock()
|
|
util.SseClientsMu.Unlock()
|
|
// 客户端断开时清理资源
|
|
// 客户端断开时清理资源
|
|
defer func() {
|
|
defer func() {
|
|
util.SseClientsMu.Lock()
|
|
util.SseClientsMu.Lock()
|
|
- delete(util.SseClients, userId)
|
|
|
|
|
|
+ delete(util.SseClients, keys)
|
|
close(messageChan)
|
|
close(messageChan)
|
|
util.SseClientsMu.Unlock()
|
|
util.SseClientsMu.Unlock()
|
|
}()
|
|
}()
|