Skip to content

Commit

Permalink
feat(hls): add support for custom headers on hls streams
Browse files Browse the repository at this point in the history
User can provide a map of key value pairs to add as headers when using the hls directive
  • Loading branch information
jimbeck committed Jan 10, 2019
1 parent 997da6e commit 3686fdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/modules/streaming/vg-hls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This module is dependant of `hls.js` library and you need to install via `npm in
| Input | Description |
|--- |--- |
| vgHls | Url to an HLS m3u8 file. |
| vgHlsHeaders | Key/Value pairs that will be added as headers to the m3u8 file. Key is header name. Value is header value. |

## Outputs

Expand All @@ -59,6 +60,7 @@ This module is dependant of `hls.js` library and you need to install via `npm in
<vg-player>
<video #myMedia
[vgHls]="'http://static.videogular.com/assets/videos/videogular.m3u8'"
[vgHlsHeaders]="headers"
(onGetBitrates)="hlsBitrates = $event"
id="my-video"
type="video/mp4"
Expand Down
4 changes: 4 additions & 0 deletions src/streaming/vg-hls/vg-hls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare let Hls;
})
export class VgHLS implements OnInit, OnChanges, OnDestroy {
@Input() vgHls:string;
@Input() vgHlsHeaders: {[key: string]: string} = {};

@Output() onGetBitrates: EventEmitter<BitrateOption[]> = new EventEmitter();

Expand Down Expand Up @@ -59,6 +60,9 @@ export class VgHLS implements OnInit, OnChanges, OnDestroy {
this.config.xhrSetup = (xhr, url) => {
// Send cookies
xhr.withCredentials = true;
for (const key of Object.keys(this.vgHlsHeaders)) {
xhr.setRequestHeader(key, this.vgHlsHeaders[key]);
}
};
}

Expand Down

0 comments on commit 3686fdc

Please sign in to comment.