feat: implement websocket and UI

This commit is contained in:
Oarkflow
2024-10-22 21:12:55 +05:45
parent 05a673bcd6
commit f337e00b88
21 changed files with 1880 additions and 33 deletions

32
dag/websocket.go Normal file
View File

@@ -0,0 +1,32 @@
package dag
import (
"encoding/json"
"github.com/oarkflow/mq/sio"
)
func WsEvents(s *sio.Server) {
s.On("join", join)
s.On("message", message)
}
func join(s *sio.Socket, data []byte) {
//just one room at a time for the simple example
currentRooms := s.GetRooms()
for _, room := range currentRooms {
s.Leave(room)
}
s.Join(string(data))
s.Emit("joinedRoom", string(data))
}
type msg struct {
Room string
Message string
}
func message(s *sio.Socket, data []byte) {
var m msg
json.Unmarshal(data, &m)
s.ToRoom(m.Room, "message", m.Message)
}