@@ -4,8 +4,6 @@ import 'whatwg-fetch';
44
55import Player from './Player' ;
66
7- import { itn , bristolsport , londontheinside , spectator , telegraph } from './playlist' ;
8-
97const Modernizr = window . suggestv . Modernizr ;
108
119/**
@@ -47,7 +45,7 @@ const CLIENT = getClient();
4745
4846class App extends React . Component {
4947 static getVideos ( url , client ) {
50- let endpoint = `https://uat .suggestv.io/semantics?url=${ url } &client=${ client } &skipcache=true ` ;
48+ const endpoint = `https://api .suggestv.io/semantics?url=${ url } &client=${ client } ` ;
5149
5250 return fetch ( endpoint , {
5351 method : 'GET' ,
@@ -126,6 +124,7 @@ class App extends React.Component {
126124 width : 640 ,
127125 height : 264 ,
128126 } ,
127+ isLoading : true ,
129128 adError : 'N/A' ,
130129 adStart : 'N/A' ,
131130 adSrc : 'N/A' ,
@@ -138,11 +137,6 @@ class App extends React.Component {
138137 watchedDuration : 0 ,
139138 flashTestFinished : false ,
140139 adLoadingPoster : 'https://build.suggestv.io/assets/adLoading.jpg' ,
141- itn : itn . slice ( 0 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ,
142- bristolsport : bristolsport . slice ( 0 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ,
143- londontheinside : londontheinside . slice ( 0 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ,
144- spectator : spectator . slice ( 0 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ,
145- telegraph : telegraph . slice ( 0 ) . sort ( ( ) => 0.5 - Math . random ( ) ) ,
146140 } ;
147141 this . setVideos = this . setVideos . bind ( this ) ;
148142 this . playlist = this . playlist . bind ( this ) ;
@@ -155,6 +149,14 @@ class App extends React.Component {
155149 console . log ( 'SUGGESTV: client is ' , CLIENT ) ;
156150 window . addEventListener ( 'scroll' , this . handleScroll ) ;
157151 window . addEventListener ( 'touchmove' , this . handleScroll ) ;
152+
153+ App . getVideos ( window . location . href , CLIENT ) . then ( ( data ) => {
154+ console . log ( 'SUGGESTV: DATA' , data ) ;
155+
156+ this . setVideos ( data ) ;
157+ } ) . catch ( ( err ) => {
158+ console . log ( 'SUGGESTV: Promise Error' , err ) ;
159+ } ) ;
158160 }
159161
160162 componentWillUnmount ( ) {
@@ -163,17 +165,14 @@ class App extends React.Component {
163165 }
164166
165167 setVideos ( data ) {
166- let videos = [ ] ;
168+ const videos = [ ] ;
167169 const SCORE_LIMIT = 15 ;
168170 this . setState ( { query : data . keywords } ) ;
169171
170172 if ( data !== null && data . results && data . results . length > 0 ) {
171173
172174 data . results . forEach ( ( video ) => {
173- let keywordsMatched = [ ] ;
174- const highlights = video . highlights ;
175175 const fields = video . fields ;
176- const regex = / \* ( \S [ \s \S ] * ?) \* / g;
177176
178177 if ( Number ( fields . _score [ 0 ] ) > SCORE_LIMIT ) {
179178 videos . push ( {
@@ -193,28 +192,20 @@ class App extends React.Component {
193192 this . setState ( {
194193 videos,
195194 videosFrom : 'semanticsearch' ,
195+ isLoading : false ,
196196 } ) ;
197197 } else {
198- console . log ( 'SUGGESTV: none of the videos matched enough keywords or have big enough score' ) ;
199- setDefaultClientVideos ( this ) ;
198+ console . log ( 'SUGGESTV: no videos' ) ;
199+ this . setState ( {
200+ videos : [ ] ,
201+ isLoading : false ,
202+ } ) ;
200203 }
201204 } else {
202- setDefaultClientVideos ( this ) ;
203- }
204-
205- function setDefaultClientVideos ( ctx ) {
206- videos = [ ] ;
207-
208- if ( CLIENT === 'localhost' ) videos = ctx . state . telegraph ;
209- if ( CLIENT === 'telegraph' ) videos = ctx . state . telegraph ;
210- if ( CLIENT === 'londontheinside' ) videos = ctx . state . londontheinside ;
211- if ( CLIENT === 'beautyandthedirt' ) videos = ctx . state . londontheinside ;
212- if ( CLIENT === 'bristol-sport' ) videos = ctx . state . bristolsport ;
213- if ( CLIENT === 'proactiveinvestors' ) videos = ctx . state . itn ;
214-
215- ctx . setState ( {
216- videos,
217- videosFrom : 'defaultplaylist' ,
205+ console . log ( 'SUGGESTV: no videos' ) ;
206+ this . setState ( {
207+ videos : [ ] ,
208+ isLoading : false ,
218209 } ) ;
219210 }
220211 }
@@ -225,15 +216,15 @@ class App extends React.Component {
225216
226217 handleScroll ( ) {
227218 const { pausedByUser, playedByUser, flashTestFinished, videoLoaded } = this . state ;
228- if ( App . isInViewport ( this . playerNode . videoNode ) ) {
229- if ( this . playerNode . videoNode && ! pausedByUser && videoLoaded && flashTestFinished ) {
219+ if ( this . playerNode && App . isInViewport ( this . playerNode . videoNode ) ) {
220+ if ( ! pausedByUser && videoLoaded && flashTestFinished ) {
230221 if ( CLIENT === 'cityam' || CLIENT === 'beautyandthedirt' ) {
231222 console . log ( 'SUGGESTV: click-to-play' ) ;
232223 } else {
233224 this . playerNode . player . play ( ) ;
234225 }
235226 }
236- } else if ( ! playedByUser ) {
227+ } else if ( this . playerNode && ! playedByUser ) {
237228 this . playerNode . player . pause ( ) ;
238229 }
239230 }
@@ -286,15 +277,11 @@ class App extends React.Component {
286277 }
287278
288279 render ( ) {
289- const url = window . location . href ;
290-
291- return (
280+ return this . state . videos . length > 0 && ! this . loading ? (
292281 < Player
293282 ref = { p => ( this . playerNode = p ) }
294283 updateState = { this . updateState }
295284 plugins = { this . plugins }
296- setVideos = { this . setVideos }
297- getVideos = { App . getVideos ( url , CLIENT ) }
298285 videos = { this . state . videos }
299286 playlist = { this . playlist }
300287 videoJsOptions = { this . state . videoJsOptions }
@@ -305,8 +292,9 @@ class App extends React.Component {
305292 postAnalytics = { this . postAnalytics }
306293 CLIENT = { CLIENT }
307294 Modernizr = { Modernizr }
295+ container = { document . getElementById ( 'suggestvplayer' ) }
308296 />
309- ) ;
297+ ) : null ;
310298 }
311299}
312300
0 commit comments