-
Notifications
You must be signed in to change notification settings - Fork 3
/
NewRelicReactPlayer.js
89 lines (75 loc) · 2.04 KB
/
NewRelicReactPlayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React from 'react'
import ReactPlayer from 'react-player'
export default class NewRelicReactPlayer extends React.Component {
static propTypes = {
onStart: ReactPlayer.propTypes.onStart,
onPlay: ReactPlayer.propTypes.onPlay,
onDuration: ReactPlayer.propTypes.onDuration,
onPause: ReactPlayer.propTypes.onPause,
onBuffer: ReactPlayer.propTypes.onBuffer,
onSeek: ReactPlayer.propTypes.onSeek,
onEnded: ReactPlayer.propTypes.onEnded,
onError: ReactPlayer.propTypes.onError
}
componentDidMount () {
this.tracker = new nrvideo.ReactPlayerTracker(this.player)
nrvideo.Core.addTracker(this.tracker)
}
componentWillReceiveProps(nextProps, nextState) {
if (nextProps.url !== this.props.url) {
// Url changed
this.tracker.onUrlChanged()
}
}
ref = (player) => {
this.player = player
}
onStart = (e) => {
if (this.props.onStart) this.props.onStart()
this.tracker.onStart(e)
}
onPlay = (e) => {
if (this.props.onPlay) this.props.onPlay()
this.tracker.onPlay(e)
}
onDuration = (e) => {
if (this.props.onDuration) this.props.onDuration()
this.tracker.onDuration(e)
}
onPause = (e) => {
if (this.props.onPause) this.props.onPause()
this.tracker.onPause(e)
}
onBuffer = (e) => {
if (this.props.onBuffer) this.props.onBuffer()
this.tracker.onBuffer(e)
}
onSeek = (e) => {
if (this.props.onSeek) this.props.onSeek()
this.tracker.onSeek(e)
}
onEnded = (e) => {
if (this.props.onEnded) this.props.onEnded()
this.tracker.onEnded(e)
}
onError = (e) => {
if (this.props.onError) this.props.onError()
this.tracker.onError(e)
}
render() {
return (
<ReactPlayer
{...this.props}
ref={this.ref}
onStart={this.onStart}
onPlay={this.onPlay}
onDuration={this.onDuration}
onPause={this.onPause}
onBuffer={this.onBuffer}
onSeek={this.onSeek}
onEnded={this.onEnded}
onError={this.onError}
/>
)
}
}