Allow getting the current URL
Is your feature request related to a problem? Please describe.
Right now, the url field is private, which means in TypeScript it's not possible to read it, but that would be useful.
Describe the solution you'd like
Provide a public getUrl(): string | null method to access the url value.
Additional context
Right now, from JS there's no problem at all reading the value, in TypeScript you need to do something like (hls as any).url to be able to read it.
Provide a public getUrl(): string | null method to access the url value.
How about making hls.url a getter (read-only)?
private _url: string | null = null; // replaces `url` property
public get url(): string | null {
return this._url;
}
Additional context
Why do you need to read the url passed to loadSource()?
How about making
hls.urla getter (read-only)?private _url: string | null = null; // replaces `url` property public get url(): string | null { return this._url; }
That could even be better, if it doesn't break older code.
Additional context
Why do you need to read the url passed to
loadSource()?
In my case I'm using Hls in a React component and I need to check what url it is playing to avoid stopping and restarting the same stream in some cases.
But, as a principle, I think that being able to read back the data you put into something can always be beneficial in a number of ways.
@ibobo I'd be happy to accept a change in the form of a PR that makes url a public getter on Hls and documents it in API.md.
That could even be better, if it doesn't break older code.
This wouldn't break code that follows hls.js public API or TypeScript definitions. Introspecting or serializing instances or setting url property would not work the same. Since url is currently undocumented and marked as private there is no support for reading or writing it. Any code that does so would need to be updated before doing a minor upgrade.
Hi @robwalch I did send a PR, thanks!
Shipped in v1.6.0-beta.2