add: basic webrtc is working

This commit is contained in:
Charles Hathaway
2023-09-28 20:35:50 -07:00
parent 7fbd4fff69
commit 19bb6c49b4
22 changed files with 2615 additions and 330 deletions
+37 -1
View File
@@ -8,6 +8,9 @@ import (
"connectrpc.com/grpcreflect"
servicepb "github.com/chathaway-codes/home-sensors/v2/gen/genconnect"
"github.com/chathaway-codes/home-sensors/v2/pkg/signaler"
"github.com/rs/cors"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
func main() {
@@ -26,7 +29,40 @@ func main() {
fmt.Printf("Got path %s\n", path)
mux.Handle(servicepb.NewSignalerServiceHandler(signaler.New()))
if err := http.ListenAndServe("127.0.0.1:8080", mux); err != nil {
corsHandler := cors.New(cors.Options{
AllowedMethods: []string{
http.MethodGet,
http.MethodPost,
},
AllowedOrigins: []string{"example.com"},
AllowedHeaders: []string{
"Accept-Encoding",
"Authorization",
"Content-Encoding",
"Content-Type",
"Connect-Protocol-Version",
"Connect-Timeout-Ms",
"Connect-Accept-Encoding", // Unused in web browsers, but added for future-proofing
"Connect-Content-Encoding", // Unused in web browsers, but added for future-proofing
"Grpc-Timeout", // Used for gRPC-web
"X-Grpc-Web", // Used for gRPC-web
"X-User-Agent", // Used for gRPC-web
},
ExposedHeaders: []string{
"Content-Encoding", // Unused in web browsers, but added for future-proofing
"Connect-Content-Encoding", // Unused in web browsers, but added for future-proofing
"Grpc-Status", // Required for gRPC-web
"Grpc-Message", // Required for gRPC-web
},
})
handler := corsHandler.Handler(mux)
server := &http.Server{
Addr: "0.0.0.0:8080",
Handler: h2c.NewHandler(handler, &http2.Server{}),
}
if err := server.ListenAndServe(); err != nil {
log.Fatalf("Failed to listen for HTTP traffic: %v", err)
}
}