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

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