Skip to content

Commit

Permalink
fix: remove identical mediaSession playpause handlers
Browse files Browse the repository at this point in the history
fixes issue with dailymotion.com player
  • Loading branch information
samuelmaddock committed Jul 1, 2020
1 parent 8100a91 commit a209659
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/metastream-remote-extension/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,31 @@
})
}

validateHandlers() {
const { play, pause } = this._handlers

// Metastream needs to be able to set the playback state accurately.
// Some websites use the same handler for both play and pause which
// causes them to toggle.
if (typeof play === 'function' && typeof pause === 'function') {
// HACK: check whether function definitions are the same.
const playStr = play.toString()
const pauseStr = pause.toString()
if (play === pause || (!playStr.includes('[native code]') && playStr === pauseStr)) {
delete this._handlers.play
delete this._handlers.pause
}
}
}

setActionHandler(name, handler) {
const noopStr = (function(){}).toString() // prettier-ignore
if (typeof handler !== 'function' || handler.toString() === noopStr) {
return // ignore noop handlers (seen on tunein.com)
}
console.debug(`MediaSession.setActionHandler '${name}'`)
this._handlers[name] = handler
this.validateHandlers()
}

execActionHandler(name, ...args) {
Expand Down

0 comments on commit a209659

Please sign in to comment.