fix build sv
All checks were successful
Deploy on Master Change / deploy (push) Successful in 1m27s

This commit is contained in:
2026-07-14 07:55:51 +07:00
parent 487e9eb8ea
commit f4b9d99051
2 changed files with 34 additions and 10 deletions

View File

@@ -381,7 +381,7 @@ func (h *WsHub) Unsubscribe(teacherAddr string, studentID int64) {
} }
} }
func (h *WsHub) RelayFrame(studentID int64, event string, data map[string]any) { func (h *WsHub) RelayFrameRaw(studentID int64, event string, rawImageBuffer json.RawMessage) {
h.mu.RLock() h.mu.RLock()
teachersList, exists := h.subscribers[studentID] teachersList, exists := h.subscribers[studentID]
if !exists || len(teachersList) == 0 { if !exists || len(teachersList) == 0 {
@@ -397,13 +397,20 @@ func (h *WsHub) RelayFrame(studentID int64, event string, data map[string]any) {
relayEvent = "teacher:webcam-stream-frame" relayEvent = "teacher:webcam-stream-frame"
} }
msg := SocketMsg{ type RelayFrameRawMsg struct {
Event: relayEvent, Event string `json:"event"`
Data: map[string]any{ Data struct {
"studentId": studentID, StudentID int64 `json:"studentId"`
"imageBuffer": data["imageBuffer"], ImageBuffer json.RawMessage `json:"imageBuffer"`
}, } `json:"data"`
} }
msg := RelayFrameRawMsg{
Event: relayEvent,
}
msg.Data.StudentID = studentID
msg.Data.ImageBuffer = rawImageBuffer
msgBytes, err := json.Marshal(msg) msgBytes, err := json.Marshal(msg)
if err != nil { if err != nil {
return return
@@ -497,6 +504,26 @@ func WebSocketHandler(db *gorm.DB) func(*websocket.Conn) {
} }
_ = c.SetReadDeadline(time.Now().Add(wsPongWait)) _ = c.SetReadDeadline(time.Now().Add(wsPongWait))
type EventOnlyMsg struct {
Event string `json:"event"`
}
var eventMsg EventOnlyMsg
if err := json.Unmarshal(msgBytes, &eventMsg); err != nil {
continue
}
if eventMsg.Event == "screenshot_stream_frame" || eventMsg.Event == "webcam_stream_frame" {
var frameMsg struct {
Data struct {
ImageBuffer json.RawMessage `json:"imageBuffer"`
} `json:"data"`
}
if err := json.Unmarshal(msgBytes, &frameMsg); err == nil {
Hub.RelayFrameRaw(client.StudentID, eventMsg.Event, frameMsg.Data.ImageBuffer)
}
continue
}
var msg SocketMsg var msg SocketMsg
if err := json.Unmarshal(msgBytes, &msg); err != nil { if err := json.Unmarshal(msgBytes, &msg); err != nil {
continue continue
@@ -506,9 +533,6 @@ func WebSocketHandler(db *gorm.DB) func(*websocket.Conn) {
case "client:ping": case "client:ping":
_ = client.WriteJSON(SocketMsg{Event: "client:pong", Data: map[string]any{"t": time.Now().UnixMilli()}}) _ = client.WriteJSON(SocketMsg{Event: "client:pong", Data: map[string]any{"t": time.Now().UnixMilli()}})
case "screenshot_stream_frame", "webcam_stream_frame":
Hub.RelayFrame(client.StudentID, msg.Event, msg.Data)
case "teacher:subscribe": case "teacher:subscribe":
if client.Role == "teacher" { if client.Role == "teacher" {
if sIDVal, ok := msg.Data["studentId"]; ok { if sIDVal, ok := msg.Data["studentId"]; ok {

Binary file not shown.