memberId to sessionId.

This commit is contained in:
Miroslav Šedivý 2021-03-13 23:32:10 +01:00
parent d83e04e7ec
commit b03a730c84
2 changed files with 14 additions and 11 deletions

View File

@ -42,7 +42,7 @@ func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) {
session := auth.GetSession(r)
if !session.CanHost() {
utils.HttpBadRequest(w, "Member is not allowed to host.")
utils.HttpBadRequest(w, "Session is not allowed to host.")
return
}
@ -54,12 +54,12 @@ func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) {
func (h *RoomHandler) controlRelease(w http.ResponseWriter, r *http.Request) {
session := auth.GetSession(r)
if !session.IsHost() {
utils.HttpUnprocessableEntity(w, "Member is not the host.")
utils.HttpUnprocessableEntity(w, "Session is not the host.")
return
}
if !session.CanHost() {
utils.HttpBadRequest(w, "Member is not allowed to host.")
utils.HttpBadRequest(w, "Session is not allowed to host.")
return
}
@ -72,7 +72,7 @@ func (h *RoomHandler) controlRelease(w http.ResponseWriter, r *http.Request) {
func (h *RoomHandler) controlTake(w http.ResponseWriter, r *http.Request) {
session := auth.GetSession(r)
if !session.CanHost() {
utils.HttpBadRequest(w, "Member is not allowed to host.")
utils.HttpBadRequest(w, "Session is not allowed to host.")
return
}
@ -82,16 +82,16 @@ func (h *RoomHandler) controlTake(w http.ResponseWriter, r *http.Request) {
}
func (h *RoomHandler) controlGive(w http.ResponseWriter, r *http.Request) {
memberId := chi.URLParam(r, "memberId")
sessionId := chi.URLParam(r, "sessionId")
target, ok := h.sessions.Get(memberId)
target, ok := h.sessions.Get(sessionId)
if !ok {
utils.HttpNotFound(w, "Target member was not found.")
utils.HttpNotFound(w, "Target session was not found.")
return
}
if !target.CanHost() {
utils.HttpBadRequest(w, "Target member is not allowed to host.")
utils.HttpBadRequest(w, "Target session is not allowed to host.")
return
}

View File

@ -23,11 +23,12 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
return nil
}
// TODO: Sessions.
members := map[string]message.MemberData{}
for _, session := range h.sessions.List() {
memberId := session.ID()
members[memberId] = message.MemberData{
ID: memberId,
sessionId := session.ID()
members[sessionId] = message.MemberData{
ID: sessionId,
Profile: session.GetProfile(),
State: session.GetState(),
}
@ -36,6 +37,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
return session.Send(
message.SystemInit{
Event: event.SYSTEM_INIT,
// TODO: Session ID.
MemberId: session.ID(),
ControlHost: controlHost,
ScreenSize: message.ScreenSize{
@ -43,6 +45,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
Height: size.Height,
Rate: size.Rate,
},
// TODO: Sessions.
Members: members,
ImplicitHosting: h.sessions.ImplicitHosting(),
})