jam-cloud/web/app/assets/javascripts/recordingManager.js

123 lines
4.1 KiB
JavaScript

/**
* Recording Manager viewer
* Although multiple instances could be made, only one should be
*/
(function(context, $) {
"use strict";
context.JK = context.JK || {};
context.JK.RecordingManager = function(){
var $parentElement = $('#recording-manager-viewer');
var logger = context.JK.logger;
if($parentElement.length == 0) {
logger.debug("no $parentElement specified in RecordingManager");
}
var $downloadCommand = $('#recording-manager-download', $parentElement);
var $downloadPercent = $('#recording-manager-download .percent', $parentElement);
var $uploadCommand = $('#recording-manager-upload', $parentElement);
var $uploadPercent = $('#recording-manager-upload .percent', $parentElement);
var $convertCommand = $('#recording-manager-convert', $parentElement);
var $convertPercent = $('#recording-manager-convert .percent', $parentElement);
// keys come from backend
var lookup = {
SyncDownload: { command: $downloadCommand, percent: $downloadPercent },
SyncUpload: { command: $uploadCommand, percent: $uploadPercent },
SyncConvert: { command: $convertCommand, percent: $convertPercent }
}
var $self = $(this);
function renderStartCommand($command) {
$command.css('visibility', 'visible');
}
function renderEndCommand($command) {
$command.css('visibility', 'hidden');
}
function renderPercentage($percent, value) {
$percent.text(Math.round(value * 100));
}
function onStartCommand(id, type) {
var command = lookup[type];
if(!command) { return }
var existingCommandId = command.command.data('command-id');
if(existingCommandId && existingCommandId != id) {
renderEndCommand(command.command);
}
command.command.data('command-id', id);
renderStartCommand(command.command);
renderPercentage(command.percent, 0);
}
function onStopCommand(id, type, success, reason, detail) {
var command = lookup[type];
if(!command) { return }
var existingCommandId = command.command.data('command-id');
if(!existingCommandId) {
command.command.data('command-id', id);
renderStartCommand(command.command);
}
else if(existingCommandId && existingCommandId != id) {
renderEndCommand(command.command);
command.command.data('command-id', id);
renderStartCommand(command.command);
}
renderPercentage(command.percent, 1);
renderEndCommand(command.command);
command.command.data('command-id', null);
}
function onCommandProgress(id, type, progress) {
var command = lookup[type];
if(!command) { return }
var existingCommandId = command.command.data('command-id');
if(!existingCommandId) {
command.command.data('command-id', id);
renderStartCommand(command.command);
}
else if(existingCommandId && existingCommandId != id) {
renderEndCommand(command.command);
command.command.data('command-id', id);
renderStartCommand(command.command);
}
renderPercentage(command.percent, progress);
}
function onCommandsChanged(id, type) {
}
context.JK.RecordingManagerCommandStart = onStartCommand;
context.JK.RecordingManagerCommandStop = onStopCommand;
context.JK.RecordingManagerCommandProgress = onCommandProgress;
context.JK.RecordingManagerCommandsChanged = onCommandsChanged;
context.jamClient.RegisterRecordingManagerCallbacks(
"JK.RecordingManagerCommandStart",
"JK.RecordingManagerCommandProgress",
"JK.RecordingManagerCommandStop",
"JK.RecordingManagerCommandsChanged"
)
return this;
}
})(window, jQuery);