From bfa7578104ce2922ac6c1f7cd45a03fec4bedca6 Mon Sep 17 00:00:00 2001 From: a-wing <1@233.email> Date: Sun, 31 Dec 2023 00:09:28 +0800 Subject: [PATCH] feat(server): add stream delete --- server/api/api.go | 1 + server/api/v1/stream.go | 12 ++++++++++++ webapp/components/layout.tsx | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/api/api.go b/server/api/api.go index 6b4e682..9f8caa2 100644 --- a/server/api/api.go +++ b/server/api/api.go @@ -40,6 +40,7 @@ func NewApi(rdb *redis.Client, live777Url string, live777Token string) http.Hand //r.Patch("/room/{roomId}", handle.UpdateRoom) r.Post("/room/{roomId}/stream", handle.CreateRoomStream) r.Patch("/room/{roomId}/stream/{streamId}", handle.UpdateRoomStream) + r.Delete("/room/{roomId}/stream/{streamId}", handle.DestroyRoomStream) //r.Post("/room/{roomId}/message", handle.CreateMessage) //r.Get("/room/{roomId}/message", handle.ShowMessage) diff --git a/server/api/v1/stream.go b/server/api/v1/stream.go index 421202f..08cd42b 100644 --- a/server/api/v1/stream.go +++ b/server/api/v1/stream.go @@ -1,6 +1,7 @@ package v1 import ( + "context" "net/http" "woom/server/model" @@ -50,3 +51,14 @@ func (h *Handler) UpdateRoomStream(w http.ResponseWriter, r *http.Request) { room.StreamId = streamId render.JSON(w, r, room) } + +func (h *Handler) DestroyRoomStream(w http.ResponseWriter, r *http.Request) { + roomId := chi.URLParam(r, "roomId") + streamId := chi.URLParam(r, "streamId") + + if err := h.rdb.HDel(context.TODO(), roomId, streamId,).Err(); err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return + } +} diff --git a/webapp/components/layout.tsx b/webapp/components/layout.tsx index eb8af6a..83b94f4 100644 --- a/webapp/components/layout.tsx +++ b/webapp/components/layout.tsx @@ -42,8 +42,10 @@ export default function Layout(props: { meetingId: string }) { } const callEnd = async () => { - // TODO: - // need clear server status + await fetch(`/room/${props.meetingId}/stream/${localStreamId}`, { + method: "DELETE" + }) + setMeetingJoined(false) }