Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/withStreamingServer/getFreeSpace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function getFreeSpace() {
return new Promise(function (resolve, reject) {
function onStorageInfo(info) {
if (info && info.units) {
var internalStorage = info.units.find(function (unit) {
return unit.type === 'INTERNAL';
});

if (internalStorage && typeof internalStorage.availableCapacity === 'number') {
return resolve(internalStorage.availableCapacity);
}

return reject(new Error('No internal storage found'));
}
}

function onStorageInfoError(error) {
return reject(error);
}

if (window.tizen) {
window.tizen.systeminfo.getPropertyValue('STORAGE', onStorageInfo, onStorageInfoError);
} else {
reject('Tizen api not available');
}
});
}

module.exports = getFreeSpace;
28 changes: 28 additions & 0 deletions src/withStreamingServer/setFreeSpace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var url = require('url');

function setFreeSpace(streamingServerURL, freeSpace) {
var endpoint = url.resolve(streamingServerURL, '/setFreeSpace');

var body = JSON.stringify({
freeSpace: freeSpace,
});

var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: body,
};

return fetch(endpoint, options)
.then(function(resp) {
if (resp.ok) {
return resp.json();
}

throw new Error(resp.status + ' (' + resp.statusText + ')');
});
}

module.exports = setFreeSpace;
23 changes: 23 additions & 0 deletions src/withStreamingServer/wipeAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var url = require('url');

function wipeAll(streamingServerURL) {
var endpoint = url.resolve(streamingServerURL, '/wipeAll');

var options = {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
};

return fetch(endpoint, options)
.then(function(resp) {
if (resp.ok) {
return resp.json();
}

throw new Error(resp.status + ' (' + resp.statusText + ')');
});
}

module.exports = wipeAll;
20 changes: 20 additions & 0 deletions src/withStreamingServer/withStreamingServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var deepFreeze = require('deep-freeze');
var mediaCapabilities = require('../mediaCapabilities');
var convertStream = require('./convertStream');
var fetchVideoParams = require('./fetchVideoParams');
var getFreeSpace = require('./getFreeSpace');
var setFreeSpace = require('./setFreeSpace');
var wipeAll = require('./wipeAll');
var ERROR = require('../error');

function withStreamingServer(Video) {
Expand Down Expand Up @@ -102,6 +105,17 @@ function withStreamingServer(Video) {
video.dispatch({ type: 'command', commandName: 'unload' });
loadArgs = commandArgs;
onPropChanged('stream');

getFreeSpace()
.then(function(freeSpace) {
setFreeSpace(commandArgs.streamingServerURL, freeSpace)
.catch(function(error) {
console.warn('Failed to set free space', error);
});
}).catch(function(error) {
console.warn('Failed to get free space', error);
});

convertStream(commandArgs.streamingServerURL, commandArgs.stream, commandArgs.seriesInfo)
.then(function(result) {
var mediaURL = result.url;
Expand Down Expand Up @@ -273,6 +287,12 @@ function withStreamingServer(Video) {
return true;
}
case 'unload': {
if (loadArgs && loadArgs.streamingServerURL) {
wipeAll(loadArgs.streamingServerURL)
.catch(function(error) {
console.warn('Failed to remove all streams', error);
});
}
loadArgs = null;
loaded = false;
actionsQueue = [];
Expand Down