-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
added optional request headers for remote assests (android & ios) #805
Conversation
This would be great, I can't wait till this is implemented. |
Great stuff. Any update on this? Would love to see this merged. |
Video.js
Outdated
const strObj = {}; | ||
|
||
Object.keys(obj).forEach(x => { | ||
strObj[x] = obj[x].toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will set objects to [object Object]
- do we want a check here for typeof obj[x]
and to use JSON.stringify
in those cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you're correct - I was kinda of unsure whether to leave it or do a "smarter" string conversion. After your review, I choose the latter. 👍
Conversion is as follows:
- Booleans, numbers, strings =>
prototype.toString
- Objects and nulls =>
JSON.stringify
' - Date =>
prototype.toISOString
undefined
=> returns empty string
@@ -190,6 +200,7 @@ export default class Video extends Component { | |||
type: source.type || '', | |||
mainVer: source.mainVer || 0, | |||
patchVer: source.patchVer || 0, | |||
requestHeaders: source.headers ? this.stringsOnlyObject(source.headers) : {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the key here should be headers
and not requestHeaders
. That or VideoViewManager.PROP_SRC_HEADERS
needs to be changed to requestHeaders
. Without these changes, this line in VideoViewManager:
src.getMap(PROP_SRC_HEADERS)
throws a runtime error due to the fact that 'headers' is not a key on 'src'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! 🙏 I've just pushed updates. I can't test it out on Android right now - it would be nice if you could verify it works. 🙌
Thanks for the reviews btw! 👍
Thank you very much for this! Hope it gets merged asap 🥇 |
Yes please! I hope this gets merged ASAP. This is required for any AES Encrypted video playback. Windows UWP should be possible as well because this is supported. There are samples from the Azure Media Services team. WPF is the only one that should have issues. |
@JohnGalt1717 could you point me in the direction of these samples? I'd love to add support for UWP too |
+1 |
Awesome ! |
@emrah88 I believe it's here: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/AdaptiveStreaming I also have UWP code that works for AES. You can use the Azure Media Player samples library to test the various types as well using that code. That will get you PlayReady, Fairplay, AES and that other one that I can never remember that Google uses. |
@emrah88 I tested your fork on android and got this error, i tried some fixes but my android knowledge is low:
Hope this help :) |
👍 should be great to have this feature merged soon :) |
Any news on this being merged anytime soon? |
Also in need of this! |
@sampurcell93 sorry, when can you merge it? it's really needed feature |
Really need this!!! can I get a merge or a alternative? |
You can of course can fork the pr in the meantime and point to that in your package.json, but yeah definitely needs merging |
It has an error on android
so fork couldn't help in this case @emrah88, sorry, when can you fix it? |
@sanchesking9 I do not have write permissions. |
@isaiahgrey93 sorry, maybe you have write permissions?? |
Thanks for your feedback!! 🙏 🙏 I don't have that much Android experience. Sadly, this PR can't be merged as it is now since the Android player throws errors. No problems in iOS though, I am currently using it production. I've tried to fix it, but I only get the first video playing. As soon as I try to load another video I get exceptions. I'll keep working on it though. For you that are willing to try it out add the following to |
@JohnGalt1717 cool, I'll look in to the AdaptiveStreaming samples |
ios/RCTVideo.m
Outdated
NSURL *url = (isNetwork || isAsset) ? | ||
[NSURL URLWithString:uri] : | ||
[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:uri ofType:type]]; | ||
|
||
if (isNetwork) { | ||
if ([headers count] > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will ignore cookies if you opt to use headers. You should build up the options object so both are supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, good point! 🙌 I see it now 👏
@emrah88 I can get this merged once the remaining issues get resolved. What sort of problems are you running into on Android, I should be able to help you get them sorted out. I left a note on the iOS code. @sampurcell93 Thanks for helping review this. We could use more maintainers, if you'd like to help out lmk and I can get you added. |
Hey @cobarx that sounds great! I should be able to give you some logcat output at Monday. The gist is: first video plays fine first time around, when selecting other video nothing happens. |
@@ -254,7 +254,7 @@ public void setSrc(final String uriString, final String type, final boolean isNe | |||
headers.putAll(toStringMap(mRequestHeaders)); | |||
} | |||
|
|||
setDataSource(uriString); | |||
setDataSource(mThemedReactContext, parsedUrl, headers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In master (of the main repo) no headers are being passed to setDataSource
. Even though the headers HashMap
is being created (lines 247-251) and the cookies are added to it.
Is it me or was the headers never used?
Luckily setDataSource
had an overload that accepted headers which I could pass them to.
hi @emrah88 /Users/user/www/GetAlertReact/node_modules/react-native-video/ios/RCTVideo.m:55:22: warning: designated initializer invoked a non-designated initializer [-Wobjc-designated-initializers]
|
@sanchesking9 thanks for the heads up! |
Ok I've tested this on all 3 platforms, made a few small fixes, and it's working great! There are only 2 things I noticed that were worth mentioning. All the data is showing up in the Apache logs URL encoded. For example:
becomes:
I don't know if this is an issue or not as I don't have a web app setup for testing headers. I suppose I can throw something together pretty quick in PHP and check it. Also, as a general coding convention I tend to like keeping the variable names the same throughout. Is there any reason we need to switch back and forth between I went ahead and added a note about changing the Android MediaPlayer setDataSource call so we can know what's up if someone reports an issue. This thing is pretty much ready to merge. I also need to go through and document it, which I'll probably do in another PR. @JohnGalt1717 If you have time to add UWP support that would be fantastic. |
I'm burried at the moment but will see if I can get some bandwidth soon to take a look. |
I need to pass a header with a video access authorization token, since I want to block the external access in .htaccess and open access only by the mobile phone through a token. I'm using Android
|
This feature isn't in 2.3.1, it's only available on the master branch. I'll be releasing 3.0 with it later today. |
thank, very much |
@cobarx thanks for the awesome job and putting this together! I'll look out for any mentions regarding the changes to Regarding the Apache Logs, did you figure out something? I'll try do some request to my IIS server too see if I get the same encoding. Regarding the naming of |
Is there any sort of documentation for this? I can't seem to pass my Authorization header successfully. |
@YoranRoels I've added docs to the README. It only works out of the box on ExoPlayer, it's disabled by default on iOS because the code uses a private API that could get the app rejected from the App Store. The README has instructions for enabling it. To troubleshoot, you can set breakpoints in the native code. Also, enable logging on your server to make sure the headers are arriving. |
This pull request adds support for setting arbitrary
Request Headers
for resolving remote media. A use case could be to add anAuthorization
header for media that needs authentication. Therefore this PR should be able to close #475.It can be used as demonstrated in the snippet below, by adding a
headers
object in thesource
property of theVideo
component.It has been tested on iOS and Android.
Note: It was currently not possible to add the same functionality for Windows.
System.Windows.Media.MediaPlayer
only supports a singleUri
class for remote/local media.