From 4f8b0d79cc806bb52e497c493ef57958a8e32499 Mon Sep 17 00:00:00 2001 From: jwbrandon Date: Mon, 10 Aug 2026 16:13:38 -0400 Subject: [PATCH] fix: wait for a library the consumer loads themselves Two ways a mount could fail when the page supplies the player library. window.jwplayer was tested for truthiness, so a value that is present but not yet callable counted as ready and blew up inside setup with "window.jwplayer(...).setup is not a function". Require a function. Without a library prop, loadPlayer threw at once, so a player mounting before the consumer's own script tag ran never set up and never retried. Nothing fires an event when window.jwplayer is assigned, so poll for it for up to 10 seconds and clear the interval on both outcomes. The error for a genuinely missing library now arrives as a rejection after that timeout rather than a synchronous throw; componentDidMount catches both identically. Its test was updated to match. Closes #12 --- README.md | 1 + src/util.js | 38 +++++++++++++- test/jwplayer-react.test.js | 99 +++++++++++++++++++++++++++++++++++-- 3 files changed, 133 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d10da68..ccf065e 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ These props are required to instantiate an instance of JW Player: * Must be a url to a jwplayer web player library. Required if jwplayer library not already instantiated on page (ie. if window.jwplayer is undefined). * Type: `string` * Example: `https://content.jwplatform.com/libraries/abcd1234.js` + * If you load the library yourself — a `