Can ask student browser where they are in the page
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
86cc2cad4a
commit
ff5cefa7ac
3 changed files with 79 additions and 7 deletions
29
direct.go
29
direct.go
|
|
@ -35,7 +35,7 @@ func declareAPIAdminDirectRoutes(router *gin.RouterGroup) {
|
|||
}
|
||||
|
||||
func WSSurveyStats(sid int64) map[string]interface{} {
|
||||
var users []string
|
||||
var users []map[string]interface{}
|
||||
var nb int
|
||||
|
||||
WSClientsMutex.RLock()
|
||||
|
|
@ -43,7 +43,10 @@ func WSSurveyStats(sid int64) map[string]interface{} {
|
|||
if w, ok := WSClients[sid]; ok {
|
||||
nb = len(w)
|
||||
for _, ws := range w {
|
||||
users = append(users, ws.u.Login)
|
||||
users = append(users, map[string]interface{}{
|
||||
"id": ws.u.Id,
|
||||
"login": ws.u.Login,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,6 +142,26 @@ func SurveyWS(c *gin.Context) {
|
|||
ch <- msgCurrentState(survey)
|
||||
|
||||
go SurveyWS_run(ws, ch, survey.Id, u)
|
||||
go func(c chan WSMessage, sid int) {
|
||||
var v WSMessage
|
||||
var err error
|
||||
for {
|
||||
err = wsjson.Read(context.Background(), ws, &v)
|
||||
if err != nil {
|
||||
log.Println("Error when receiving message:", err)
|
||||
close(c)
|
||||
break
|
||||
}
|
||||
|
||||
if v.Action == "myscroll" {
|
||||
v.UserId = &u.Id
|
||||
v.SurveyId = &survey.Id
|
||||
WSAdminWriteAll(v)
|
||||
} else {
|
||||
log.Println("Unknown ws response:", v.Action)
|
||||
}
|
||||
}
|
||||
}(ch, int(survey.Id))
|
||||
}
|
||||
|
||||
func WSWriteAll(message WSMessage) {
|
||||
|
|
@ -423,6 +446,8 @@ func SurveyWSAdmin(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if v.Action == "where_are_you" {
|
||||
survey.WSWriteAll(v)
|
||||
} else {
|
||||
log.Println("Unknown admin action:", v.Action)
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue