The object provides API to download manager.
Download manager allows adding and scheduling download tasks, which will try to download and store remote file into local storage.
stbDownloadManager object itself does not require any additional initialization. It is always accessible from JavaScript context.
Job states table:
Value | Description |
---|---|
0 | stopped |
1 | waiting for queue |
2 | running |
3 | completed |
4 | temporary error |
5 | permanent error |
Methods
-
AddJob
<static> AddJob ( urlToDownload, filePath ) → {boolean} -
Add a job for file downloading using URL "
urlToDownload
".In case of success local file will be stored in filePath. By the time of the operation local file should not exist.
Parameters:Name Type Description urlToDownload
string
address of the file
filePath
string
path to local storage pointing to a non-existed file
downloaded file will be stored using this path to the local storage
- Since:
- 0.2.16
Returns:Type Description boolean
operation status:
Value Description true job was added successfully false failure -
AddMeasureJob
<static> AddMeasureJob ( urlToDownload ) → {boolean} -
Similar to stbDownloadManager.AddJob.
Create a special job, that will download given file without saving the result to file storage.
This job is using as connection test facility. You can calculate download speed (once job is finished) using "
timeWasted
" and "sizeDone
" attributes.You can only create one such connection at the moment. So, you have to delete it each time you want to create next one.
Parameters:Name Type Description urlToDownload
string
address must point to a remote file
Returns:Type Description boolean
operation status:
Value Description true job was added successfully false failure -
AdjustJobPriority
<static> AdjustJobPriority ( id, direction ) -
Change priority of the given job.
Priority can either be increased or decreased.
Parameters:Name Type Description id
number
unique identifier of a job assigned for this operation [-1, 0..4294967295]
direction
boolean
possible values:
Value Description true increase priority false decrease priority -
AdjustJobPriorityV2
<static> AdjustJobPriorityV2 ( id, prioLevel ) -
Same as AdjustJobPriority but receive priority level.
Parameters:Name Type Description id
number
unique identifier of a job assigned for this operation [-1, 0..4294967295]
prioLevel
boolean
new priority of the job expressed in levels (allowed values 1,2,3,4,5)
-
DeleteJob
<static> DeleteJob ( id, deleteFile ) → {boolean} -
Delete given job.
Parameters:Name Type Description id
number
unique identifier of a job assigned for this operation [-1, 0..4294967295]
deleteFile
boolean
keep or remove the downloaded file:
Value Description true delete associated local file false just delete the job and keep local file Returns:Type Description boolean
operation status:
Value Description true job was removed successfully false failure -
GetMeasureInfo
<static> GetMeasureInfo () → {Array.<stbDownloadManager.JobInfo>} -
Similar to stbDownloadManager.GetQueueInfo.
Get information about special (test) job. If test job does not exist then return empty list.
See stbDownloadManager.JobInfo, stbDownloadManager.AddMeasureJob.
Returns:Type Description Array.<stbDownloadManager.JobInfo>
list of jobs in JSON format
-
GetQueueInfo
<static> GetQueueInfo ( idList ) → {Array.<stbDownloadManager.JobInfo>} -
Get info about queue of jobs.
Parameters:Name Type Argument Description idList
string
<optional>
list of ids in JSON format
If list is not empty information for given jobs will be returned. Whole queue will be returned in other case.
Returns:Type Description Array.<stbDownloadManager.JobInfo>
list of jobs in JSON format
Example
// get the particular jobs info stbDownloadManager.GetQueueInfo('[1, 2, 3]'); // get all jobs data stbDownloadManager.GetQueueInfo();
-
InvalidateCatalog
<static> InvalidateCatalog ( mountPoint ) -
Invalidate jobs for selected mount point.
Parameters:Name Type Description mountPoint
string
folder where storage device content mounted
- Since:
- 0.2.16
-
PlayDownloadedMedia
<static> PlayDownloadedMedia ( id ) -
Play the given job in dedicated "media player" window of the internal portal.
This effectively generate stbEvent.onMediaAvailable event.
Parameters:Name Type Description id
number
unique identifier of a job assigned for this operation [-1, 0..4294967295]
-
RestoreJobs
<static> RestoreJobs ( mountPoint ) -
Restore jobs using local catalog on selected device.
Parameters:Name Type Description mountPoint
string
folder where storage device content mounted
- Since:
- 0.2.16
-
StartJob
<static> StartJob ( id ) → {boolean} -
Change state of the given job to "waiting for queue".
This will cause job to start downloading process once queue will be ready to schedule the job.
Parameters:Name Type Description id
number
unique identifier of a job assigned for this operation [-1, 0..4294967295]
Returns:Type Description boolean
operation status:
Value Description true job was started successfully false failure -
StopJob
<static> StopJob ( id ) → {boolean} -
Change state of the given job to "stopped".
This state will cause the job will never be selected by scheduler for downloading.
Parameters:Name Type Description id
number
unique identifier of a job assigned for this operation [-1, 0..4294967295]
Returns:Type Description boolean
operation status:
Value Description true job was stopped successfully false failure
Type Definitions
-
JobInfo
JobInfo -
Information about a job in JSON format.
Type:-
string
Properties:Name Type Description id
number
unique task identifier of the job
state
number
current job state (see job states table)
stateStr
string
state string (localization is supported for this string resource)
url
string
remote file address
filePath
string
path to a local storage
tempFile
string
temporary file
mountPoint
string
folder where storage device content mounted
progressPct
number
progress of downloading process in percents [0..100]
sizeDone
number
size of already downloaded data
sizeTotal
number
total file size (value -1 if undefined)
prio
number
priority of the job
prioLevel
number
priority of the job expressed in levels (allowed values 1,2,3,4,5)
attempt
number
number of the download attempt
timeWasted
number
time elapsed since job start (ms)
Example
// parsed JSON data { id: 1, state: 3, stateStr: "Completed", url: "http://somehost/Hawking (BBC).avi" mountPoint: "/media/HDD-SATA-1", filePath: "Hawking (BBC).avi", progressPct: 100, sizeDone: 739287040, sizeTotal: 739287040, prio: 1, prioLevel: 5, attempt: 0, tempFile: "Hawking (BBC).avi-a528f.temp", timeWasted: 310728, }
-