@@ -3,6 +3,8 @@ var cloneDeep = require('lodash.clonedeep');
3
3
var deepFreeze = require ( 'deep-freeze' ) ;
4
4
var ERROR = require ( '../error' ) ;
5
5
6
+ var lastMediaId = false ;
7
+
6
8
function luna ( params , call , fail , method ) {
7
9
if ( call ) params . onSuccess = call || function ( ) { } ;
8
10
@@ -240,9 +242,10 @@ function WebOsVideo(options) {
240
242
'subscribe' : true
241
243
}
242
244
} , function ( result ) {
243
- if ( result . sourceInfo && ! answered ) {
245
+ if ( ( result || { } ) . sourceInfo && ! answered ) {
244
246
answered = true ;
245
- var info = result . sourceInfo . programInfo [ 0 ] ;
247
+ var programInfo = result . sourceInfo . programInfo || [ ] ;
248
+ var info = programInfo [ 0 ] ;
246
249
247
250
setSubs ( info ) ;
248
251
@@ -251,42 +254,47 @@ function WebOsVideo(options) {
251
254
unsubscribe ( cb ) ;
252
255
}
253
256
254
- if ( ( result . error || { } ) . errorCode ) {
255
- answered = true ;
256
- // console.error('luna playback error', result.error);
257
- unsubscribe ( cb ) ;
258
- // unsubscribe();
259
- // onVideoError();
260
- return ;
261
- }
262
-
263
- if ( ( result . unloadCompleted || { } ) . mediaId === knownMediaId && ( result . unloadCompleted || { } ) . state ) {
264
- // strange case where it just.. ends? without ever getting result.sourceInfo
265
- // onEnded();
266
- // console.log('strange case of end');
267
- // unsubscribe(cb);
268
- return ;
269
- }
270
-
271
- count_message ++ ;
272
-
273
- if ( count_message === 30 && ! answered ) {
274
- // cb();
275
- unsubscribe ( cb ) ;
276
- }
257
+ // if ((result.error || {}).errorCode) {
258
+ // answered = true;
259
+ // // console.error('luna playback error', result.error);
260
+ // unsubscribe(cb);
261
+ // // unsubscribe();
262
+ // // onVideoError();
263
+ // return;
264
+ // }
265
+
266
+ // if ((result.unloadCompleted || {}).mediaId === knownMediaId && (result.unloadCompleted || {}).state) {
267
+ // // strange case where it just.. ends? without ever getting result.sourceInfo
268
+ // // onEnded();
269
+ // // console.log('strange case of end');
270
+ // // unsubscribe(cb);
271
+ // return;
272
+ // }
273
+
274
+ // if ((result || {}).bufferRange) {
275
+ // count_message++;
276
+
277
+ // if (count_message === 60 && !answered) {
278
+ // answered = true;
279
+ // unsubscribe(cb);
280
+ // }
281
+ // }
277
282
} , function ( ) { // function(err)
278
283
// console.log('luna error log 2');
279
284
// console.error(err);
285
+ answered = true ;
286
+ unsubscribe ( cb ) ;
280
287
} ) ;
281
288
} ;
282
289
283
290
var unsubscribe = function ( cb ) {
284
291
if ( ! subscribed ) return ;
285
292
subscribed = false ;
286
293
luna ( {
287
- method : 'unsubscribe ' ,
294
+ method : 'subscribe ' ,
288
295
parameters : {
289
- 'mediaId' : knownMediaId
296
+ 'mediaId' : knownMediaId ,
297
+ 'subscribe' : false
290
298
}
291
299
} , function ( ) { // function(result)
292
300
// console.log('unsubscribe result', JSON.stringify(result));
@@ -295,7 +303,7 @@ function WebOsVideo(options) {
295
303
// console.log('unsubscribe error', JSON.stringify(err));
296
304
cb ( ) ;
297
305
} ) ;
298
- cb ( ) ;
306
+ // cb();
299
307
} ;
300
308
301
309
// var unload = function (cb) {
@@ -970,18 +978,19 @@ function WebOsVideo(options) {
970
978
971
979
var initMediaId = function ( cb ) {
972
980
function retrieveMediaId ( ) {
973
- if ( videoElement . mediaId ) {
981
+ if ( videoElement . mediaId && videoElement . mediaId !== lastMediaId ) {
974
982
knownMediaId = videoElement . mediaId ;
983
+ lastMediaId = knownMediaId ;
975
984
clearInterval ( timer ) ;
976
985
subscribe ( cb ) ;
977
986
return ;
978
987
}
979
- count ++ ;
980
- if ( count > 4 ) {
981
- // console.log('failed to get media id');
982
- clearInterval ( timer ) ;
983
- cb ( ) ;
984
- }
988
+ // count++;
989
+ // if (count > 4) {
990
+ // // console.log('failed to get media id');
991
+ // clearInterval(timer);
992
+ // cb();
993
+ // }
985
994
}
986
995
var timer = setInterval ( retrieveMediaId , 300 ) ;
987
996
} ;
0 commit comments