PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.12.1
WpStream – Live Streaming, Video on Demand, Pay Per View v4.12.1
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / admin / js / admin_control.js

admin_control.js in WpStream – Live Streaming, Video on Demand, Pay Per View 4.12.1, at admin/js/admin_control.js

715 lines 24.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*global $, jQuery, */
2 var counters={};
3
4 const CHUNK_SIZE = 128 * 1024 * 1024; // 128MB in bytes
5 const MAX_STANDARD_UPLOAD_SIZE = 5 * 1000000000; // 5GB in bytes
6 const MAX_RETRIES = 3;
7 const RETRY_DELAY = 5000;
8
9 jQuery(document).ready(function ($) {
10 "use strict";
11
12
13 WpStreamUtils.generate_download_link();
14 WpStreamUtils.generate_delete_link();
15 wpstream_handle_video_selection();
16 wpstream_handle_caption_selection();
17 wpstream_upload_images_in_wpadmin();
18
19 wpstream_upload_player_logo();
20
21
22 function social_media_toggle(social_class){
23
24 jQuery('.'+social_class).on('change',function(){
25
26 if( $(this).prop('checked') ){
27 jQuery($(this).parent().parent().find( '.'+social_class+'_container' )).slideDown('100');
28 }else{
29 jQuery($(this).parent().parent().find( '.'+social_class+'_container' )).slideUp('100');
30 }
31
32 });
33 }
34
35
36
37 jQuery('.wpstream_notices .notice-dismiss').on('click',function(){
38
39 var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
40 var notice_type = $(this).parent().attr('data-notice-type');
41 var nonce = $('#wpstream_notice_nonce').val();
42
43
44 jQuery.ajax({
45 type: 'POST',
46 url: ajaxurl,
47 data: {
48 'action' : 'wpstream_update_cache_notice',
49 'notice_type' : notice_type,
50 'security' : nonce
51 },
52 success: function (data) {
53
54
55 },
56 error: function (errorThrown) {
57
58 }
59 });
60 });
61
62 $( '.inputfile' ).each( function(){
63 var $input = $( this ),
64 $label = $input.next( 'label' ),
65 labelVal = $label.html();
66
67 $input.on( 'change', function( e )
68 {
69 var fileName = '';
70
71 if( this.files && this.files.length > 1 )
72 fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
73 else if( e.target.value )
74 fileName = e.target.value.split( '\\' ).pop();
75
76 if( fileName )
77 $label.find( 'span' ).html( fileName );
78 else
79 $label.html( labelVal );
80 });
81
82 // Firefox bug fix
83 $input
84 .on( 'focus', function(){ $input.addClass( 'has-focus' ); })
85 .on( 'blur', function(){ $input.removeClass( 'has-focus' ); });
86 });
87
88
89
90 /*
91 *
92 * File Upload
93 *
94 */
95
96
97 var form = $('.direct-upload');
98 var multipartUploadData = null;
99 var handle = null;
100 var currentUploadedParts = [];
101
102 form.fileupload({
103 url: form.attr('action'),
104 type: form.attr('method'),
105
106 datatype: 'xml',
107 add: function (event, data) {
108
109
110 if( data.files[0].type!=='video/mp4' && data.files[0].type!=='video/quicktime'){
111 jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.not_accepted);
112 jQuery('#wpstream_label_action').text(wpstream_admin_control_vars.choose_a_file);
113 return;
114 }
115
116 // Get file info
117 var file = data.files[0];
118 var fileSizeInBytes = file.size;
119 var file_size = (parseInt(fileSizeInBytes, 10))/1000000;
120 var user_storage = jQuery('#wpstream_storage').val();
121 var user_band = jQuery('#wpstream_band').val();
122
123 if(file_size > user_storage || file_size > user_band){
124 jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.no_band_no_store);
125 return;
126 }
127
128 // Update UI
129 $('#wpstream_label_action').text(wpstream_admin_control_vars.uploading);
130 $('#wpstream_upload').prop('disabled', true);
131 $('label[for="wpstream_upload"]')
132 .css('cursor','not-allowed')
133 .css('background-color','#8c8f94');
134
135 jQuery('#wpstream_uploaded_mes').empty();
136
137 // Show warning message if leaving page during upload
138 window.onbeforeunload = function () {
139 return 'You have unsaved changes.';
140 };
141
142 // Set content headers
143 form.find('input[name="Content-Type"]').val(file.type);
144 form.find('input[name="Content-Length"]').val(file.size);
145
146 // Show the progress bar
147 var bar = $('<div class="progress" data-mod="'+file.size+'"><div class="bar"></div></div>');
148 $('.progress-bar-area').append(bar);
149 bar.slideDown('fast');
150
151 // Check if file size exceeds 5GB and requires multipart upload
152 if (fileSizeInBytes > MAX_STANDARD_UPLOAD_SIZE) {
153 // Show multipart upload message
154 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.exceeding_limit);
155 // Initiate multipart upload
156 initiateMultipartUpload(file, data);
157 } else {
158 // Standard upload for files under 5GB
159 data.submit();
160 }
161 },
162 progress: function (e, data) {
163 // Standard upload progress
164 if (!multipartUploadData) {
165 var percent = Math.round((data.loaded / data.total) * 100);
166 $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', percent + '%').html(percent+'%');
167 }
168 },
169
170 fail: function () {
171 handleUploadFailure();
172 },
173
174 error: function () {
175 handleUploadFailure();
176 },
177 done: function (event, data) {
178 if (!multipartUploadData) {
179 // Handle standard upload completion
180 handleUploadSuccess(data.files[0]);
181 }
182 }
183 });
184
185 // Function to initiate multipart upload
186 function initiateMultipartUpload(file, data) {
187 var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
188 var fileName = file.name;
189 var fileSize = file.size;
190
191 // Calculate number of parts needed
192 var numParts = Math.ceil(fileSize / CHUNK_SIZE);
193
194 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.preparing_multipart);
195
196 jQuery.ajax({
197 type: 'POST',
198 url: ajaxurl,
199 dataType: 'json',
200 data: {
201 'action': 'wpstream_initiate_multipart_upload',
202 'security': wpstream_admin_control_vars.multipart_upload_nonce,
203 'file_name': fileName,
204 'file_size': fileSize,
205 'content_type': file.type,
206 'parts': numParts
207 },
208 success: function(response) {
209 if (response.success) {
210 // Validate required data exists in response
211 if (!response.data ||
212 !response.data.multipart ||
213 !response.data.parts ||
214 !response.data.handle
215 ) {
216 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.invalid_response);
217 handleUploadFailure();
218 return;
219 }
220
221 multipartUploadData = {
222 parts: response.data.parts
223 };
224 currentUploadedParts = [];
225 handle = response.data.handle;
226
227 // Start uploading chunks
228 uploadNextChunk(file, 0, numParts);
229 } else {
230 jQuery('#wpstream_uploaded_mes').html(response.error || wpstream_admin_control_vars.upload_failed);
231 handleUploadFailure();
232 }
233 },
234 error: function() {
235 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed);
236 handleUploadFailure();
237 }
238 });
239 }
240
241 // Function to upload a chunk of the file
242 function uploadNextChunk(
243 file,
244 partIndex,
245 totalParts,
246 retryCount = 0
247 ) {
248 if (partIndex >= totalParts) {
249 // All parts uploaded, complete the multipart upload
250 completeMultipartUpload(file, totalParts);
251 return;
252 }
253
254 var start = partIndex * CHUNK_SIZE;
255 var end = Math.min((partIndex + 1) * CHUNK_SIZE, file.size);
256 var chunk = file.slice(start, end);
257 var partNumber = partIndex + 1;
258
259 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.uploading_part.replace('{part}', partNumber).replace('{total}', totalParts));
260
261 // Update progress bar to show overall progress
262 var overallProgress = Math.round((partIndex / totalParts) * 100);
263 jQuery('.progress[data-mod="'+file.size+'"] .bar').css('width', overallProgress + '%').html(overallProgress+'%');
264
265 // Upload the chunk
266 var xhr = new XMLHttpRequest();
267 // xhr.open('POST', 'https://s3.amazonaws.com/' + partData.bucket, true);
268 xhr.open('PUT', multipartUploadData.parts[partIndex], true);
269
270 xhr.onload = function() {
271 if (xhr.status === 204 || xhr.status === 200) {
272 currentUploadedParts.push({
273 PartNumber: partNumber,
274 });
275
276 // Upload next chunk
277 uploadNextChunk(file, partIndex + 1, totalParts);
278 } else {
279 var errorInfo = {
280 status: xhr.status,
281 statusText: xhr.statusText,
282 response: xhr.responseText,
283 headers: xhr.getAllResponseHeaders()
284 };
285 console.error('Part Upload Failed:', errorInfo);
286
287 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed_part.replace('{part}', partNumber));
288 handleUploadFailure();
289 }
290 };
291
292 xhr.onerror = function() {
293 handleChunkError(file, partIndex, totalParts, retryCount, xhr);
294 // jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed_part.replace('{part}', partNumber));
295 // handleUploadFailure();
296 };
297
298 xhr.upload.onprogress = function(e) {
299 if (e.lengthComputable) {
300 // Calculate chunk progress and overall progress
301 var chunkProgress = (e.loaded / e.total) * 100;
302 var overallProgress = Math.round((partIndex / totalParts * 100) + (chunkProgress / totalParts));
303 jQuery('.progress[data-mod="'+file.size+'"] .bar').css('width', overallProgress + '%').html(overallProgress+'%');
304 }
305 };
306
307 xhr.send(chunk);
308 }
309
310 // Function to retry uploading when failing
311 // Adding a delay of RETRY_DELAY seconds before retrying
312 function handleChunkError(file, partIndex, totalParts, retryCount, xhr) {
313 var partNumber = partIndex + 1;
314
315 if ( retryCount < MAX_RETRIES ) {
316 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed_part_retry.replace('{part}', partNumber).replace('{times}', retryCount + 1));
317 setTimeout(function() {
318 uploadNextChunk(file, partIndex, totalParts, retryCount + 1);
319 }, RETRY_DELAY);
320 } else {
321 handleUploadFailure();
322 }
323
324 }
325
326 // Function to complete multipart upload
327 function completeMultipartUpload(file, totalParts) {
328 var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
329
330 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.completing_upload);
331 jQuery.ajax({
332 type: 'POST',
333 url: ajaxurl,
334 dataType: 'json',
335 data: {
336 'action': 'wpstream_complete_multipart_upload',
337 'security': wpstream_admin_control_vars.multipart_upload_nonce,
338 'parts': totalParts,
339 'file_name': file.name,
340 'handle': handle,
341 },
342 success: function(response) {
343 if (response.success) {
344 // Reset multipart data
345 multipartUploadData = null;
346 currentUploadedParts = [];
347
348 // Handle success
349 handleUploadSuccess(file);
350 } else {
351 jQuery('#wpstream_uploaded_mes').html(response.error || wpstream_admin_control_vars.upload_failed);
352 handleUploadFailure();
353 }
354 },
355 error: function(e) {
356 jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed);
357 handleUploadFailure();
358 }
359 });
360 }
361
362 // Handle upload failure
363 function handleUploadFailure() {
364 window.onbeforeunload = null;
365 jQuery('.bar').remove();
366 jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_failed);
367 jQuery('#wpstream_label_action').empty().html(wpstream_admin_control_vars.upload_failed2);
368 jQuery('#wpstream_upload').prop('disabled', false);
369 jQuery('label[for="wpstream_upload"]')
370 .css('cursor','')
371 .css('background-color','');
372
373 // Reset multipart upload data
374 multipartUploadData = null;
375 currentUploadedParts = [];
376 }
377
378 // Handle upload success
379 function handleUploadSuccess(file) {
380 window.onbeforeunload = null;
381 jQuery('.bar').remove();
382 jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_complete);
383 jQuery('#wpstream_label_action').text(wpstream_admin_control_vars.upload_complete2);
384 jQuery('#wpstream_upload').prop('disabled', false);
385 jQuery('label[for="wpstream_upload"]')
386 .css('cursor','')
387 .css('background-color','');
388
389 var new_file_name = file.name;
390 var new_file_size = Math.floor(file.size / 1048576);
391
392 var new_file_name_array = new_file_name.split(".");
393 var temp_file_name = new_file_name_array[0].split(' ').join('_');
394 temp_file_name = temp_file_name.replace(/\W/g, '');
395 new_file_name = temp_file_name+'.'+new_file_name_array[new_file_name_array.length-1];
396
397 var to_insert='<div class="wpstream_video_wrapper"><div class="wpstream_video_title"><div class="wpstream_video_notice"></div></div>';
398 to_insert += `<div class="wpstream_video_title"><strong class="storage_file_name">${wpstream_admin_control_vars.file_name_text}</strong><span class="storage_file_name_real">`+new_file_name+`</span><span class="storage_file_size">` + new_file_size + ` MB</span></div>`;
399 to_insert += `<div class="wpstream_video_pending">${wpstream_admin_control_vars.video_processing}</div>`;
400
401 jQuery('#video_management_title').after(to_insert);
402
403 WpStreamUtils.checkPendingVideos();
404 }
405
406 jQuery('#product-type').on('change',function(){
407
408 var product_type= jQuery('#product-type').val();
409 if(product_type==='live_stream' || product_type==='video_on_demand' || product_type==='wpstream_bundle' ){
410 jQuery('._sold_individually_field').show();
411 }
412
413 });
414
415 if(wpstream_findGetParameter('new_video_name')!=='' && wpstream_findGetParameter('new_video_name')!=null ){
416 jQuery('#product-type').val('video_on_demand').trigger('change');
417 }
418
419 if(wpstream_findGetParameter('new_stream')!=='' && wpstream_findGetParameter('new_stream')!=null ){
420 jQuery('#product-type').val('live_stream').trigger('change');
421 }
422
423 var product_type= jQuery('#product-type').val();
424 if ( product_type === 'video_on_demand' ) {
425 jQuery('.show_if_video_on_demand' ).show();
426 }else if ( product_type === 'live_stream' ) {
427 jQuery( '.show_if_live_stream' ).show();
428 } else if ( product_type === 'wpstream_bundle' ) {
429 jQuery( '.show_if_wpstream_bundle' ).show();
430 console.log ('we do click');
431 var element= jQuery('.general_tab');
432 console.log(element);
433 jQuery('.general_tab').trigger('click');
434 $('a[href="#general_product_data"]').click();
435 $('.product_data_tabs .tab.general_tab').click();
436 }
437
438
439
440
441
442 function wpstream_findGetParameter(parameterName) {
443 var result = null,
444 tmp = [];
445 location.search
446 .substr(1)
447 .split("&")
448 .forEach(function (item) {
449 tmp = item.split("=");
450 if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
451 });
452 return result;
453 }
454
455
456 jQuery('#_subscript_live_event').change(function(){
457 //alert('move it'+product_type);
458 if ( product_type === 'video_on_demand' || product_type === 'live_stream' || product_type === 'wpstream_bundle' ) {
459
460 }else{
461 var value= jQuery(this).val();
462 if(value==="no"){
463 jQuery("._movie_url_field").parent().removeClass("hide_if_subscription").show();
464 }else{
465 jQuery("._movie_url_field").parent().addClass("hide_if_subscription").hide();
466 }
467 }
468 });
469
470 jQuery('#_subscript_live_event').trigger('change');
471
472
473 $('#wpstream_product_type').change(function(){
474 jQuery('.video_free').hide();
475 jQuery('.video_free_external').hide();
476
477 jQuery('.wpstream_option_vod_source').hide();
478
479 if( jQuery('#wpstream_product_type').val()=== "2"){
480 jQuery('.video_free').show();
481 jQuery('.wpstream_show_recording').show();
482 }
483 if( jQuery('#wpstream_product_type').val()=== "3"){
484 jQuery('.video_free_external').show();
485 jQuery('.wpstream_show_external').show();
486 }
487 });
488 $('#wpstream_product_type').trigger('change');
489
490
491
492
493
494
495 $('.close_event').click(function(event){
496 event.preventDefault();
497 var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
498 var acesta = $(this);
499 var parent = $(this).parent().parent();
500 var notification_area = $(this).parent().find('.event_list_unit_notificationx');
501 var show_id = parseFloat( $(this).attr('data-show-id') );
502 var nonce = $('#wpstream_start_event_nonce').val();
503 //$(this).unbind();
504 notification_area.text('Closing Event');
505
506
507 jQuery.ajax({
508 type: 'POST',
509 url: ajaxurl,
510 dataType: 'json',
511 data: {
512 'action' : 'wpstream_close_event',
513 'security' : nonce,
514 'show_id' : show_id
515 },
516 success: function (data) {
517 parent.remove();
518 },
519 error: function (errorThrown) {
520
521 }
522 });
523
524 });
525 });
526
527
528
529 /*
530 * Upload images in admin
531 *
532 */
533 function wpstream_upload_images_in_wpadmin(){
534 console.log('wpstream_upload_images_in_wpadmin');
535 var idList = ["category_featured_image_button"];
536
537 for (var i = 0; i < idList.length; i++) {
538 var currentId = idList[i];
539 jQuery('#'+currentId).on( 'click', function(event) {
540 var parent=jQuery(this).parent();
541 wpstream_admin_return_uploaded_image().then(function(image) {
542 parent.find('.wpestate_landing_upload').val(image.url);
543 parent.find('.wpestate_landing_upload_id').val(image.id);
544
545 });
546
547 });
548
549 }
550 }
551
552
553 /*
554 * return uploaded image
555 *
556 */
557 function wpstream_admin_return_uploaded_image(){
558
559 return new Promise(function(resolve, reject) {
560 var mediaUploader = wp.media({
561 frame: "post",
562 state: "insert",
563 multiple: false
564 });
565
566 mediaUploader.on("insert", function(){
567 var image = mediaUploader.state().get("selection").first().toJSON();
568 resolve(image);
569 });
570
571 mediaUploader.open();
572 });
573 }
574
575
576
577
578
579 /*
580 * handle video selection for recording
581 *
582 */
583
584 function wpstream_handle_video_selection(){
585
586 jQuery('#wpstream_free_video_external_button').on( 'click', function(event) {
587 var parent=jQuery(this).parent();
588 wpstream_admin_return_uploaded_image().then(function(image) {
589 parent.find('#wpstream_free_video_external').val(image.url);
590 });
591 });
592 }
593
594 /*
595 * handle caption selection for recording
596 */
597 function wpstream_handle_caption_selection(){
598 jQuery('#wpstream_vod_captions_url_button').on( 'click', function(event) {
599 event.preventDefault();
600 var parent = jQuery(this).parent();
601 var button = jQuery(this);
602
603 var mediaUploader = wp.media({
604 title: wpstream_admin_control_vars.select_caption_file,
605 button: {
606 text: 'Select'
607 },
608 multiple: false,
609 library: {
610 type: 'text/vtt'
611 }
612 });
613
614 mediaUploader.on("select", function(){
615 var attachment = mediaUploader.state().get("selection").first().toJSON();
616 parent.find('#wpstream_closed_captions_file').val(attachment.url);
617 parent.find('.wpstream_caption_file_display').text(attachment.filename);
618
619 button.hide();
620
621 if( parent.find('.wpstream_remove_caption').length === 0 ){
622 parent.append('<input type="button" class="button wpstream_remove_caption" value="' + wpstream_admin_control_vars.remove_button + '" style="margin-left: 5px;" />');
623 }
624 });
625
626 mediaUploader.open();
627 });
628
629 jQuery(document).on('click', '.wpstream_remove_caption', function(e){
630 e.preventDefault();
631 var parent = jQuery(this).parent();
632 parent.find('#wpstream_closed_captions_file').val('');
633 parent.find('.wpstream_caption_file_display').text('');
634
635 parent.find('#wpstream_vod_captions_url_button').show();
636
637 jQuery(this).remove();
638 });
639 }
640
641 /*
642 * return uploaded image
643 *
644 */
645 function wpstream_admin_return_uploaded_image(){
646
647
648 return new Promise(function(resolve, reject) {
649 var mediaUploader = wp.media({
650 frame: "post",
651 state: "insert",
652 multiple: false
653 });
654
655 mediaUploader.on("insert", function(){
656 var image = mediaUploader.state().get("selection").first().toJSON();
657 resolve(image);
658 });
659
660 mediaUploader.open();
661 });
662 }
663
664 function wpstream_upload_player_logo(){
665 var mediaUploader;
666
667 // Handle upload button click
668 jQuery('.wpstream-upload-image').on('click', function(e) {
669 e.preventDefault();
670
671 var button = jQuery(this);
672 var wrapper = button.closest('.wpstream-image-upload-wrapper');
673 var inputField = wrapper.find('input[type="hidden"]');
674 var previewArea = wrapper.find('.wpstream-image-preview');
675 var removeButton = wrapper.find('.wpstream-remove-image');
676
677 // Create media uploader instance if not already created
678 if (!mediaUploader) {
679 mediaUploader = wp.media({
680 title: wpstream_settings_vars.choose_image_text || 'Choose Image',
681 button: {
682 text: wpstream_settings_vars.select_image_text || 'Select Image'
683 },
684 multiple: false
685 });
686
687 // When image is selected in the media uploader
688 mediaUploader.on('select', function() {
689 var attachment = mediaUploader.state().get('selection').first().toJSON();
690 inputField.val(attachment.url);
691
692 previewArea.find('img').attr('src', attachment.url);
693 previewArea.show();
694 removeButton.show();
695 });
696 }
697
698 // Open the media uploader
699 mediaUploader.open();
700 });
701
702 // Handle remove button click
703 jQuery('.wpstream-remove-image').on('click', function(e) {
704 e.preventDefault();
705
706 var button = jQuery(this);
707 var wrapper = button.closest('.wpstream-image-upload-wrapper');
708 var inputField = wrapper.find('input[type="hidden"]');
709 var previewArea = wrapper.find('.wpstream-image-preview');
710
711 inputField.val('');
712 previewArea.hide();
713 button.hide();
714 });
715 }