@@ -43,16 +43,14 @@ func InitWhipServer(config *whipConfig) error {
4343
4444 httpServerMux := http .NewServeMux ()
4545
46- httpServerMux .HandleFunc ("/whip" , func (w http.ResponseWriter , r * http.Request ) {
47-
46+ httpServerMux .HandleFunc ("OPTIONS /whip" , func (w http.ResponseWriter , r * http.Request ) {
4847 w .Header ().Add ("Access-Control-Allow-Origin" , "*" )
4948 w .Header ().Add ("Access-Control-Allow-Methods" , "POST" )
5049 w .Header ().Add ("Access-Control-Allow-Headers" , "*" )
5150 w .Header ().Add ("Access-Control-Allow-Headers" , "Authorization" )
52-
53- if r .Method == http .MethodOptions {
54- return
55- }
51+ })
52+
53+ httpServerMux .HandleFunc ("POST /whip" , func (w http.ResponseWriter , r * http.Request ) {
5654
5755 if ! WhipConfig .Enabled .IsEnabled () {
5856 w .WriteHeader (http .StatusInternalServerError )
@@ -68,6 +66,11 @@ func InitWhipServer(config *whipConfig) error {
6866 return
6967 }
7068 }()
69+
70+ w .Header ().Add ("Access-Control-Allow-Origin" , "*" )
71+ w .Header ().Add ("Access-Control-Allow-Methods" , "POST" )
72+ w .Header ().Add ("Access-Control-Allow-Headers" , "*" )
73+ w .Header ().Add ("Access-Control-Allow-Headers" , "Authorization" )
7174
7275 for _ , s := range * WhipConfig .ICEServers .Load () {
7376 for _ , url := range s .URLs {
@@ -123,7 +126,7 @@ func InitWhipServer(config *whipConfig) error {
123126 log .Printf ("Sending answer for whip: %s\n " , answerStruct .Answer .SDP )
124127
125128 w .Header ().Set ("Content-Type" , "application/sdp" )
126- w .Header ().Add ("Location" , "/ whip" )
129+ w .Header ().Add ("Location" , fmt . Sprintf ( "http://localhost:%d/ whip", config . Port ) )
127130
128131 w .WriteHeader (http .StatusCreated )
129132 _ , _ = w .Write ([]byte (answerStruct .Answer .SDP ))
0 commit comments