Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem when accessing video from chrome or other browser: #50

Closed
fherking opened this issue Dec 28, 2023 · 6 comments
Closed

problem when accessing video from chrome or other browser: #50

fherking opened this issue Dec 28, 2023 · 6 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@fherking
Copy link

Hello:
I configured the server (i think that ok), when I watch movies from mpc-hc or vlc I can access the file, transcode is good and I can view the file from any machine

when I try to access the file from an html through a web broser I get the following error:

xxxxx.html:1 Access to XMLHttpRequest at 'http://192.168.10.3:44444/vod/xxxx/yyy/360p.m3u8' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there any way to set cross origin policy on the server ( even if i need to change the source code and recompile) or I'm doing something wrong?

thanks in advance

@m1k1o
Copy link
Owner

m1k1o commented Dec 30, 2023

Hello, CORS is missing.

It is not part of the codebae but could be added easily. Using this code.

Or you could just make sure that the oriign where you play the video is the same as the go-transcode. By using reverse proxy.

E.g:

  • point /vod/* on your reverse proxy to 192.168.10.3:44444/vod/
  • everything else to your nginx server/backend that will serve player to play the videos.

That means when you play your video on example.com/player.html it needs to request videos from /vod/* and it matches origin policy.

@m1k1o m1k1o added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 30, 2023
@fherking
Copy link
Author

​Hello, thanks, for your answer and time, i'm gonna compile now the server with the new code you sent me and see if it works, because i don't have a reverse proxy setup at the moment...
(Yes I know its a couple of lines in apache but , I configured one once upon a time and alzhéimer is kicking in... if It doesn't work I tell you something about my setup ... )

Thanks and
cute-cat-kitten-greeting-cartoon-doodle-background-wallpaper-free-vector

@fherking
Copy link
Author

fherking commented Dec 30, 2023

Ok, its working now (at least it seems) had to :

go import "github.com/go-chi/cors"
modify :
./go-transcode/internal/http/http.go
add imports to that file
"github.com/go-chi/cors"
and the code i used is where the router is created :


	router.Use(cors.Handler(cors.Options{
		AllowOriginFunc:  conf.AllowOrigin, <-deleted this line, giving me errors about conf/config object not having the function.... it seems to be working anyway.
		AllowedMethods:   []string{"GET", "POST", "DELETE", "OPTIONS"},
		AllowedHeaders:   []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
		ExposedHeaders:   []string{"Link"},
		AllowCredentials: true,
		MaxAge:           300, // Maximum value not ignored by any of major browsers
	}))

I still am not able to play anything in chrome , edge , firefox and firedragon, BUT at least its not complaining about security concerns (all dev tools give ok 200 to all files) and in media player classic and vlc plays ok.

I suppose that it fails for the codec.

For the moment Im trying different js players to see if someone works with this hls file format / codec , if you know anyone that works, that would be a plus.

THANKS for your time and patience

For me this problem is closed as valid.

As always, thanks for your time and help.

@m1k1o
Copy link
Owner

m1k1o commented Dec 31, 2023

I use video.js with http-streaming plugin, works most of the time for me:
https://github.com/m1k1o/go-transcode/blob/f7cf54dbf7cde826d8a8be58f18a6375ddbf6f4c/internal/api/play.html

@fherking
Copy link
Author

fherking commented Dec 31, 2023 via email

@m1k1o m1k1o closed this as completed in 4c25571 Jan 26, 2024
@m1k1o
Copy link
Owner

m1k1o commented Jan 26, 2024

Added cors: [bool] to config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants