Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't store multiple Widgets #290

Open
nnra6864 opened this issue Apr 7, 2024 · 0 comments
Open

Can't store multiple Widgets #290

nnra6864 opened this issue Apr 7, 2024 · 0 comments
Labels

Comments

@nnra6864
Copy link

nnra6864 commented Apr 7, 2024

Can't store multiple Widgets

Issue found of: April 6th, 2024.

Issue

Whilst using the SoundCloud API, I ran into a really annoying issue that actually took me several hours to debug.
SC.Widget(songIFrame) doesn't return a new instance of a widget for the said iframe but (my best guess) sets the internal field widget of SC to the new value and returns a reference to that field.
This is an issue if you want to have multiple players at once and, for example, change their volumes.
Instead of simply being able to store the widget once and use that value later, you have to set the widget field's value to the iframe you wanna affect and then set the volume of the updated widget.
Here's how the code should look like:

const song = document.createElement('iframe');
song.src = `https://w.soundcloud.com/player/?url=${encodeURIComponent(element.Content)}`;

const songWidget = SC.Widget(song);
volumeSlider.addEventListener('input', (event) => {
    songWidget.setVolume(event.target.value);
});

Here's a workaround you have to do in order to make it work:

const song = document.createElement('iframe');
song.src = `https://w.soundcloud.com/player/?url=${encodeURIComponent(element.Content)}`;

volumeSlider.addEventListener('input', (event) => {
    SC.Widget(song).setVolume(event.target.value);
});

You can find the full implementation here.

Reasons to fix

It is fairly unintuitive and hard to use.
Some things might not be doable with the current implementation.

Solution

In order to keep the functionality of old codebases, simply add a new function, eg. SC.WidgetInstance(), that would return the actual instance of a widget instead of returning a reference to some field inside of SC.
This way, the API would be fully compatible with previously written code whilst allowing for a new, intuitive approach for multiple widgets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants