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

Add crossdomain support in http_remux and hls for HTML5 playback #691

Closed
wants to merge 1 commit into from

Conversation

xqq
Copy link

@xqq xqq commented Nov 14, 2016

For flv.js or hls.js HTML5 playback,
CORS header (Access-Control-Allow-Origin) is necessary for ajax stream fetching.

This pull request adds crossdomain on; config support in http_remux and hls block,
which will emit Access-Control-Allow-Origin: * header in http-flv stream or hls m3u8/ts GET request.

CORS header will not affect exisiting service, so it is turned on by default for now.

Changes may be inappropriate, suggestion or modification please!

@winlinvip
Copy link
Member

winlinvip commented Nov 17, 2016

Crossdomain should not be specified through configuration. It can be determined based on the request. If a crossdomain request is made, it should be included in the response. Additionally, the headers should not only include ALLOW ORIGIN, but also specify the allowed methods using ALLOW METHODS. You can refer to the handling of HTTP APIs for guidance.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Nov 17, 2016

In addition, if it can be achieved through an HTTP proxy, such as using ORYXY's HTTPLB proxy once, with cross-origin support, it will be much simpler.

TRANS_BY_GPT3

@xqq
Copy link
Author

xqq commented Nov 17, 2016

Because OPTIONS is not necessary in normal live streaming scenarios, Allow Methods should be unnecessary.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 15, 2016

I made a GET request for http-flv using JavaScript, which should require ALLOW: GET request. Additionally, it seems that JavaScript cannot directly access this type of long connection http-flv. Is there a new standard that supports it?

Access-Control-Request-Headers:content-type
Access-Control-Request-Method:GET
Origin:http://ossrs.net
Referer:http://ossrs.net/srs.release/http-rest/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36

HTTP Request Tool:
http://ossrs.net/srs.release/http-rest/

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 15, 2016

In addition, this belongs to the functionality and will definitely not be added in SRS2. I will include this feature in the develop.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 15, 2016

f30b307

I first improved part of the HTTP-API and made changes to conveniently support CORS for HTTP-FLV.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 15, 2016

In addition, we are planning to remove HLS RAM as it does not support memory distribution for HLS. It can be achieved using memory disks, which unnecessarily adds a lot of complexity.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 15, 2016

Already supported, but I couldn't make it work in chrome54. I guess it's because I'm not using the correct way to initiate the xhr request. You can give it a try, it's added in 3.0.9.

TRANS_BY_GPT3

@winlinvip winlinvip closed this Dec 15, 2016
@xqq
Copy link
Author

xqq commented Dec 15, 2016

  1. To play a live stream, simply use a GET request without adding the Content-Type header in the request. Therefore, it will not initiate an OPTIONS request, and there is no need for the server to respond with Access-Control-Allow-Methods and Access-Control-Allow-Headers.

  2. The xhr standard specification will not add streaming functionality anymore. Currently, the fetch and stream standard APIs support streaming.
    Refer to https://github.com/Bilibili/flv.js/blob/master/src/io/fetch-stream-loader.js
    Fetch+stream is the future trend (although currently only Chrome has fully implemented this), while other browsers are in an incomplete implementation state. However, FireFox can use Mozilla's xhr extension responseType = 'moz-chunked-arraybuffer'.

  3. You can directly test HTTP-FLV live streaming using flv.js.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Dec 16, 2016

Understood, it's not xhr, it's a new JS API.
So, is the current solution problematic? Do we need to make any modifications?

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Mar 6, 2017

Long time no response, create a new #798 memo.

TRANS_BY_GPT3

@LF-DevJourney
Copy link

LF-DevJourney commented Jul 31, 2017

When using flv.js to play FLV, there may be a cross-origin issue. To solve this, add w->header()->set("Access-Control-Allow-Origin", "*"); after srs_app_http_stream.cpp to set Access-Control-Allow-Origin. For security reasons, * can be replaced with a specific value.

TRANS_BY_GPT3

@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants