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

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