Live video on the AT Protocol
at eli/too-many-keyframes 42 lines 1.1 kB view raw
1package api 2 3import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 "net/http" 8 9 "github.com/julienschmidt/httprouter" 10 "stream.place/streamplace/pkg/atproto" 11 "stream.place/streamplace/pkg/log" 12) 13 14func (a *StreamplaceAPI) HandleDidJSON(ctx context.Context) httprouter.Handle { 15 return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) { 16 host := a.CLI.BroadcasterHost 17 didJSON := atproto.DIDDoc(host) 18 w.WriteHeader(200) 19 w.Header().Set("Content-Type", "application/json") 20 bs, err := json.Marshal(didJSON) 21 if err != nil { 22 log.Error(ctx, "could not marshal did json", "error", err) 23 return 24 } 25 if _, err := w.Write(bs); err != nil { 26 log.Error(ctx, "error writing response", "error", err) 27 } 28 } 29} 30 31func (a *StreamplaceAPI) HandleAtprotoDID(ctx context.Context) httprouter.Handle { 32 return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) { 33 did := a.CLI.AtprotoDID 34 if did == "" { 35 did = fmt.Sprintf("did:web:%s", a.CLI.BroadcasterHost) 36 } 37 _, err := fmt.Fprintf(w, "%s", did) 38 if err != nil { 39 log.Error(ctx, "error writing response", "error", err) 40 } 41 } 42}