@@ -4,6 +4,8 @@ import { StyleSheet, View } from 'react-native'
4
4
import GoogleCast , { CastButton } from 'react-native-google-cast'
5
5
import Orientation from 'react-native-orientation'
6
6
7
+ import withApollo from 'modules/GraphQL/withApollo'
8
+ import { progrssMutation } from 'modules/GraphQL/ProgressGraphQL'
7
9
import withIpFinder from 'modules/IpFinder/withIpFinder'
8
10
import dimensions from 'modules/dimensions'
9
11
import colors from 'modules/colors'
@@ -26,6 +28,7 @@ const styles = StyleSheet.create({
26
28
} )
27
29
28
30
@withIpFinder
31
+ @withApollo
29
32
export default class PlayerManager extends React . Component {
30
33
31
34
constructor ( props ) {
@@ -37,6 +40,7 @@ export default class PlayerManager extends React.Component {
37
40
mediaUrl : `http://${ ipFinder . host } /watch/${ item . _id } ` ,
38
41
progress : 0 ,
39
42
casting : false ,
43
+ lastProgressSend : 0 ,
40
44
}
41
45
}
42
46
@@ -137,12 +141,42 @@ export default class PlayerManager extends React.Component {
137
141
}
138
142
139
143
handleSetProgress = ( { currentTime, duration, progress } ) => {
144
+ const { lastProgressSend } = this . state
145
+
146
+ let newLastProgressSend = lastProgressSend
147
+
148
+ // We don't want to spam the graph api
149
+ if ( ( lastProgressSend + 0.001 ) < progress ) {
150
+ const progressToSend = parseFloat ( `${ progress * 100 } ` ) . toFixed ( 2 )
151
+
152
+ newLastProgressSend = progress
153
+
154
+ // After 95 we don't update anymore
155
+ if ( progressToSend > 95 ) {
156
+ newLastProgressSend = 100
157
+ }
158
+
159
+ this . doProgressUpdateMutation ( progressToSend )
160
+ }
161
+
140
162
this . setState ( {
141
163
currentTime,
142
164
duration,
143
165
progress,
144
- } , ( ) => {
145
- // console.log('progress',progress)
166
+ lastProgressSend : newLastProgressSend ,
167
+ } )
168
+ }
169
+
170
+ doProgressUpdateMutation = async ( progress ) => {
171
+ const { apollo, item } = this . props
172
+
173
+ await apollo . mutate ( {
174
+ variables : {
175
+ _id : item . _id ,
176
+ type : item . type ,
177
+ progress : parseFloat ( progress ) ,
178
+ } ,
179
+ mutation : progrssMutation ,
146
180
} )
147
181
}
148
182
@@ -157,7 +191,7 @@ export default class PlayerManager extends React.Component {
157
191
}
158
192
159
193
render ( ) {
160
- const { style, children } = this . props
194
+ const { style, children, item } = this . props
161
195
const { casting, mediaUrl } = this . state
162
196
163
197
return (
@@ -166,6 +200,9 @@ export default class PlayerManager extends React.Component {
166
200
{ children ( {
167
201
casting,
168
202
mediaUrl,
203
+ startPosition : item . watched . progress === 100
204
+ ? 0
205
+ : item . watched . progress ,
169
206
renderCastButton : this . renderCastButton ,
170
207
setProgress : this . handleSetProgress ,
171
208
} ) }
0 commit comments