feat: release hand endpoint & button
This commit is contained in:
parent
b90fcc3f20
commit
b1f2e896b9
|
@ -35,11 +35,10 @@ func (r *Room)InitMaps() {
|
|||
// if you are speaking - change nothing
|
||||
// if nobody is speaking, set this person as a first speaker
|
||||
func (r *Room) RaiseHand(p PersonId, gesture HandGesture) Room {
|
||||
// TODO This is temporary
|
||||
// if (r.CurrentSpeaker == p) {
|
||||
// // if person already speaking, should first end speaking
|
||||
// return *r
|
||||
// }
|
||||
if (r.CurrentSpeaker == p) {
|
||||
// if person already speaking, should first end speaking
|
||||
return *r
|
||||
}
|
||||
r.ParticipantHands[p] = gesture
|
||||
if r.CurrentSpeaker == PersonId(0) {
|
||||
r.CurrentSpeaker = p
|
||||
|
|
|
@ -227,8 +227,10 @@ func joinRoomHandler(templateFs *embed.FS,
|
|||
Id: rooms.RandomPersonId(),
|
||||
}
|
||||
err := roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
log.Printf("/login/join about to modify room %+v", fromRoom)
|
||||
toRoom = fromRoom
|
||||
toRoom.AllKnownPeople = append(toRoom.AllKnownPeople, person)
|
||||
log.Printf("/login/join will save %+v", toRoom)
|
||||
return toRoom
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -244,6 +246,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
|||
// and we've checked password
|
||||
|
||||
err = roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
toRoom = fromRoom
|
||||
toRoom.Paricipants = append(toRoom.Paricipants, person.Id)
|
||||
return toRoom
|
||||
})
|
||||
|
|
|
@ -2,7 +2,6 @@ package routes
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
|
@ -33,7 +32,10 @@ func registerPageRoutes(
|
|||
http.Handle(raiseHandPath, // ending in / captures all following path sections, i.e gesture num
|
||||
authedPageMiddleware(
|
||||
sessionSM,
|
||||
http.StripPrefix(raiseHandPath, raiseGestureHandRoute(templateFs, roomsM))))
|
||||
http.StripPrefix(raiseHandPath, raiseGestureHandRoute(roomsM))))
|
||||
|
||||
http.Handle("/rooms/releaseHand",
|
||||
authedPageMiddleware(sessionSM, releaseHandRoute(roomsM)))
|
||||
|
||||
http.Handle(subscribeRoomPath,
|
||||
authedPageMiddleware(
|
||||
|
@ -94,7 +96,6 @@ func streamingRoomStates(
|
|||
|
||||
// if currently speaking? i guess first lower the hand and then raise new
|
||||
func raiseGestureHandRoute(
|
||||
templateFs *embed.FS,
|
||||
roomsM rooms.RoomManager,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -112,7 +113,7 @@ func raiseGestureHandRoute(
|
|||
return
|
||||
}
|
||||
var outerClosureRoom rooms.Room
|
||||
err = roomsM.Update(context.TODO(), session.RoomId, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
err = roomsM.Update(r.Context(), session.RoomId, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
toRoom = fromRoom.RaiseHand(session.PersonId, gesture)
|
||||
outerClosureRoom = toRoom
|
||||
return toRoom
|
||||
|
@ -130,6 +131,30 @@ func raiseGestureHandRoute(
|
|||
}
|
||||
}
|
||||
|
||||
func releaseHandRoute(
|
||||
roomsM rooms.RoomManager,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, found := getContextSession(r.Context())
|
||||
if !found {
|
||||
log.Printf("/rooms/releaseHand session not found, should be impossible")
|
||||
// TODO return error i guess
|
||||
return
|
||||
}
|
||||
err := roomsM.Update(r.Context(), session.RoomId, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
toRoom = fromRoom
|
||||
toRoom.ReleaseHand(session.PersonId)
|
||||
return toRoom
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("/rooms/releaseHand error saving hand: %s\n", err)
|
||||
return
|
||||
// TODO return error i guess
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
|
||||
func roomPageRoute(
|
||||
templateFs *embed.FS,
|
||||
roomsM rooms.RoomManager,
|
||||
|
|
|
@ -598,6 +598,10 @@ video {
|
|||
border-width: 2px;
|
||||
}
|
||||
|
||||
.border-4 {
|
||||
border-width: 4px;
|
||||
}
|
||||
|
||||
.border-black {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(0 0 0 / var(--tw-border-opacity));
|
||||
|
@ -608,6 +612,11 @@ video {
|
|||
border-color: rgb(29 78 216 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-yellow-700 {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(161 98 7 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.bg-amber-400 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(251 191 36 / var(--tw-bg-opacity));
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
id="roomTextContainer"
|
||||
class="bg-blue-200"
|
||||
hx-ext="sse"
|
||||
sse-connect="/rooms/subscribe?roomName=test"
|
||||
sse-connect="/rooms/subscribe?roomName={{ .Room.Name }}"
|
||||
>
|
||||
{{ block "simpleRoomShow" .Room }}
|
||||
<!-- TODO use template, not block, have only 'loader' in base place -->
|
||||
|
@ -53,6 +53,11 @@
|
|||
{{ .Name }}
|
||||
</button>
|
||||
{{ end }}
|
||||
<button hx-get="/rooms/releaseHand"
|
||||
class="bg-white rounded border-yellow-700 border-4"
|
||||
>
|
||||
Release Hand
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue