feat: release hand endpoint & button

This commit is contained in:
efim 2023-11-12 18:24:32 +00:00
parent b90fcc3f20
commit b1f2e896b9
5 changed files with 51 additions and 10 deletions

View File

@ -35,11 +35,10 @@ func (r *Room)InitMaps() {
// if you are speaking - change nothing // if you are speaking - change nothing
// if nobody is speaking, set this person as a first speaker // if nobody is speaking, set this person as a first speaker
func (r *Room) RaiseHand(p PersonId, gesture HandGesture) Room { func (r *Room) RaiseHand(p PersonId, gesture HandGesture) Room {
// TODO This is temporary if (r.CurrentSpeaker == p) {
// if (r.CurrentSpeaker == p) { // if person already speaking, should first end speaking
// // if person already speaking, should first end speaking return *r
// return *r }
// }
r.ParticipantHands[p] = gesture r.ParticipantHands[p] = gesture
if r.CurrentSpeaker == PersonId(0) { if r.CurrentSpeaker == PersonId(0) {
r.CurrentSpeaker = p r.CurrentSpeaker = p

View File

@ -227,8 +227,10 @@ func joinRoomHandler(templateFs *embed.FS,
Id: rooms.RandomPersonId(), Id: rooms.RandomPersonId(),
} }
err := roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) { 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 = fromRoom
toRoom.AllKnownPeople = append(toRoom.AllKnownPeople, person) toRoom.AllKnownPeople = append(toRoom.AllKnownPeople, person)
log.Printf("/login/join will save %+v", toRoom)
return toRoom return toRoom
}) })
if err != nil { if err != nil {
@ -244,6 +246,7 @@ func joinRoomHandler(templateFs *embed.FS,
// and we've checked password // and we've checked password
err = roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) { err = roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
toRoom = fromRoom
toRoom.Paricipants = append(toRoom.Paricipants, person.Id) toRoom.Paricipants = append(toRoom.Paricipants, person.Id)
return toRoom return toRoom
}) })

View File

@ -2,7 +2,6 @@ package routes
import ( import (
"bytes" "bytes"
"context"
"embed" "embed"
"fmt" "fmt"
"html/template" "html/template"
@ -33,7 +32,10 @@ func registerPageRoutes(
http.Handle(raiseHandPath, // ending in / captures all following path sections, i.e gesture num http.Handle(raiseHandPath, // ending in / captures all following path sections, i.e gesture num
authedPageMiddleware( authedPageMiddleware(
sessionSM, sessionSM,
http.StripPrefix(raiseHandPath, raiseGestureHandRoute(templateFs, roomsM)))) http.StripPrefix(raiseHandPath, raiseGestureHandRoute(roomsM))))
http.Handle("/rooms/releaseHand",
authedPageMiddleware(sessionSM, releaseHandRoute(roomsM)))
http.Handle(subscribeRoomPath, http.Handle(subscribeRoomPath,
authedPageMiddleware( authedPageMiddleware(
@ -94,7 +96,6 @@ func streamingRoomStates(
// if currently speaking? i guess first lower the hand and then raise new // if currently speaking? i guess first lower the hand and then raise new
func raiseGestureHandRoute( func raiseGestureHandRoute(
templateFs *embed.FS,
roomsM rooms.RoomManager, roomsM rooms.RoomManager,
) http.HandlerFunc { ) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
@ -112,7 +113,7 @@ func raiseGestureHandRoute(
return return
} }
var outerClosureRoom rooms.Room 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) toRoom = fromRoom.RaiseHand(session.PersonId, gesture)
outerClosureRoom = toRoom outerClosureRoom = toRoom
return 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( func roomPageRoute(
templateFs *embed.FS, templateFs *embed.FS,
roomsM rooms.RoomManager, roomsM rooms.RoomManager,

View File

@ -598,6 +598,10 @@ video {
border-width: 2px; border-width: 2px;
} }
.border-4 {
border-width: 4px;
}
.border-black { .border-black {
--tw-border-opacity: 1; --tw-border-opacity: 1;
border-color: rgb(0 0 0 / var(--tw-border-opacity)); 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-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 { .bg-amber-400 {
--tw-bg-opacity: 1; --tw-bg-opacity: 1;
background-color: rgb(251 191 36 / var(--tw-bg-opacity)); background-color: rgb(251 191 36 / var(--tw-bg-opacity));

View File

@ -35,7 +35,7 @@
id="roomTextContainer" id="roomTextContainer"
class="bg-blue-200" class="bg-blue-200"
hx-ext="sse" hx-ext="sse"
sse-connect="/rooms/subscribe?roomName=test" sse-connect="/rooms/subscribe?roomName={{ .Room.Name }}"
> >
{{ block "simpleRoomShow" .Room }} {{ block "simpleRoomShow" .Room }}
<!-- TODO use template, not block, have only 'loader' in base place --> <!-- TODO use template, not block, have only 'loader' in base place -->
@ -53,6 +53,11 @@
{{ .Name }} {{ .Name }}
</button> </button>
{{ end }} {{ end }}
<button hx-get="/rooms/releaseHand"
class="bg-white rounded border-yellow-700 border-4"
>
Release Hand
</button>
</div> </div>
</div> </div>
</body> </body>