|
@@ -8,7 +8,6 @@ import (
|
|
"app.yhyue.com/moapp/message/model"
|
|
"app.yhyue.com/moapp/message/model"
|
|
"app.yhyue.com/moapp/message/util"
|
|
"app.yhyue.com/moapp/message/util"
|
|
"fmt"
|
|
"fmt"
|
|
- "log"
|
|
|
|
"net/http"
|
|
"net/http"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -30,12 +29,12 @@ func (s *ServerSentRouter) Notify() {
|
|
|
|
|
|
sessVal := s.Session().GetMultiple()
|
|
sessVal := s.Session().GetMultiple()
|
|
userId := common.ObjToString(sessVal["userId"])
|
|
userId := common.ObjToString(sessVal["userId"])
|
|
- log.Println("message userId:", userId)
|
|
|
|
|
|
+ logger.Info("message userId:", userId)
|
|
if userId == "" {
|
|
if userId == "" {
|
|
userId = common.InterfaceToStr(s.Session().Id())
|
|
userId = common.InterfaceToStr(s.Session().Id())
|
|
}
|
|
}
|
|
//userId = s.GetString("userId")
|
|
//userId = s.GetString("userId")
|
|
- log.Println("params userId:", s.GetString("userId"))
|
|
|
|
|
|
+ logger.Info("params userId:", s.GetString("userId"))
|
|
if userId != "" {
|
|
if userId != "" {
|
|
// 创建用户专属的消息通道
|
|
// 创建用户专属的消息通道
|
|
messageChan := make(chan string)
|
|
messageChan := make(chan string)
|
|
@@ -57,8 +56,10 @@ func (s *ServerSentRouter) Notify() {
|
|
for {
|
|
for {
|
|
select {
|
|
select {
|
|
case msg := <-messageChan:
|
|
case msg := <-messageChan:
|
|
|
|
+ logger.Info("--msg--:", msg, "--userId--:", userId)
|
|
fmt.Fprintf(s.ResponseWriter, "data: %s\n\n", msg)
|
|
fmt.Fprintf(s.ResponseWriter, "data: %s\n\n", msg)
|
|
case <-ticker.C:
|
|
case <-ticker.C:
|
|
|
|
+ logger.Info("--heartbeat--:", userId)
|
|
fmt.Fprintf(s.ResponseWriter, ": heartbeat\n\n")
|
|
fmt.Fprintf(s.ResponseWriter, ": heartbeat\n\n")
|
|
case <-s.Request.Context().Done():
|
|
case <-s.Request.Context().Done():
|
|
return // 客户端断开连接
|
|
return // 客户端断开连接
|