Skip to content

Commit

Permalink
Fix issues with non-embeddable Facebook videos
Browse files Browse the repository at this point in the history
Manually set isLoading to false when we know the FB SDK has loaded, even if onReady/onPlay hasn't been called (like when a video is non-embeddable)
#464
  • Loading branch information
cookpete committed Sep 20, 2018
1 parent ae49d6d commit 48401ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export default class Player extends Component {
this.durationCheckTimeout = setTimeout(this.onDurationCheck, 100)
}
}
onLoaded = () => {
// Sometimes we know loading has stopped but onReady/onPlay are never called
// so this provides a way for players to avoid getting stuck
this.isLoading = false
}
ref = player => {
if (player) {
this.player = player
Expand All @@ -208,6 +213,7 @@ export default class Player extends Component {
onPlay={this.onPlay}
onPause={this.onPause}
onEnded={this.onEnded}
onLoaded={this.onLoaded}
/>
)
}
Expand Down
5 changes: 5 additions & 0 deletions src/players/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export class Facebook extends Component {
xfbml: true,
version: 'v2.5'
})
FB.Event.subscribe('xfbml.render', msg => {
// Here we know the SDK has loaded, even if onReady/onPlay
// is not called due to a video that cannot be embedded
this.props.onLoaded()
})
FB.Event.subscribe('xfbml.ready', msg => {
if (msg.type === 'video' && msg.id === this.playerID) {
this.player = msg.instance
Expand Down
18 changes: 10 additions & 8 deletions test/players/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ test('load()', async t => {
init: () => null,
Event: {
subscribe: (event, fn) => {
fn({
type: 'video',
id: 'mock-player-id',
instance: {
subscribe: () => null,
unmute: () => null
}
})
if (event === 'xfbml.ready') {
fn({
type: 'video',
id: 'mock-player-id',
instance: {
subscribe: () => null,
unmute: () => null
}
})
}
}
}
}
Expand Down

0 comments on commit 48401ab

Please sign in to comment.