Skip to content

Commit

Permalink
Test Simpler Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Jun 4, 2024
1 parent 14ab8ee commit fc7afb3
Showing 1 changed file with 44 additions and 35 deletions.
79 changes: 44 additions & 35 deletions src/WebOsVideo/WebOsVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var cloneDeep = require('lodash.clonedeep');
var deepFreeze = require('deep-freeze');
var ERROR = require('../error');

var lastMediaId = false;

function luna(params, call, fail, method) {
if (call) params.onSuccess = call || function() {};

Expand Down Expand Up @@ -240,9 +242,10 @@ function WebOsVideo(options) {
'subscribe': true
}
}, function (result) {
if (result.sourceInfo && !answered) {
if ((result || {}).sourceInfo && !answered) {
answered = true;
var info = result.sourceInfo.programInfo[0];
var programInfo = result.sourceInfo.programInfo || [];
var info = programInfo[0];

setSubs(info);

Expand All @@ -251,42 +254,47 @@ function WebOsVideo(options) {
unsubscribe(cb);
}

if ((result.error || {}).errorCode) {
answered = true;
// console.error('luna playback error', result.error);
unsubscribe(cb);
// unsubscribe();
// onVideoError();
return;
}

if ((result.unloadCompleted || {}).mediaId === knownMediaId && (result.unloadCompleted || {}).state) {
// strange case where it just.. ends? without ever getting result.sourceInfo
// onEnded();
// console.log('strange case of end');
// unsubscribe(cb);
return;
}

count_message++;

if (count_message === 30 && !answered) {
// cb();
unsubscribe(cb);
}
// if ((result.error || {}).errorCode) {
// answered = true;
// // console.error('luna playback error', result.error);
// unsubscribe(cb);
// // unsubscribe();
// // onVideoError();
// return;
// }

// if ((result.unloadCompleted || {}).mediaId === knownMediaId && (result.unloadCompleted || {}).state) {
// // strange case where it just.. ends? without ever getting result.sourceInfo
// // onEnded();
// // console.log('strange case of end');
// // unsubscribe(cb);
// return;
// }

// if ((result || {}).bufferRange) {
// count_message++;

// if (count_message === 60 && !answered) {
// answered = true;
// unsubscribe(cb);
// }
// }
}, function() { // function(err)
// console.log('luna error log 2');
// console.error(err);
answered = true;
unsubscribe(cb);
});
};

var unsubscribe = function (cb) {
if (!subscribed) return;
subscribed = false;
luna({
method: 'unsubscribe',
method: 'subscribe',
parameters: {
'mediaId': knownMediaId
'mediaId': knownMediaId,
'subscribe': false
}
}, function () { // function(result)
// console.log('unsubscribe result', JSON.stringify(result));
Expand All @@ -295,7 +303,7 @@ function WebOsVideo(options) {
// console.log('unsubscribe error', JSON.stringify(err));
cb();
});
cb();
// cb();
};

// var unload = function (cb) {
Expand Down Expand Up @@ -970,18 +978,19 @@ function WebOsVideo(options) {

var initMediaId = function (cb) {
function retrieveMediaId() {
if (videoElement.mediaId) {
if (videoElement.mediaId && videoElement.mediaId !== lastMediaId) {
knownMediaId = videoElement.mediaId;
lastMediaId = knownMediaId;
clearInterval(timer);
subscribe(cb);
return;
}
count++;
if (count > 4) {
// console.log('failed to get media id');
clearInterval(timer);
cb();
}
// count++;
// if (count > 4) {
// // console.log('failed to get media id');
// clearInterval(timer);
// cb();
// }
}
var timer = setInterval(retrieveMediaId, 300);
};
Expand Down

0 comments on commit fc7afb3

Please sign in to comment.