Skip to content

Commit fc7afb3

Browse files
committed
Test Simpler Logic
1 parent 14ab8ee commit fc7afb3

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

src/WebOsVideo/WebOsVideo.js

+44-35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var cloneDeep = require('lodash.clonedeep');
33
var deepFreeze = require('deep-freeze');
44
var ERROR = require('../error');
55

6+
var lastMediaId = false;
7+
68
function luna(params, call, fail, method) {
79
if (call) params.onSuccess = call || function() {};
810

@@ -240,9 +242,10 @@ function WebOsVideo(options) {
240242
'subscribe': true
241243
}
242244
}, function (result) {
243-
if (result.sourceInfo && !answered) {
245+
if ((result || {}).sourceInfo && !answered) {
244246
answered = true;
245-
var info = result.sourceInfo.programInfo[0];
247+
var programInfo = result.sourceInfo.programInfo || [];
248+
var info = programInfo[0];
246249

247250
setSubs(info);
248251

@@ -251,42 +254,47 @@ function WebOsVideo(options) {
251254
unsubscribe(cb);
252255
}
253256

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+
// }
277282
}, function() { // function(err)
278283
// console.log('luna error log 2');
279284
// console.error(err);
285+
answered = true;
286+
unsubscribe(cb);
280287
});
281288
};
282289

283290
var unsubscribe = function (cb) {
284291
if (!subscribed) return;
285292
subscribed = false;
286293
luna({
287-
method: 'unsubscribe',
294+
method: 'subscribe',
288295
parameters: {
289-
'mediaId': knownMediaId
296+
'mediaId': knownMediaId,
297+
'subscribe': false
290298
}
291299
}, function () { // function(result)
292300
// console.log('unsubscribe result', JSON.stringify(result));
@@ -295,7 +303,7 @@ function WebOsVideo(options) {
295303
// console.log('unsubscribe error', JSON.stringify(err));
296304
cb();
297305
});
298-
cb();
306+
// cb();
299307
};
300308

301309
// var unload = function (cb) {
@@ -970,18 +978,19 @@ function WebOsVideo(options) {
970978

971979
var initMediaId = function (cb) {
972980
function retrieveMediaId() {
973-
if (videoElement.mediaId) {
981+
if (videoElement.mediaId && videoElement.mediaId !== lastMediaId) {
974982
knownMediaId = videoElement.mediaId;
983+
lastMediaId = knownMediaId;
975984
clearInterval(timer);
976985
subscribe(cb);
977986
return;
978987
}
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+
// }
985994
}
986995
var timer = setInterval(retrieveMediaId, 300);
987996
};

0 commit comments

Comments
 (0)