<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: removeListener not working inside addEventListener handler in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793497#M12130</link>
    <description>&lt;P&gt;Sniffing around this a bit more it seems like despite correctly setting up the event listeners for 'blur' and 'focus' on this.textAreaTarget, the issue might persist due to the EmbedController's removeListener and addListener methods not functioning as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ensure the event names are accurate and the EmbedController methods are being used correctly. Debugging with console logs or a debugger might help trace the execution flow within the EmbedController.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider checking if the removeListener and addListener methods are implemented as intended in the EmbedController. Sometimes, specific nuances or requirements might exist regarding event handling within that library or framework.&lt;/P&gt;&lt;P&gt;Getting closer?&lt;BR /&gt;Top paw regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Prague the Dog&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2024 20:40:10 GMT</pubDate>
    <dc:creator>Prague</dc:creator>
    <dc:date>2024-01-03T20:40:10Z</dc:date>
    <item>
      <title>removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793209#M12123</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;US&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Macbook Pro&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MacOS Sonoma&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;I'm using a stimulus controller to initialize the iframe embed. I'm adding an event listener to the EmbedController that works fine and I want to remove it when the form is selected. I'm not sure what I'm doing wrong but the removeListener function is not working for the EmbedController. I've gone into debugger, the textArea event is being triggered and I have access to EmbedController.removeListener but it returns undefined when I call&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;EmbedController&lt;/SPAN&gt;&lt;SPAN&gt;.removeListener(&lt;/SPAN&gt;&lt;SPAN&gt;'playback_update'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;playBackPositionBroadcast&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;in the debugger. I can see the event listed under _listeners on EmbedController. I'm not sure where to go from here. My code is below. Any help is appreciated&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;callback&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;EmbedController&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt; &lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;SPAN&gt;{&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;playBackPositionBroadcast&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;playbackEvent&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt; &lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt; &lt;SPAN&gt;{&lt;BR /&gt;///code to send playbackEvent.data.position to form in the dom&lt;BR /&gt;&lt;/SPAN&gt;};&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;EmbedController&lt;/SPAN&gt;&lt;SPAN&gt;.addListener(&lt;/SPAN&gt;&lt;SPAN&gt;'playback_update'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;playBackPositionBroadcast&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;textAreaTarget&lt;/SPAN&gt;&lt;SPAN&gt;.addEventListener(&lt;/SPAN&gt;&lt;SPAN&gt;'click'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;()&lt;/SPAN&gt; &lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt; &lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;EmbedController&lt;/SPAN&gt;&lt;SPAN&gt;.removeListener(&lt;/SPAN&gt;&lt;SPAN&gt;'playback_update'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;playBackPositionBroadcast&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;});&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;};&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 18:33:27 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793209#M12123</guid>
      <dc:creator>ZackAttax</dc:creator>
      <dc:date>2024-01-03T18:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793359#M12125</link>
      <description>&lt;P&gt;Howldy ZachAttax!&lt;/P&gt;&lt;P&gt;It seems there might be an issue with scoping or context when trying to remove the listener. In your code, you're using an arrow function for the click event listener, which might affect the scope of this. Also, the&amp;nbsp;this keyword might refer to the global context rather than the expected context within the callback.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try capturing the reference to playBackPositionBroadcast&amp;nbsp;outside the callback function, and make sure to use a named function for the click event listener to ensure proper scoping:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const callback = (EmbedController) =&amp;gt; {
  const playBackPositionBroadcast = (playbackEvent) =&amp;gt; {
    // code to send playbackEvent.data.position to form in the dom
  };

  const removePlaybackListener = () =&amp;gt; {
    EmbedController.removeListener('playback_update', playBackPositionBroadcast);
    this.textAreaTarget.removeEventListener('click', removePlaybackListener);
  };

  EmbedController.addListener('playback_update', playBackPositionBroadcast);
  this.textAreaTarget.addEventListener('click', removePlaybackListener);
};&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;By defining a named function (removePlaybackListener), it ensures that the same reference is used for adding and removing the event listener. Also, using removeEventListener instead of removeListener for the textAreaTarget should properly remove the click event listener when triggered.&lt;/P&gt;&lt;P&gt;Bark some more orders at me if this doesn't solve the issue and we'll get it sorted,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Prague the Dog&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 19:40:05 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793359#M12125</guid>
      <dc:creator>Prague</dc:creator>
      <dc:date>2024-01-03T19:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793477#M12129</link>
      <description>&lt;P&gt;I think you're right that it is a context issue. I tried your suggestion of using named function for the event callback. I also changed the event from to 'click' to 'blur' and 'focus'. Using the debugger I'm getting the expected context of this as my stimulus controller. I can also see that the 'click' and 'blur' events are being triggered correctly but the EmbedController events are still not being removed. Here is my updated code.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        const callback = (EmbedController) =&amp;gt; {
          const playBackPositionBroadcast = (playbackEvent) =&amp;gt; {
           // broadcast code
          };

          const removePlaybackListener = () =&amp;gt; {
            EmbedController.removeListener('playback_update', playBackPositionBroadcast);
          };
          const addPlaybackListener = () =&amp;gt; {
            EmbedController.addListener('playback_update', playBackPositionBroadcast);
          };
    
          EmbedController.addListener('playback_update', playBackPositionBroadcast);

          this.textAreaTarget.addEventListener('focus', removePlaybackListener);
          this.textAreaTarget.addEventListener('blur', addPlaybackListener);
        };&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Jan 2024 20:31:52 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793477#M12129</guid>
      <dc:creator>ZackAttax</dc:creator>
      <dc:date>2024-01-03T20:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793497#M12130</link>
      <description>&lt;P&gt;Sniffing around this a bit more it seems like despite correctly setting up the event listeners for 'blur' and 'focus' on this.textAreaTarget, the issue might persist due to the EmbedController's removeListener and addListener methods not functioning as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ensure the event names are accurate and the EmbedController methods are being used correctly. Debugging with console logs or a debugger might help trace the execution flow within the EmbedController.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider checking if the removeListener and addListener methods are implemented as intended in the EmbedController. Sometimes, specific nuances or requirements might exist regarding event handling within that library or framework.&lt;/P&gt;&lt;P&gt;Getting closer?&lt;BR /&gt;Top paw regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Prague the Dog&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 20:40:10 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793497#M12130</guid>
      <dc:creator>Prague</dc:creator>
      <dc:date>2024-01-03T20:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793571#M12131</link>
      <description>&lt;P&gt;This is from the docs&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;DIV class=""&gt;&lt;H3&gt;playback_update&lt;/H3&gt;&lt;/DIV&gt;&lt;P class=""&gt;This event fires after the state of playback changes. Playback state changes can occur by the user tapping on the playback controls in the Embed, or programmatically through methods of the iFrame API, such as the seek() method.&lt;/P&gt;&lt;P class=""&gt;The event handler will receive an object with four properties describing the current playback state:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;isPaused&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(bool),&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;isBuffering&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(bool),&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;duration&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(number) and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;position&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(number).&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;duration&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;describes the length of the loaded podcast episode in miliseconds and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;position&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;describes the cursor location in miliseconds.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Code sample&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;EmbedController.addListener('playback_update', e =&amp;gt; {
  document.getElementById('progressTimestamp').innerText = `${parseInt(e.data.position / 1000, 10)} s`;
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm not seeing any documentation for removeListener but it is in the source code on line 48&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        this.removeListener = (eventName, handler) =&amp;gt; {
            if (!this._listeners[eventName] || !this._listeners[eventName].length) {
                this._listeners[eventName] = this._listeners[eventName].filter(storedHandler =&amp;gt; handler !== storedHandler);
            }
        };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm not sure how I could debug the EmbedController since it's part of the Spotify API&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;full source code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @spotify-internal/uri */ "./node_modules/@spotify-internal/uri/lib/index.js");
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/iframe-api/src/v1/constants.ts");
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types */ "./src/iframe-api/src/v1/types.ts");



let SpotifyIframeApi;
class SpotifyEmbedController {
    constructor(targetElement, options) {
        var _a, _b, _c, _d, _e;
        this._listeners = {
            [_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.READY]: [],
            [_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.PLAYBACK_UPDATE]: [],
            [_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR]: [],
        };
        this.currentUri = '';
        this.loading = false;
        this._commandQ = [];
        this.setIframeDimensions = (width, height) =&amp;gt; {
            this.iframeElement.setAttribute('width', width);
            this.iframeElement.setAttribute('height', height);
        };
        this.onWindowMessages = (e) =&amp;gt; {
            var _a, _b, _c, _d, _e;
            if (e.source === this.iframeElement.contentWindow) {
                if (((_a = e.data) === null || _a === void 0 ? void 0 : _a.type) === _types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.READY) {
                    this.onPlayerReady();
                }
                if (((_b = e.data) === null || _b === void 0 ? void 0 : _b.type) === _types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.PLAYBACK_UPDATE) {
                    const playbackState = (_c = e.data) === null || _c === void 0 ? void 0 : _c.payload;
                    this.onPlaybackUpdate(playbackState);
                }
                if (((_d = e.data) === null || _d === void 0 ? void 0 : _d.type) === _types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR) {
                    this.emitEvent(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR, (_e = e.data) === null || _e === void 0 ? void 0 : _e.payload);
                }
            }
        };
        this.addListener = (eventName, handler) =&amp;gt; {
            if (!this._listeners[eventName]) {
                this._listeners[eventName] = [];
            }
            this._listeners[eventName].push(handler);
            return () =&amp;gt; {
                this.removeListener(eventName, handler);
            };
        };
        this.removeListener = (eventName, handler) =&amp;gt; {
            if (!this._listeners[eventName] || !this._listeners[eventName].length) {
                this._listeners[eventName] = this._listeners[eventName].filter(storedHandler =&amp;gt; handler !== storedHandler);
            }
        };
        this.on = this.addListener;
        this.off = this.removeListener;
        this.once = (eventName, handler) =&amp;gt; {
            this.addListener(eventName, (...args) =&amp;gt; {
                handler(...args);
                this.removeListener(eventName, handler);
            });
        };
        this.emitEvent = (eventName, eventData) =&amp;gt; {
            var _a;
            (_a = this._listeners[eventName]) === null || _a === void 0 ? void 0 : _a.forEach(handler =&amp;gt; handler({ data: eventData }));
        };
        this.onPlayerReady = () =&amp;gt; {
            this.loading = false;
            this.flushCommandQ();
            this.playerReadyAck();
            this.emitEvent(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.READY, {});
        };
        this.onPlaybackUpdate = (playbackState) =&amp;gt; {
            this.emitEvent(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.PLAYBACK_UPDATE, playbackState);
        };
        this.loadUri = (uriString, preferVideo = false, timestampInSeconds = 0) =&amp;gt; {
            var _a;
            if (uriString !== this.currentUri) {
                const uri = (0,_spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.parseURI)(uriString);
                if (uri &amp;amp;&amp;amp;
                    (uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.EPISODE ||
                        uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.SHOW ||
                        uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.ALBUM ||
                        uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.ARTIST ||
                        uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.PLAYLIST_V2 ||
                        uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.TRACK)) {
                    this.loading = true;
                    const type = uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.PLAYLIST_V2 ? 'playlist' : uri.type;
                    const embedURL = new URL(`${this.host}/embed/${type}/${uri.id}`);
                    if (this.options.startAt || timestampInSeconds) {
                        const startAt = timestampInSeconds !== null &amp;amp;&amp;amp; timestampInSeconds !== void 0 ? timestampInSeconds : parseInt((_a = this.options.startAt) !== null &amp;amp;&amp;amp; _a !== void 0 ? _a : '0', 10);
                        if (!isNaN(startAt))
                            embedURL.searchParams.append('t', startAt.toString());
                    }
                    if (this.options.theme === 'dark') {
                        embedURL.searchParams.append('theme', '0');
                    }
                    if (this.queryParamReferer) {
                        embedURL.searchParams.append('referrer', this.queryParamReferer);
                    }
                    this.iframeElement.src=embedURL.href;
                    if ((uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.EPISODE || uri.type === _spotify_internal_uri__WEBPACK_IMPORTED_MODULE_0__.URITypeMap.SHOW) &amp;amp;&amp;amp;
                        preferVideo) {
                        SpotifyIframeApi.supportsVideo(uriString).then(isVideoContent =&amp;gt; {
                            if (isVideoContent) {
                                embedURL.pathname += '/video';
                                this.iframeElement.src=embedURL.href;
                            }
                        });
                    }
                }
                else {
                    const error = {
                        code: _types__WEBPACK_IMPORTED_MODULE_2__.EmbedErrorCode.InvalidURI,
                        message: `Invalid URI: ${uriString}`,
                        recoverable: false,
                    };
                    this.emitEvent(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR, error);
                }
            }
        };
        this.playerReadyAck = () =&amp;gt; {
            this.sendMessageToEmbed({ command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.LOAD_COMPLETE_ACK });
        };
        this.play = () =&amp;gt; {
            this.sendMessageToEmbed({ command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.PLAY });
        };
        this.playFromStart = () =&amp;gt; {
            this.sendMessageToEmbed({ command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.PLAY_FROM_START });
        };
        this.pause = () =&amp;gt; {
            this.sendMessageToEmbed({ command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.PAUSE });
        };
        this.resume = () =&amp;gt; {
            this.sendMessageToEmbed({ command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.RESUME });
        };
        this.togglePlay = () =&amp;gt; {
            this.sendMessageToEmbed({ command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.TOGGLE_PLAY });
        };
        this.seek = (timestampInSeconds) =&amp;gt; {
            this.sendMessageToEmbed({
                command: _types__WEBPACK_IMPORTED_MODULE_2__.IframeCommands.SEEK,
                timestamp: timestampInSeconds,
            });
        };
        this.sendMessageToEmbed = (messageToSend) =&amp;gt; {
            if (this.loading) {
                this._commandQ.push(messageToSend);
                return;
            }
            if (this.iframeElement.contentWindow) {
                this.iframeElement.contentWindow.postMessage(messageToSend, '*');
            }
            else {
                console.error(`Spotify Embed: Failed to send message ${messageToSend}.
      Most likely this is because the iframe containing the embed player
      has not finished loading yet.`);
            }
        };
        this.flushCommandQ = () =&amp;gt; {
            if (this._commandQ.length) {
                this._commandQ.forEach(command =&amp;gt; {
                    setTimeout(() =&amp;gt; {
                        this.sendMessageToEmbed(command);
                    }, 0);
                });
                this._commandQ = [];
            }
        };
        this.destroy = () =&amp;gt; {
            var _a;
            (_a = this.iframeElement.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this.iframeElement);
            window.removeEventListener('message', this.onWindowMessages);
        };
        this.host =
            ((_a = window.SpotifyIframeConfig) === null || _a === void 0 ? void 0 : _a.host) ||
                'https://open.spotify.com';
        this.queryParamReferer =
            ((_b = window.SpotifyIframeConfig) === null || _b === void 0 ? void 0 : _b.referrer) ||
                undefined;
        this.options = options;
        const url = new URL(this.host);
        if (!url.hostname.endsWith('.spotify.com') &amp;amp;&amp;amp;
            !url.hostname.endsWith('.spotify.net')) {
            throw new Error(`It appears that the hostname for the Spotify embed player has been overridden.
      Please make sure that "SpotifyEmbedConfig" is not being overridden.`);
        }
        const iframeElement = document.createElement('iframe');
        Object.entries(_constants__WEBPACK_IMPORTED_MODULE_1__.EMBED_REQUIRED_IFRAME_ATTRIBUTES).forEach(([attr, val]) =&amp;gt; {
            const htmlAttr = attr.toLowerCase();
            if (typeof val === 'boolean') {
                iframeElement.setAttribute(htmlAttr, '');
            }
            else {
                iframeElement.setAttribute(htmlAttr, val);
            }
        });
        this.iframeElement = iframeElement;
        const width = (_c = options.width) !== null &amp;amp;&amp;amp; _c !== void 0 ? _c : '100%';
        const height = (_d = options.height) !== null &amp;amp;&amp;amp; _d !== void 0 ? _d : _constants__WEBPACK_IMPORTED_MODULE_1__.EMBED_DEFAULT_HEIGHT.toString();
        this.setIframeDimensions(width, height);
        (_e = targetElement.parentElement) === null || _e === void 0 ? void 0 : _e.replaceChild(iframeElement, targetElement);
        window.addEventListener('message', this.onWindowMessages);
    }
}
SpotifyIframeApi = {
    createController: (targetElement, options = {}, callbackOrEventsHandlers) =&amp;gt; {
        var _a, _b, _c;
        const apiInstance = new SpotifyEmbedController(targetElement, options);
        let callback;
        let errorCallback = undefined;
        if (typeof callbackOrEventsHandlers === 'function') {
            callback = callbackOrEventsHandlers;
            if (options.uri) {
                apiInstance.loadUri(options.uri, options.preferVideo);
            }
        }
        else {
            callback = callbackOrEventsHandlers.onCreateCallback;
            if ((_a = callbackOrEventsHandlers === null || callbackOrEventsHandlers === void 0 ? void 0 : callbackOrEventsHandlers.events) === null || _a === void 0 ? void 0 : _a.onError) {
                errorCallback = callbackOrEventsHandlers.events.onError;
                apiInstance.addListener(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR, errorCallback);
            }
            if ((_b = callbackOrEventsHandlers === null || callbackOrEventsHandlers === void 0 ? void 0 : callbackOrEventsHandlers.events) === null || _b === void 0 ? void 0 : _b.onReady) {
                apiInstance.addListener(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.READY, callbackOrEventsHandlers.events.onReady);
            }
            if ((_c = callbackOrEventsHandlers === null || callbackOrEventsHandlers === void 0 ? void 0 : callbackOrEventsHandlers.events) === null || _c === void 0 ? void 0 : _c.onPlaybackUpdate) {
                apiInstance.addListener(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.PLAYBACK_UPDATE, callbackOrEventsHandlers.events.onPlaybackUpdate);
            }
        }
        if (options.uri) {
            if (!errorCallback) {
                const errorHandler = error =&amp;gt; {
                    throw new Error(error.data.message);
                };
                apiInstance.addListener(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR, errorHandler);
                apiInstance.loadUri(options.uri, options.preferVideo);
                apiInstance.removeListener(_types__WEBPACK_IMPORTED_MODULE_2__.IframeAPIEvent.ERROR, errorHandler);
            }
            else {
                apiInstance.loadUri(options.uri, options.preferVideo);
            }
        }
        if (callback)
            callback(apiInstance);
    },
    supportsVideo: async (uri) =&amp;gt; {
        var _a;
        const host = (_a = window.SpotifyIframeConfig) === null || _a === void 0 ? void 0 : _a.host;
        const response = await fetch(`${host}/oembed?url=${encodeURIComponent(uri)}`, {
            method: 'GET',
        });
        const data = await response.json();
        return data.type === 'video';
    },
};
/* harmony default export */ __webpack_exports__["default"] = (SpotifyIframeApi);
if (!window.onSpotifyIframeApiReady) {
    console.warn(`SpotifyIframeApi: "onSpotifyIframeApiReady" has not been defined.
  Please read the docs to see why you are seeing this warning.
  https://developer.spotify.com/documentation/embeds/references/iframe-api`);
}
else {
    window.onSpotifyIframeApiReady(SpotifyIframeApi);
}


//# sourceURL=webpack://embed-standalone-prod/./src/iframe-api/src/v1/index.ts?&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 21:16:32 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793571#M12131</guid>
      <dc:creator>ZackAttax</dc:creator>
      <dc:date>2024-01-03T21:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793742#M12134</link>
      <description>&lt;P&gt;Woof what a line of code... lol&lt;BR /&gt;The code you shared involves an SpotifyEmbedController managing Spotify iframe API events. The addListener and removeListener methods handle event addition and removal. Despite correct usage, the removeListener for 'playback_update' might not be working as expected. It's challenging to debug or check the source code of the Spotify API directly. Double-checking event names and their consistency could be helpful in troubleshooting.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 22:55:47 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5793742#M12134</guid>
      <dc:creator>Prague</dc:creator>
      <dc:date>2024-01-03T22:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5794042#M12135</link>
      <description>&lt;P&gt;It feels a bit janky but I got it working by redefining&amp;nbsp;&lt;SPAN&gt;EmbedController&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;_listeners&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;'playback_update'&lt;/SPAN&gt;&lt;SPAN&gt;] = []&lt;BR /&gt;&lt;BR /&gt;So my working code is:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const callback = (EmbedController) =&amp;gt; {
          const playBackPositionBroadcast = (playbackEvent) =&amp;gt; {
   /// broadcast to dom
          };

          const removePlaybackListener = () =&amp;gt; {
            EmbedController._listeners['playback_update'] = [];
          };
          const addPlaybackListener = () =&amp;gt; {
            EmbedController.addListener('playback_update', playBackPositionBroadcast);
          };
    
          
          this.textAreaTarget.addEventListener('focus', removePlaybackListener);
          this.textAreaTarget.addEventListener('blur', addPlaybackListener);
          EmbedController.addListener('playback_update', playBackPositionBroadcast);
        };&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 04 Jan 2024 02:21:09 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5794042#M12135</guid>
      <dc:creator>ZackAttax</dc:creator>
      <dc:date>2024-01-04T02:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: removeListener not working inside addEventListener handler</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5794072#M12136</link>
      <description>&lt;P&gt;Pawesome dude!&lt;/P&gt;&lt;P&gt;It's great to hear that you were able to make it work! Adjusting EmbedController._listeners['playback_update'] to an empty array is a workaround solution if removeListener doesn't behave as expected. While it may solve the immediate issue, directly manipulating private properties (such as _listeners) might not be the recommended approach due to potential risks related to API changes or unintended consequences.&lt;/P&gt;&lt;P&gt;HMU if you need me to fetch anything else,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Prague the Dog&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 02:48:40 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/removeListener-not-working-inside-addEventListener-handler/m-p/5794072#M12136</guid>
      <dc:creator>Prague</dc:creator>
      <dc:date>2024-01-04T02:48:40Z</dc:date>
    </item>
  </channel>
</rss>

