Skip to content

Conversation

@Florent-Bouisset
Copy link
Collaborator

@Florent-Bouisset Florent-Bouisset commented Feb 28, 2024

The RxPlayer was not designed to run multiple instance of RxPlayer with the same videoElement. Having multiple instance sharing the same video element would result in various issues and unexpected behavior.

This commit adds a check to throw an error if a videoElement is shared between RxPlayer instances. This will provide better guidance to application developers regarding any errors in their implementation.

Relates to #1390

element in multiple instance of the RxPlayer

The RxPlayer was not designed to run multiple instance of
RxPlayer with the same videoElement. Having multiple instance sharing
the same video element would result in various issues and unexpected
behavior.

This commit adds a check to throw an error if a videoElement is shared
between RxPlayer instances. This will provide better guidance to
application developers regarding any errors in their implementation.
@Florent-Bouisset Florent-Bouisset changed the title api: throw and error if an application use a video element in multiple instance of the RxPlayer api: throw an error if an application use a video element in multiple instance of the RxPlayer Feb 28, 2024
in the demo.

Commit 57fd4b9 added an error message
if the video element is reused between RxPlayer instance.
This was the case on the demo, and this commit ensure to dispose the
previous instance before creating a new one.
@peaBerberian
Copy link
Collaborator

Even if I like the improvement, this may break usage where application codes didn't destroy previous instances, though it would probably have lead to minor issues before like the one we have seen.

For example, even our demo page would now be broke if we didn't update it.

I'm not even sure the API documentation was clear enough about the one RxPlayer per video element rule, so we may have to make it very clear in our release note that this may break some previous usages.

What do you think about this?

@Florent-Bouisset
Copy link
Collaborator Author

I'm not even sure the API documentation was clear enough about the one RxPlayer per video element rule, so we may have to make it very clear in our release note that this may break some previous usages.

I was wondering too if this should be considered as a breaking change.
We can keep this dev for a future v5 but this will be in a long time since we just released 4.0.
Eventually we can include it in a minor update 4.1 because there is no changes in the prototype of the API but still there is changes to the behavior.

@Florent-Bouisset
Copy link
Collaborator Author

I liked you suggestion to only display a console.error() for the time, and then update it to throw an error in the version 5. I will do that

});

describe("Player instantiation", () => {
it("should throw an error if creating two players attached to the same video element", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording of the test case to update.

Same for the next one

* @throws Error - Throws if the element is already used by another player instance.
*/
private static _priv_registerVideoElement(videoElement: HTMLMediaElement) {
const errorMessage =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why declaring the errorMessage variable outside the if?

It would make more sense when reading if it comes after the related check, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I changed it

@peaBerberian peaBerberian merged commit 0fe59ed into dev Mar 11, 2024
peaBerberian pushed a commit that referenced this pull request Jun 13, 2024
… instance of the RxPlayer (#1394)

* api: throw and error if an application use a video
element in multiple instance of the RxPlayer

The RxPlayer was not designed to run multiple instance of
RxPlayer with the same videoElement. Having multiple instance sharing
the same video element would result in various issues and unexpected
behavior.

This commit adds a check to throw an error if a videoElement is shared
between RxPlayer instances. This will provide better guidance to
application developers regarding any errors in their implementation.

* demo: dispose the previous RxPlayer instance before creating a new one
in the demo.

Commit 57fd4b9 added an error message
if the video element is reused between RxPlayer instance.
This was the case on the demo, and this commit ensure to dispose the
previous instance before creating a new one.

* add unit test and console.warn instead of throwing to prevent breaking change in API

* lint

* PR feedback

* format
@peaBerberian peaBerberian deleted the fix/throw-if-videoelem-is-shared branch July 26, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants