diff --git a/VLCPlayer.js b/VLCPlayer.js index f7cdca5..01d5ea5 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 d56aa86..e4a1708 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 c346f4c..ede2699 100755 --- a/ios/RCTVLCPlayer/RCTVLCPlayer.m +++ b/ios/RCTVLCPlayer/RCTVLCPlayer.m @@ -120,7 +120,21 @@ - (void)setSource:(NSDictionary *)source // Create dialog provider with custom UI to handle dialogs programmatically self.dialogProvider = [[VLCDialogProvider alloc] initWithLibrary:library customUI:YES]; self.dialogProvider.customRenderer = self; - _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];