hls.js icon indicating copy to clipboard operation
hls.js copied to clipboard

Allow getting the current URL

Open ibobo opened this issue 1 year ago • 4 comments

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.

ibobo avatar Apr 23 '24 16:04 ibobo

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()?

robwalch avatar Apr 23 '24 18:04 robwalch

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;
}

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 avatar Apr 24 '24 08:04 ibobo

@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.

robwalch avatar May 10 '24 19:05 robwalch

Hi @robwalch I did send a PR, thanks!

ibobo avatar May 12 '24 14:05 ibobo

Shipped in v1.6.0-beta.2

robwalch avatar Dec 11 '24 20:12 robwalch