This commit is contained in:
@@ -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()
|
||||
teachersList, exists := h.subscribers[studentID]
|
||||
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"
|
||||
}
|
||||
|
||||
msg := SocketMsg{
|
||||
Event: relayEvent,
|
||||
Data: map[string]any{
|
||||
"studentId": studentID,
|
||||
"imageBuffer": data["imageBuffer"],
|
||||
},
|
||||
type RelayFrameRawMsg struct {
|
||||
Event string `json:"event"`
|
||||
Data struct {
|
||||
StudentID int64 `json:"studentId"`
|
||||
ImageBuffer json.RawMessage `json:"imageBuffer"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
msg := RelayFrameRawMsg{
|
||||
Event: relayEvent,
|
||||
}
|
||||
msg.Data.StudentID = studentID
|
||||
msg.Data.ImageBuffer = rawImageBuffer
|
||||
|
||||
msgBytes, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -497,6 +504,26 @@ func WebSocketHandler(db *gorm.DB) func(*websocket.Conn) {
|
||||
}
|
||||
_ = 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
|
||||
if err := json.Unmarshal(msgBytes, &msg); err != nil {
|
||||
continue
|
||||
@@ -506,9 +533,6 @@ func WebSocketHandler(db *gorm.DB) func(*websocket.Conn) {
|
||||
case "client:ping":
|
||||
_ = 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":
|
||||
if client.Role == "teacher" {
|
||||
if sIDVal, ok := msg.Data["studentId"]; ok {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user