Skip to content

Commit

Permalink
* bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Ben committed Oct 28, 2023
1 parent a08afcf commit ba8d5f2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 51 deletions.
2 changes: 1 addition & 1 deletion config/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
func init() {
config := facades.Config()
config.Add("websocket", map[string]any{
"interval": config.Env("WEBSOCKET_INTERVAL", 10),
"interval": config.Env("WEBSOCKET_INTERVAL", 30),
})
}
30 changes: 0 additions & 30 deletions http/controllers/test_controller.go

This file was deleted.

2 changes: 1 addition & 1 deletion listeners/client_connect_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (receiver *ClientConnectListener) Queue(args ...any) event.Queue {
}

func (receiver *ClientConnectListener) Handle(args ...any) error {
facades.Log().Info("client_connect_listener")
facades.Log().Debug("client_connect_listener")
return nil
}
2 changes: 1 addition & 1 deletion listeners/client_disconnect_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (receiver *ClientDisConnectListener) Queue(args ...any) event.Queue {
}

func (receiver *ClientDisConnectListener) Handle(args ...any) error {
facades.Log().Info("client_connect_listener")
facades.Log().Debug("client_connect_listener")
return nil
}
8 changes: 4 additions & 4 deletions servers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (manager *ClientManager) Start() {
// 建立连接事件
func (manager *ClientManager) EventConnect(client *Client) {
manager.AddClient(client)
facades.Log().Infof("客户端已连接: %s, 客户端总数: %d", client.ClientId, Manager.Count())
facades.Log().Debugf("客户端已连接: %s, 客户端总数: %d", client.ClientId, Manager.Count())

//连接事件
t := carbon.Carbon{}.Now("PRC").ToDateTimeString()
events.NewClientConnectEvent(client.UserId, client.UserId, t)
events.NewClientConnectEvent(client.UserId, client.ClientId, t)
}

// 断开连接时间
Expand All @@ -83,9 +83,9 @@ func (manager *ClientManager) EventDisconnect(client *Client) {
}

t := uint64(time.Now().Unix()) - client.ConnectTime
facades.Log().Infof("客户端已断开: %s, 总数: %d, 耗时: %d", client.ClientId, Manager.Count(), t)
facades.Log().Debugf("客户端已断开: %s, 总数: %d, 耗时: %d", client.ClientId, Manager.Count(), t)
//连接断开事件
events.NewClientDisConnectEvent(client.UserId, client.UserId, t)
events.NewClientDisConnectEvent(client.UserId, client.ClientId, t)

//标记销毁
client.IsDeleted = true
Expand Down
20 changes: 10 additions & 10 deletions servers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func GetOnlineList(systemId *string, groupName *string) map[string]interface{} {

// 通过本服务器发送信息
func SendMessage2LocalClient(messageId, clientId string, sendUserId string, code int, msg string, data *string) {
//facades.Log().Info("发送到通道:" + clientId)
//facades.Log().Debug("发送到通道:" + clientId)
ToClientChan <- clientInfo{ClientId: clientId, MessageId: messageId, SendUserId: sendUserId, Code: code, Msg: msg, Data: data}
return
}
Expand All @@ -146,11 +146,11 @@ func CloseLocalClient(clientId, systemId string) {
return
}
Manager.DisConnect <- conn
facades.Log().Info("主动踢掉客户端:" + clientId)
facades.Log().Debug("主动踢掉客户端:" + clientId)

//连接事件
t := carbon.Now("PRC").ToDateTimeString()
events.NewClientKillEvent(conn.UserId, conn.UserId, t)
events.NewClientKillEvent(conn.UserId, conn.ClientId, t)
}
return
}
Expand All @@ -165,15 +165,15 @@ func WriteMessage() {
facades.Log().Error("终端设备离线:" + clientInfo.ClientId)
//设备失败事件
t := carbon.Now("PRC").ToDateTimeString()
events.NewClientMessageFailEvent(conn.UserId, conn.UserId, t, clientInfo.MessageId)
events.NewClientMessageFailEvent(conn.UserId, conn.ClientId, t, clientInfo.MessageId)

//设备离线
events.NewClientOffloneEvent(conn.UserId, conn.UserId, t)
events.NewClientOffloneEvent(conn.UserId, conn.ClientId, t)
} else {
facades.Log().Infof("终端设备消息:%s, 消息编号:%s", clientInfo.ClientId, clientInfo.MessageId)
facades.Log().Debugf("终端设备消息:%s, 消息编号:%s", clientInfo.ClientId, clientInfo.MessageId)
//设备成功事件
t := carbon.Now("PRC").ToDateTimeString()
events.NewClientMessageSuccessEvent(conn.UserId, conn.UserId, t, clientInfo.MessageId)
events.NewClientMessageSuccessEvent(conn.UserId, conn.ClientId, t, clientInfo.MessageId)
}
}
}
Expand Down Expand Up @@ -209,12 +209,12 @@ func PingTimer() {
Manager.DisConnect <- conn
facades.Log().Errorf("发送心跳失败: %s 总连接数:%d", clientId, Manager.Count())
t := carbon.Now("PRC").ToDateTimeString()
events.NewClientOffloneEvent(conn.UserId, conn.UserId, t)
events.NewClientOffloneEvent(conn.ClientId, conn.ClientId, t)
} else {
facades.Log().Infof("发送心跳成功: %s 总连接数:%d", clientId, Manager.Count())
facades.Log().Debugf("发送心跳成功: %s 总连接数:%d", clientId, Manager.Count())
//设备在线事件
t := carbon.Now("PRC").ToDateTimeString()
e := events.NewClientKeepLiveEvent(conn.UserId, conn.UserId, t)
e := events.NewClientKeepLiveEvent(conn.UserId, conn.ClientId, t)
if e != nil {
facades.Log().Errorf("NewClientKeepLiveEvent: %s ", e.Error())
}
Expand Down
10 changes: 6 additions & 4 deletions service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ func (receiver *ServiceProvider) Boot(app foundation.Application) {

func (receiver *ServiceProvider) Router() {
r := App.MakeRoute()

r.Prefix("api/websocket").Get("ws", controllers.NewWebsocketController().Server)
r.Prefix("api/websocket").Post("register", controllers.NewWebsocketController().Register)
r.Prefix("api/websocket").Post("send_to_client", controllers.NewWebsocketController().SendToClient)
r.Prefix("api/websocket").Post("bind_to_group", controllers.NewWebsocketController().BindToGroup)
r.Prefix("api/websocket").Post("send_to_group", controllers.NewWebsocketController().SendToGroup)
r.Prefix("api/websocket").Post("online_list", controllers.NewWebsocketController().OnelineList)
r.Prefix("api/websocket").Post("close", controllers.NewWebsocketController().CloseClient)
r.Prefix("api/websocket").Post("kick_user", controllers.NewWebsocketController().KickUser)
r.Prefix("api/websocket").Post("online_list", controllers.NewWebsocketController().OnelineList)
r.Prefix("api/websocket").Post("register", controllers.NewWebsocketController().Register)
r.Prefix("api/websocket").Post("send_to_client", controllers.NewWebsocketController().SendToClient)
r.Prefix("api/websocket").Post("send_to_system", controllers.NewWebsocketController().SendToSystem)
go servers.Manager.Start()
go servers.WriteMessage()
servers.PingTimer()
Expand Down

0 comments on commit ba8d5f2

Please sign in to comment.