This commit is contained in:
2026-07-13 08:12:04 +07:00
parent 2bb856f2fd
commit 719704f19e
4 changed files with 215 additions and 93 deletions

View File

@@ -578,6 +578,7 @@ func (a *App) Logout() {
blocker.Instance.Stop()
a.disconnectWS()
a.stopScreenshotStream()
a.stopWebcamStream()
guard.SuppressFor(5 * time.Second)
runtime.WindowExecJS(a.ctx, "window.location.href = 'https://portal.rikkei.edu.vn/dangnhap'")
@@ -1157,7 +1158,15 @@ func (a *App) connectWS() {
log.Println("[WS] Connected to proctor websocket hub.")
go func() {
defer a.disconnectWS()
defer func() {
a.disconnectWS(conn)
go func() {
time.Sleep(500 * time.Millisecond)
if a.isMonitoringActive() && a.CheckLoginStatus() {
a.connectWS()
}
}()
}()
for {
var msg struct {
Event string `json:"event"`
@@ -1214,15 +1223,28 @@ func (a *App) connectWS() {
}()
}
func (a *App) disconnectWS() {
a.mu.Lock()
defer a.mu.Unlock()
func (a *App) disconnectWS(expectedConn ...*websocket.Conn) {
var shouldStopStreams bool
a.mu.Lock()
if len(expectedConn) > 0 && expectedConn[0] != nil {
if a.wsConn != expectedConn[0] {
a.mu.Unlock()
return
}
}
if a.wsConn != nil {
_ = a.wsConn.Close()
a.wsConn = nil
}
a.wsConnected = false
shouldStopStreams = a.isStreamingSc || a.isStreamingCam
a.mu.Unlock()
if shouldStopStreams {
a.stopScreenshotStream()
a.stopWebcamStream()
}
}
func (a *App) startScreenshotStream() {