function WebTorrentDownloadForm( PHPSESSID ) { this.strTorrentFor = null; this.strTorrentHash = null; this.PHPSESSID = PHPSESSID; this.strWTSessionKey = null; this.strFileHost = null; this.strHttpHost = null; this.objFilesFmP2P = null; this.objClient = null; this.objTorrent = null; this.objStatistics = { connections:[], pieces:[] }; this.objTextTranslations = {}; this.bolDownloadFinished = false; this.objP2PGraph = null; this.arrGraphUnregisteredWires = []; this.arrFilterFileHashes = []; this.arrFilterFiles = null; this.arrFilterFileNames = null; this.arrTorrentClientFiles = []; this.bolNewHash = false; this.bolNewFileHashes = false; this.intDownloadStartedTimestamp = null; this.intTotalBytes = 0; this.intDownloadedBytes = 0; this.dblProgressPercents = 0; this.bolAllowRegisterStatistics = false; var jqDownloadButton = $('#webtorrent_download_form__top_content .webtorrent_download_form__download_all_button'); // Show the P2P sharing form this.bolPrevFinished_showForm = true; this.showForm = function( strTorrentFor, strTorrentHash, arrFilterFileHashes ) { var _this = this; if ( ! this.bolPrevFinished_showForm ) { return; } this.bolPrevFinished_showForm = false; // Check if new upload hash changed if ( this.strTorrentFor !== strTorrentFor || this.strTorrentHash !== strTorrentHash ) { this.strTorrentFor = strTorrentFor; this.strTorrentHash = strTorrentHash; this.bolNewHash = true; } // Check if files mach previous download if ( ! arrFilterFileHashes || ! Array.isArray( arrFilterFileHashes ) ) arrFilterFileHashes = []; this.bolNewFileHashes = false; for (var i = 0; i < this.arrFilterFileHashes.length; i++) { if ( this.arrFilterFileHashes[i] !== arrFilterFileHashes[i] ) { this.bolNewFileHashes = true; } } if ( this.arrFilterFileHashes.length < arrFilterFileHashes.length ) { this.bolNewFileHashes = true; } this.arrFilterFileHashes = arrFilterFileHashes; // Show in form loading info this.setFormViewStatus( 'form_loading' ); showModal( 'webtorrent_download_form' ); // If WebTorrent library is not loaded, wait 1 second and try again if ( typeof FilesFm_P2P != 'function' ) { setTimeout( function() { _this.showForm( strTorrentFor, strTorrentHash, arrFilterFileHashes ); }, 1000 ); this.bolPrevFinished_showForm = true; return; } // Check if upload hash changed if ( this.bolNewHash ) { // If form called with other upload hash than previous // Register a new client and get parameters this.registerClient( function () { // Check if the browser supports WebRTC if ( FilesFm_P2P.WEBRTC_SUPPORT ) { // Initiate a WebTorrent client's object _this.initClient( function () { $( '#webtorrent_download_form__alert_container__wait .alert_main_text' ).html( _this.getText( 'GeneratingTorrentFile' ) ); $( '#webtorrent_download_form__alert_container__wait' ).css('display', 'table'); // Initiate a WebTorrent torrent's object _this.addTorrent( function () { // Show in form that download is started _this.setFormViewStatus( 'donwload_in_progress' ); var strTorrentLink = null; if ( _this.strTorrentFor === 'file' ) { strTorrentLink = 'https://' + _this.strHttpHost + '/torrent/get_torrent.php?file_hash=' + _this.strTorrentHash; } else { strTorrentLink = 'https://' + _this.strHttpHost + '/torrent/get_torrent.php?folder_hash=' + _this.strTorrentHash; } $( '#webtorrent_download_form__torrent_file_url' ) // Set up the torrent file's simple download url .attr( 'href', strTorrentLink ) // set file name for download url .attr( 'download', _this.strTorrentHash + ".torrent" ); _this.initP2PGraph(); _this.setupDownloadButton(); _this.bolNewHash = false; _this.bolPrevFinished_showForm = true; $( '#webtorrent_download_form__alert_container__wait' ).hide(); }, function () { $( '#webtorrent_download_form__alert_container__wait' ).hide(); _this.setFormViewStatus( 'download_error' ); _this.bolNewHash = false; _this.bolPrevFinished_showForm = true; } ); }, function () { _this.setFormViewStatus( 'download_error' ); _this.bolPrevFinished_showForm = true; } ); } else { // TO-DO: register no Webrtc // Show message that the browser does not have P2P download support _this.setFormViewStatus( 'browser_has_not_p2p_support' ); _this.bolPrevFinished_showForm = true; } }, function () { setTimeout( function () { _this.showForm( _this.strTorrentFor, _this.strTorrentHash, _this.arrFilterFileHashes ); }, 1000 ); _this.bolPrevFinished_showForm = true; } ); } else { // If form called with same upload hash _this.dblProgressPercents = 0; _this.intDownloadedBytes = 0; _this.intTotalBytes = 0; _this.bolDownloadFinished = false; // If form called with same file hashes if ( ! this.bolNewFileHashes ) { // If file hashes are the same _this.onDownloadFinished(); // Show in form that download is started _this.setFormViewStatus( 'donwload_in_progress' ); _this.setFormViewStatus( 'donwload_finished' ); _this.bolPrevFinished_showForm = true; } else { // If file hashes changed, get new filenames from server and change torrent selection this.registerClient( function () { // Select new files _this.torrentMakeSelection(); // Bug in webtorrrent - quick fix. _this.objTorrent.done = false; _this.intDownloadStartedTimestamp = ( new Date() ).getTime(); _this.bolPrevFinished_showForm = true; // Show in form that download is started _this.setFormViewStatus( 'donwload_in_progress' ); $( '#webtorrent_download_form__alert_container__wait' ).hide(); }, function () { setTimeout( function () { _this.showForm( _this.strTorrentFor, _this.strTorrentHash, _this.arrFilterFileHashes ); }, 1000 ); _this.bolPrevFinished_showForm = true; } ); } } } // Register a new client and get parameters this.registerClient = function( fncCallback_Success, fncCallback_Error ) { var _this = this; $.ajax( { type : 'POST', dataType : 'json', url : '/ajax/webtorrent_download_form.php?PHPSESSID='+ this.PHPSESSID , data : { action : 'init_client' , folder_hash : this.strTorrentFor === 'folder' ? this.strTorrentHash : null, file_hash : this.strTorrentFor === 'file' ? this.strTorrentHash : null, file_hashes: JSON.stringify(this.arrFilterFileHashes) } , success : function( objResponse ) { if ( objResponse[ 'status' ] == 'ok' ) { _this.strWTSessionKey = objResponse[ 'data' ][ 'wt_session_key' ]; _this.strFileHost = objResponse[ 'data' ][ 'file_host' ]; _this.strHttpHost = objResponse[ 'data' ][ 'http_host' ]; _this.objTextTranslations = objResponse[ 'data' ][ 'text_translations' ]; _this.arrFilterFiles = objResponse[ 'data' ][ 'files' ]; _this.arrFilterFileNames = []; for (var i=0; i<_this.arrFilterFiles.length; i++) _this.arrFilterFileNames.push(_this.arrFilterFiles[i]['Name']); _this.bolAllowRegisterStatistics = objResponse[ 'data' ][ 'allow_register_statistics' ]; fncCallback_Success(); } else { fncCallback_Error(); } } , error : function() { fncCallback_Error(); } } ); }; // Initiate the client this.initClient = function( fncCallback_Success, fncCallback_Error ) { var _this = this; // Create a new WebTorrent client try { /* JV 2022-09-20 samazinu skaitu ātrākai torrenta peeru noskaidrošanai var objOptions = { tracker: { rtcConfig: { 'iceServers': [ { 'urls': [ 'stun:stun.files.fm:443' ], 'username': 'filesfm', 'credential': 'password', 'credentialType': 'password' } , { 'urls': [ 'turn:stun.files.fm:443' ], 'username': 'filesfm', 'credential': 'password', 'credentialType': 'password' } , { 'urls': [ 'stun:stun-ltc.files.fm:80' ], 'username': 'filesfm', 'credential': 'password', 'credentialType': 'password' } , { 'urls': [ 'turn:stun-ltc.files.fm:80' ], 'username': 'filesfm', 'credential': 'password', 'credentialType': 'password' } ] } } }; */ var objOptions = { tracker: { rtcConfig: { 'iceServers': [ { 'urls': [ 'stun:stun.files.fm:443' ], 'username': 'filesfm', 'credential': 'password', 'credentialType': 'password' } , { 'urls': [ 'turn:stun.files.fm:443' ], 'username': 'filesfm', 'credential': 'password', 'credentialType': 'password' } ] } } }; objOptions.WebRequests_QueryString = 'PHPSESSID=' + PHPSESSID; _this.objFilesFmP2P = new FilesFm_P2P(objOptions); _this.objClient = _this.objFilesFmP2P.getClient(); } catch ( objError ) { fncCallback_Error(); return; } // Add listener for the WebTorrent client's errors this.objClient.on( 'error', function ( objError ) { _this.setFormViewStatus( 'download_error' ); } ); fncCallback_Success(); }; // Initiate a new torrent this.addTorrent = function( fncCallback_Success, fncCallback_Error ) { var _this = this; // Add a new torrent for the WebTorrent client try { _this.objFilesFmP2P.addTorrent( this.strTorrentFor, this.strTorrentHash, function ( objTorrent ) { _this.objTorrent = objTorrent; _this.objTorrent.on('error', function (err) { _this.setFormViewStatus( 'download_error' ); }); _this.arrTorrentClientFiles = []; // Torrent file downloaded _this.objTorrent.on( 'ready', function () { _this.torrentMakeSelection(); _this.intDownloadStartedTimestamp = (new Date()).getTime(); // Update the form's progress info every second setInterval( function() { _this.updateFormViewSharingProgress(); } , 1000 ); // Add listener for download finished event _this.objTorrent.on( 'done', function() { _this.onDownloadFinished(); _this.setupDownloadLinks(); } ); // Send connections and file pieces download statistics for saving every 10 seconds setInterval( function() { _this.registerStatistics(); }, 1000 * 10 ); fncCallback_Success(); }); // Add listener for a new piece download _this.objStatistics.pieces = []; _this.objTorrent.on( 'piece_done', function ( strRemoteAddress, strLocalAddress, intPieceIndex, intPieceOffset, intPieceBufferLength, intPieceDownloadStartTimestamp ) { _this.onNewPieceDownload( strRemoteAddress, strLocalAddress, intPieceIndex, intPieceOffset, intPieceBufferLength, intPieceDownloadStartTimestamp ); } ); // Add listener for a new connections _this.objStatistics.connections = []; _this.objTorrent.on( 'wire', function ( objWire ) { _this.onNewConnection( objWire ); } ); }, function ( objTorrentStatusResponse ){ $( '#webtorrent_download_form__alert_container__wait .alert_main_text' ).html( _this.getText( 'GeneratingTorrentFile_WithTimeLeft' ).replace('[[TIME_LEFT]]', secondsToString( objTorrentStatusResponse.GenerationTimeRequired ) ) ); }, function ( error ) { fncCallback_Error( error ); } ); } catch( objError ) { fncCallback_Error(); return; } } // Select only required files this.torrentMakeSelection = function () { var _this = this; // Is file filter active? var bolDownloadOnlySpecificFiles = this.arrFilterFileNames && this.arrFilterFileNames.length; if ( bolDownloadOnlySpecificFiles ) { // Remove default selection (whole torrent) this.objTorrent.deselect( 0, this.objTorrent.pieces.length - 1, false ); } else { // Add default selection (whole torrent) this.objTorrent.select( 0, this.objTorrent.pieces.length - 1 ); } // Reset torrent files array this.arrTorrentClientFiles = []; // Select only required file, deselect all other. Also register files in files array. this.objTorrent.files.forEach( function ( file ) { if ( bolDownloadOnlySpecificFiles && _this.arrFilterFileNames && _this.arrFilterFileNames.length && _this.arrFilterFileNames.indexOf( file.name ) === -1 ) { // Bug in Webtorrent, also need to deselect specific file. file.deselect(); } else { // Register file in array fro progress calculation. _this.arrTorrentClientFiles.push(file); file.select(); } } ); } this.initP2PGraph = function() { try { this.objP2PGraph = new window.P2PGraph( '#webtorrent_download_form__p2p_graph' ); // Quick fix - remove duplicate svgs. var intSvgCount = $( '#webtorrent_download_form__p2p_graph SVG' ).length; if ( intSvgCount > 1 ) { for ( var i = 0; i < intSvgCount - 1; i++ ) $( $( '#webtorrent_download_form__p2p_graph SVG' )[ i ] ).remove(); } var _this = this; try { this.objP2PGraph.add( { id: 'You', me: true, name: _this.getText( 'GraphPeerYou' ) } ); } catch ( ex ) { console.error( ex ); } // Register wires made before graph initialization for ( var i = 0; i < this.arrGraphUnregisteredWires.length; i++ ) { this.onNewConnection( this.arrGraphUnregisteredWires[ i ] ); } } catch (ex) { console.error(ex); } } this.setupDownloadButton = function () { var intFileCount = this.objTorrent.files.length; if ( this.arrFilterFileNames.length > 0 ) intFileCount = this.arrFilterFileNames.length; jqDownloadButton .html(this.getText( intFileCount > 1 ? 'SaveMultipleFiles' : 'SaveSingleFile' )) .addClass('visible'); jqDownloadButton.attr('title', this.getText('SaveInactiveTitle') ); checkTooltips( jqDownloadButton.parent()[0] ); jqDownloadButton.on('click', this.saveAllDownloadedFiles); }; // Update the download/upload progress info in the form this.updateFormViewSharingProgress = function() { var _this = this; if ( ! this.bolDownloadFinished ) { // Get total and downloaded bytes from torrent file array var intTotalBytes = 0; //var intDownloadedBytes = 0; for (var i=0; i 0 ? this.arrTorrentClientFiles[i].downloaded : 0); */ } var intDownloadedBytes = this.objTorrent.received; if ( this.intTotalBytes < intTotalBytes ) this.intTotalBytes = intTotalBytes; if ( this.intDownloadedBytes < intDownloadedBytes ) this.intDownloadedBytes = intDownloadedBytes; var intDownloadLeftBytes = this.intTotalBytes - this.intDownloadedBytes; if ( intDownloadLeftBytes < 0 ) intDownloadLeftBytes = 0; // Update progress bar var dblProgressPercents = ( this.intDownloadedBytes / this.intTotalBytes ) * 100; if (dblProgressPercents>100) dblProgressPercents = 100; if ( this.dblProgressPercents < dblProgressPercents ) this.dblProgressPercents = dblProgressPercents; $( '#webtorrent_download_form__main_content__wt_download__progress__bar_inner' ).stop(true, true).animate( { width: this.dblProgressPercents + '%' } , 1000 , function() { $( '#webtorrent_download_form__main_content__wt_download__progress__bar_text' ).html( Math.round(_this.dblProgressPercents) + '%' ); } ); if ( this.dblProgressPercents == 100 ) { this.bolDownloadFinished = true; } // Update estimated download end time //var intTimeRemaining_Seconds = this.objTorrent.timeRemaining; var intTimeRemaining_Seconds = intDownloadLeftBytes / this.objClient.downloadSpeed; if ( intTimeRemaining_Seconds == Infinity || this.objTorrent.timeRemaining == Infinity ) { strTimeRemaining = '--:--:--'; } else { var intTimeRemaining_Days = Math.floor( intTimeRemaining_Seconds / ( 60 * 60 * 24 ) ); var intTimeRemaining_Hours = Math.floor( ( intTimeRemaining_Seconds % ( 60 * 60 * 24 ) ) / ( 60 * 60 ) ); var intTimeRemaining_Minutes = Math.floor( ( intTimeRemaining_Seconds % ( 60 * 60 ) ) / ( 60 ) ); var intTimeRemaining_Seconds = Math.floor( ( intTimeRemaining_Seconds % ( 60 ) ) ); var strTimeRemaining = ''; if ( intTimeRemaining_Days > 0 ) { strTimeRemaining = intTimeRemaining_Days + 'd '; } if ( intTimeRemaining_Hours < 10 ) { strTimeRemaining += '0'; } strTimeRemaining += intTimeRemaining_Hours + ':'; if ( intTimeRemaining_Minutes < 10 ) { strTimeRemaining += '0'; } strTimeRemaining += intTimeRemaining_Minutes + ':'; if ( intTimeRemaining_Seconds < 10 ) { strTimeRemaining += '0'; } strTimeRemaining += intTimeRemaining_Seconds; } $( '#webtorrent_download_form__main_content__wt_download__status__in_progress__value' ).html( strTimeRemaining ); // Update downloaded size $( '#webtorrent_download_form__sharing_size__download' ).html( this.convertBytesToSizeSting( this.objTorrent.received ) + ' ' + _this.getText( 'SizeOf' ) + ' ' + this.convertBytesToSizeSting( intTotalBytes ) ); $( '#webtorrent_download_form__sharing_speed__download' ).html( this.convertBytesToSizeSting( this.objTorrent.downloadSpeed ) + '/sec' ); } // Update uploaded size $( '#webtorrent_download_form__sharing_size__upload' ).html( this.convertBytesToSizeSting( this.objTorrent.uploaded ) ); $( '#webtorrent_download_form__sharing_speed__upload' ).html( this.convertBytesToSizeSting( this.objTorrent.uploadSpeed ) + '/sec' ); } // Finish download of files: update the form's info and output files this.onDownloadFinished = function() { // Show in form that download is finished this.setFormViewStatus( 'donwload_finished' ); this.updateFormViewSharingProgress(); if ( ! this.bolAllowRegisterStatistics ) { setTimeout( this.saveAllDownloadedFiles, 500 ); return; } var _this = this; // Register that download is finished $.ajax( { type : 'POST', dataType : 'json', url : '/ajax/webtorrent_download_form.php?PHPSESSID='+ this.PHPSESSID , data : { action : 'register_download_finished' , wt_session_key : this.strWTSessionKey } , success : function() { setTimeout(_this.saveAllDownloadedFiles, 500); } , error : function() { _this.setFormViewStatus( 'download_error' ); } } ); }; this.bloDownloadLinksSavedOnce = false; this.setupDownloadLinks = function (){ if (this.bloDownloadLinksSavedOnce) return; this.bloDownloadLinksSavedOnce = true; var _this = this; var jqDownloadLinksContainer = $('#webtorrent_download_form__file_links'); jqDownloadButton .addClass('active') .attr('my_title', jqDownloadButton.text()); // Output for download the files _this.objTorrent.files.forEach( function( objFile ) { try { var bolDownloadOnlySpecificFiles = _this.arrFilterFileNames && _this.arrFilterFileNames.length; if ( ! bolDownloadOnlySpecificFiles || _this.arrFilterFileNames.indexOf( objFile.name ) !== -1 ) { objFile.getBlobURL( function ( objError, strBlobURL ) { if ( objError ) { throw objError } var objFileDownloadEl = document.createElement( 'a' ); objFileDownloadEl.download = objFile.name; objFileDownloadEl.href = strBlobURL; objFileDownloadEl.textContent = 'Download ' + objFile.name; jqDownloadLinksContainer.append( objFileDownloadEl ); } ); } } catch ( objError ) { console.error(objError); _this.setFormViewStatus( 'download_error' ); } } ) }; this.saveAllDownloadedFiles = function (){ var _this = this; var jqDownloadLinksContainer = $('#webtorrent_download_form__file_links'); var intNextTimeout = 0; $('a', jqDownloadLinksContainer).each(function (){ var domLink = this; setTimeout(function(){ domLink.click(); }, intNextTimeout); intNextTimeout += 1000; }); }; // Register a new peer connection this.onNewConnection = function( objWire ) { // Skip destroyed wires if ( objWire.destroyed ) return; try { if ( ! this.objP2PGraph ) { // Register wires made before graph initialization this.arrGraphUnregisteredWires.push( objWire ); return; } this.objStatistics.connections.push( { peer_key : objWire.peerId , local_ip : ( typeof objWire.localAddress == 'undefined' ? '' : objWire.localAddress ) , local_port : ( typeof objWire.localPort == 'undefined' ? '' : objWire.localPort ) , remote_ip : ( typeof objWire.remoteAddress == 'undefined' ? '' : objWire.remoteAddress ) , remote_port : ( typeof objWire.remotePort == 'undefined' ? '' : objWire.remotePort ) , date_start_tmst : Math.round( ( new Date() ).getTime() / 1000 ) } ); var _this = this; var strPeerID = objWire.peerId; var r = true; if ( objWire.type === 'webSeed' ) { this.objP2PGraph.add( { id: strPeerID, me: false, name: _this.getText( 'GraphPeerServer' ), webseed: true } ); } else { if ( objWire.remoteAddress ) { var ipParts = objWire.remoteAddress.split( '.' ); delete ipParts[ 0 ]; var maskedAddress = "*" + ipParts.join( '.' ); } else { var maskedAddress = _this.getText( 'UnknownIpAddress' ); } r = this.objP2PGraph.add( { id: strPeerID, me: false, name: maskedAddress } ); } if ( r !== false ) { this.objP2PGraph.connect( 'You', strPeerID ); this.objP2PGraph.rate( 'You', strPeerID, 1000 * 1000 ); objWire.on( 'close', function ( a, b ) { _this.objP2PGraph.disconnect( 'You', strPeerID ); _this.objP2PGraph.remove( strPeerID ); } ); } } catch (ex) { console.error(ex); } } // Register a new file piece's download this.onNewPieceDownload = function( strRemoteAddress, strLocalAddress, intPieceIndex, intPieceOffset, intPieceBufferLength, intPieceDownloadStartTimestamp ) { return; var strLocalIP = ''; var strLocalPort = ''; if ( strLocalAddress != null ) { var arrLocalAddress = strLocalAddress.split( ':' ); strLocalIP = arrLocalAddress[ 0 ]; strLocalPort = arrLocalAddress[ 1 ]; } var strRemoteIP = ''; var strReomtePort = ''; if ( strRemoteAddress != null ) { var arrRemoteAddress = strRemoteAddress.split( ':' ); strRemoteIP = arrRemoteAddress[ 0 ]; strReomtePort = arrRemoteAddress[ 1 ]; } this.objStatistics.pieces.push( { piece_index : intPieceIndex , piece_offset : intPieceOffset , piece_size : intPieceBufferLength , date_start_tmst : Math.round( intPieceDownloadStartTimestamp / 1000 ) , date_end_tmst : Math.round( ( new Date() ).getTime() / 1000 ) , local_ip : strLocalIP , local_port : strLocalPort , remote_ip : strRemoteIP , remote_port : strReomtePort } ); } // Register statistics of connections and piece downloads this.bolPrevFinished_registerStatistics = true; this.registerStatistics = function() { if ( ! this.bolAllowRegisterStatistics ) { return; } if ( ! this.bolPrevFinished_registerStatistics ) { return; } this.bolPrevFinished_registerStatistics = false; var objStaticticsClone = {}; $.extend( objStaticticsClone, this.objStatistics ); this.objStatistics.connections = []; this.objStatistics.pieces = []; var _this = this; $.ajax( { type : 'POST', dataType : 'json', url : '/ajax/webtorrent_download_form.php?PHPSESSID='+ this.PHPSESSID , data : { action : 'register_statistics' , wt_session_key : this.strWTSessionKey , statistics : objStaticticsClone } , success : function( objResponse ) { if ( objResponse[ 'status' ] == 'error' ) { $.extend( _this.objStatistics, objStaticticsClone ); } _this.bolPrevFinished_registerStatistics = true; } , error : function() { $.extend( _this.objStatistics, objStaticticsClone ); _this.bolPrevFinished_registerStatistics = true; } } ); } // Update the form's view this.setFormViewStatus = function( strStatus ) { if ( strStatus == 'form_loading' ) { $( '#webtorrent_download_form__main_content__wt_download__progress__bar_inner' ).width( 0 ); $( '#webtorrent_download_form__main_content__wt_download__progress__bar_text' ).html( '' ); $( '#webtorrent_download_form__main_content__wt_download__status__in_progress__value' ).html( '--:--:--' ); $( '#webtorrent_download_form__sharing_size__download' ).html( '0 kB' ); $( '#webtorrent_download_form__sharing_speed__download' ).html( '' ); $( '#webtorrent_download_form__sharing_size__upload' ).html( '0 kB' ); $( '#webtorrent_download_form__sharing_speed__upload' ).html( '' ); $( '#webtorrent_download_form__torrent_file_url' ).attr( 'href', 'javascript:void()' ); $( '#webtorrent_download_form__top_alerts_container .alert_container' ).hide(); $( '#webtorrent_download_form__main_content' ).hide(); $( '#webtorrent_download_form__alert_container__wait .alert_main_text' ).html( this.getText( 'PleaseWait' ) ); $( '#webtorrent_download_form__alert_container__wait' ).css('display', 'table'); $( '#webtorrent_download_form__desktop_clients_line' ).hide(); $( '#webtorrent_download_form__top_alerts_container' ).css( 'marginTop', "12px" ); } else if ( strStatus == 'browser_has_not_p2p_support' ) { $( '#webtorrent_download_form__top_alerts_container .alert_container' ).hide(); $( '#webtorrent_download_form__alert_container__error .alert_main_text' ).html( this.getText( 'BrowserHasNoSupport' ) ); $( '#webtorrent_download_form__alert_container__error' ).css('display', 'table'); } else if ( strStatus == 'donwload_in_progress' ) { $( '#webtorrent_download_form__top_alerts_container .alert_container' ).hide(); $( '#webtorrent_download_form__main_content' ).show(); $( '#webtorrent_download_form__main_content__wt_download' ).removeClass(); $( '#webtorrent_download_form__main_content__wt_download' ).addClass( 'in_progress' ); $( '#webtorrent_download_form__desktop_clients_line' ).show(); $( '#webtorrent_download_form__top_alerts_container' ).css( 'marginTop', "0" ); } else if ( strStatus == 'donwload_finished' ) { $( '#webtorrent_download_form__main_content__wt_download' ).removeClass(); $( '#webtorrent_download_form__main_content__wt_download' ).addClass( 'finished' ); $( '#webtorrent_download_form__desktop_clients_line' ).show(); $( '#webtorrent_download_form__top_alerts_container' ).css( 'marginTop', "0" ); } else if ( strStatus == 'download_error' ) { $( '#webtorrent_download_form__main_content__wt_download' ).removeClass(); $( '#webtorrent_download_form__main_content__wt_download' ).addClass( 'download_error' ); $( '#webtorrent_download_form__desktop_clients_line' ).show(); $( '#webtorrent_download_form__top_alerts_container' ).css( 'marginTop', "0" ); } } // Convert bytes to size string this.convertBytesToSizeSting = function( intBytes ) { var strSizeSting = ''; if ( intBytes < 1024 ) { strSizeSting = intBytes + ' B'; } else { var intKB = Math.round( intBytes / 1024 ); if ( intKB < 1024 ) { strSizeSting = intKB + ' kB'; } else { var intMB = Math.round( intKB / 1024 ); if ( intMB < 1024 ) { strSizeSting = intMB + ' MB'; } else { var intGB = Math.round( intMB / 1024 ); strSizeSting = intGB + ' GB'; } } } return strSizeSting; } // Get the text's translation this.getText = function( strKey ) { if ( typeof this.objTextTranslations[ strKey ] != 'undefined' ) { return this.objTextTranslations[ strKey ]; } else { return ''; } } }