|
@@ -10,14 +10,14 @@ import (
|
|
|
"github.com/IceWhaleTech/CasaOS/model/notify"
|
|
|
"github.com/IceWhaleTech/CasaOS/service/model"
|
|
|
"github.com/IceWhaleTech/CasaOS/types"
|
|
|
- "github.com/ambelovsky/gosf"
|
|
|
+
|
|
|
socketio "github.com/googollee/go-socket.io"
|
|
|
"github.com/gorilla/websocket"
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- NotifyMsg chan notify.Message
|
|
|
+ //NotifyMsg chan notify.Message
|
|
|
ClientCount int
|
|
|
)
|
|
|
|
|
@@ -31,12 +31,9 @@ type NotifyServer interface {
|
|
|
MarkRead(id string, state int)
|
|
|
// SendText(m model.AppNotify)
|
|
|
SendUninstallAppBySocket(app notifyCommon.Application)
|
|
|
- SendNetInfoBySocket(netList []model2.IOCountersStat)
|
|
|
- SendCPUInfoBySocket(cpu map[string]interface{})
|
|
|
- SendMemInfoBySocket(mem map[string]interface{})
|
|
|
+
|
|
|
SendFileOperateNotify(nowSend bool)
|
|
|
SendInstallAppBySocket(app notifyCommon.Application)
|
|
|
- SendAllHardwareStatusBySocket(mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat)
|
|
|
SendStorageBySocket(message notify.StorageMessage)
|
|
|
SendNotify(path string, message map[string]interface{})
|
|
|
SettingSystemTempData(message map[string]interface{})
|
|
@@ -55,57 +52,11 @@ func (i *notifyServer) SettingSystemTempData(message map[string]interface{}) {
|
|
|
}
|
|
|
|
|
|
func (i *notifyServer) SendNotify(path string, message map[string]interface{}) {
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = message
|
|
|
- msg.Success = true
|
|
|
- msg.Text = path
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = path
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", path, message)
|
|
|
}
|
|
|
|
|
|
func (i *notifyServer) SendStorageBySocket(message notify.StorageMessage) {
|
|
|
- body := make(map[string]interface{})
|
|
|
- body["data"] = message
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "storage_status"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "storage_status"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
-}
|
|
|
-
|
|
|
-func (i *notifyServer) SendAllHardwareStatusBySocket(mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat) {
|
|
|
- body := make(map[string]interface{})
|
|
|
-
|
|
|
- body["sys_mem"] = mem
|
|
|
-
|
|
|
- body["sys_cpu"] = cpu
|
|
|
-
|
|
|
- body["sys_net"] = netList
|
|
|
-
|
|
|
- for k, v := range i.SystemTempMap {
|
|
|
- body[k] = v
|
|
|
- }
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "sys_hardware_status"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "sys_hardware_status"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", "storage_status", message)
|
|
|
}
|
|
|
|
|
|
// Send periodic broadcast messages
|
|
@@ -122,17 +73,8 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
|
|
|
listMsg := make(map[string]interface{})
|
|
|
if len == 0 {
|
|
|
model.Data = []string{}
|
|
|
-
|
|
|
listMsg["file_operate"] = model
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Success = true
|
|
|
- msg.Body = listMsg
|
|
|
- msg.Text = "file_operate"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "file_operate"
|
|
|
- notify.Msg = msg
|
|
|
- NotifyMsg <- notify
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", "file_operate", listMsg)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -180,16 +122,7 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
|
|
|
model.Data = list
|
|
|
|
|
|
listMsg["file_operate"] = model
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Success = true
|
|
|
- msg.Body = listMsg
|
|
|
- msg.Text = "file_operate"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "file_operate"
|
|
|
- notify.Msg = msg
|
|
|
- NotifyMsg <- notify
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", "file_operate", listMsg)
|
|
|
} else {
|
|
|
for {
|
|
|
|
|
@@ -246,99 +179,19 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
|
|
|
model.Data = list
|
|
|
|
|
|
listMsg["file_operate"] = model
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Success = true
|
|
|
- msg.Body = listMsg
|
|
|
- msg.Text = "file_operate"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "file_operate"
|
|
|
- notify.Msg = msg
|
|
|
- NotifyMsg <- notify
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", "file_operate", listMsg)
|
|
|
time.Sleep(time.Second * 3)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (i *notifyServer) SendMemInfoBySocket(mem map[string]interface{}) {
|
|
|
- body := make(map[string]interface{})
|
|
|
- body["data"] = mem
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "sys_mem"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "sys_mem"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
-}
|
|
|
-
|
|
|
func (i *notifyServer) SendInstallAppBySocket(app notifyCommon.Application) {
|
|
|
- body := make(map[string]interface{})
|
|
|
- body["data"] = app
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", "app_install", app)
|
|
|
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "app_install"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "app_install"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
-}
|
|
|
-
|
|
|
-func (i *notifyServer) SendCPUInfoBySocket(cpu map[string]interface{}) {
|
|
|
- body := make(map[string]interface{})
|
|
|
- body["data"] = cpu
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "sys_cpu"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "sys_cpu"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
-}
|
|
|
-
|
|
|
-func (i *notifyServer) SendNetInfoBySocket(netList []model2.IOCountersStat) {
|
|
|
- body := make(map[string]interface{})
|
|
|
- body["data"] = netList
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "sys_net"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "sys_net"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
}
|
|
|
|
|
|
func (i *notifyServer) SendUninstallAppBySocket(app notifyCommon.Application) {
|
|
|
- body := make(map[string]interface{})
|
|
|
- body["data"] = app
|
|
|
-
|
|
|
- msg := gosf.Message{}
|
|
|
- msg.Body = body
|
|
|
- msg.Success = true
|
|
|
- msg.Text = "app_uninstall"
|
|
|
-
|
|
|
- notify := notify.Message{}
|
|
|
- notify.Path = "app_uninstall"
|
|
|
- notify.Msg = msg
|
|
|
-
|
|
|
- NotifyMsg <- notify
|
|
|
+ SocketServer.BroadcastToRoom("/", "public", "app_uninstall", app)
|
|
|
}
|
|
|
|
|
|
func (i *notifyServer) SSR() {
|