From 000ebaef8b5ab4dcacc9d211de0cc406dcd33e0a Mon Sep 17 00:00:00 2001 From: shay <43248357+shayypy@users.noreply.github.com> Date: Mon, 18 Aug 2025 10:45:02 -0500 Subject: [PATCH] feat(ios): support cookies for http/s media related to #8 --- VLCPlayer.js | 1 + index.d.ts | 21 +++++++++++++++++++++ ios/RCTVLCPlayer/RCTVLCPlayer.m | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/VLCPlayer.js b/VLCPlayer.js index 0b90a46..12a682b 100755 --- a/VLCPlayer.js +++ b/VLCPlayer.js @@ -183,6 +183,7 @@ export default class VLCPlayer extends Component { source.isNetwork = isNetwork; source.autoplay = this.props.autoplay; source.initOptions = source.initOptions || []; + source.cookies = source.cookies || []; if (this.props.repeat) { const existingRepeat = source.initOptions.find(item => item.startsWith('--repeat') || item.startsWith('--input-repeat')); diff --git a/index.d.ts b/index.d.ts index d586dd4..00ee1f2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,6 +43,27 @@ export interface VLCPlayerSource { * @default [] */ initOptions?: string[]; + /** + * Cookie jar to fetch HTTP/HTTPS media with. Cookies for non-applicable + * hosts will be ignored. Not supported on MacOS. + * + * From VLCKit's documentation: + * > Parse a value of an incoming Set-Cookie header (see RFC 6265) and + * > append the cookie to the stored cookies if appropriate. The "secure" + * > attribute can be added to cookie to limit the scope of the cookie to + * > secured channels (https). + * + * @example ```js + * [{ value: "name=value; Path=/; Domain=example.com", host: "example.com", path: "/" }] + * ``` + * + * @default [] + */ + cookies?: { + value: string; + host: string; + path: string; + }[]; } /** diff --git a/ios/RCTVLCPlayer/RCTVLCPlayer.m b/ios/RCTVLCPlayer/RCTVLCPlayer.m index 976fab7..3b4a325 100755 --- a/ios/RCTVLCPlayer/RCTVLCPlayer.m +++ b/ios/RCTVLCPlayer/RCTVLCPlayer.m @@ -106,7 +106,20 @@ - (void)setSource:(NSDictionary *)source _player.drawable = self; // [bavv edit end] - _player.media = [VLCMedia mediaWithURL:uri]; + VLCMedia* media = [VLCMedia mediaWithURL:uri]; + + NSArray* cookiesArray = [source objectForKey:@"cookies"]; + for (id cookieDict in cookiesArray) { + NSString* value = [cookieDict objectForKey:@"value"]; + NSString* host = [cookieDict objectForKey:@"host"]; + NSString* path = [cookieDict objectForKey:@"path"]; + int cookieStatus = [media storeCookie:value forHost:host path:path]; + if (cookieStatus != 0) { + NSLog(@"Failed to store cookie: %@", cookieStatus); + } + } + + _player.media = media; if (_autoplay) [_player play];