PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.13.1
WpStream – Live Streaming, Video on Demand, Pay Per View v4.13.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.13.1, at admin/js/admin_control.js

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