1/*global $, jQuery, wpstream_start_streaming_vars*/ 2var counters={}; 3 4// post_type can be FTV or PPV channel or VOD 5var post_type = null; 6 7jQuery(document).ready(function ($) { 8 "use strict"; 9 10 wpstream_set_current_post_type(); 11 wpstream_check_live_connections(); 12 wpestate_start_modal_actions(); 13 wpestate_start_modal_error_actions(); 14 wpstream_tooltip(); 15 wpstream_copy_to_clipboard(); 16 // Commenting the following line because we are using the new webcaster 17 wpstream_webcaster_actions(); 18 wpstream_save_options_actions(); 19 wpstream_save_use_global_event_options(); 20 wpstream_bind_start_and_stop(); 21 22 wpstream_bind_stats_link(); 23 wpstream_adjust_settings_general(); 24 25}); 26 27function wpstream_safe_track_onboarding(action, step, element_type = 'button', element_name = '') { 28 if (typeof wpstream_track_onboarding_step === 'function') { 29 wpstream_track_onboarding_step(action, step, element_type, element_name); 30 } 31} 32 33function wpstream_set_current_post_type() { 34 let params = (new URL(document.location)).searchParams; 35 let branch= params.get( 'branch' ); 36 branch = parseInt( branch ); 37 38 if( isNaN( branch ) ) { 39 post_type = null; 40 } 41 42 switch ( branch ) { 43 case 1: 44 post_type = 'ftv_channel'; 45 break; 46 case 2: 47 post_type = 'ppv_channel'; 48 break; 49 case 3: 50 post_type = 'ftv_vod'; 51 break; 52 case 4: 53 post_type = 'ppv_vod'; 54 break; 55 default: 56 post_type = null; 57 } 58} 59 60/* 61* 62* genereal settings - low latency vs bitrate vs encrypt 63* 64*/ 65 66 67function wpstream_adjust_settings_general(){ 68 69 jQuery('.theme_options_tab_wpstream .wpstream_slider').on('click',function(event){ 70 event.stopPropagation(); 71 var parent = jQuery(this).parent(); 72 var input_element = parent.find('.wpstream_event_option_item'); 73 var attr_value = input_element.attr('data-attr-ajaxname'); 74 75 76 if( attr_value === 'adaptive_bitrate' || attr_value==='low_latency'){ 77 78 var timer = setTimeout(function() { 79 80 if( jQuery('.wpstream-setting-adaptive_bitrate .wpstream_event_option_item').is(':checked') || 81 jQuery('.wpstream-setting-low_latency .wpstream_event_option_item').is(':checked') ){ 82 jQuery('.wpstream-setting-encrypt .wpstream_event_option_item') .removeAttr('checked'); 83 } 84 }, 300); 85 86 } 87 88 if( attr_value === 'encrypt'){ 89 var timer = setTimeout(function() { 90 91 if( jQuery('.wpstream-setting-encrypt .wpstream_event_option_item').is(':checked') ){ 92 jQuery('.wpstream-setting-low_latency .wpstream_event_option_item') .removeAttr('checked'); 93 jQuery('.wpstream-setting-adaptive_bitrate .wpstream_event_option_item') .removeAttr('checked'); 94 } 95 }, 300); 96 97 } 98 99 }); 100} 101 102 103 104 105 106 107 108 109 110 111/* 112* 113* Bind block stats link 114* 115*/ 116 117function wpstream_bind_stats_link(){ 118 119 jQuery('.wpstream_statistics_channel,.start_webcaster').each(function(event){ 120 var selected_icon = jQuery(this); 121 selected_icon.on('click',function(event){ 122 if(selected_icon.hasClass('wpstream_inactive_icon')){ 123 event.preventDefault(); 124 event.stopPropagation(); 125 } 126 127 }); 128 129 }) 130 131 132} 133 134 135 136 137/* 138*
139* Bind Start and Stop channel 140* 141*/ 142 143 144function wpstream_bind_start_and_stop(){ 145 146 jQuery('.start_event.wpstream_button').each(function(element){ 147 var start_button=jQuery(this); 148 wpstream_bind_start_event(start_button); 149 }); 150 151 152 jQuery('.wpstream_stop_event').each(function(element){ 153 var stop_button=jQuery(this); 154 wpstream_bind_stop_event(stop_button); 155 }); 156 157} 158 159 160/* 161* 162* Bind start channel action 163* 164*/ 165var start_onboarding=''; 166function wpstream_bind_start_event(button){ 167 168 button.click(function(event){ 169 wpstream_safe_track_onboarding('start_stream_clicked', 'wpstream_' + post_type); 170 var basicStreaming = jQuery('#wpstream_basic_streaming').val() === 'true'; 171 if (basicStreaming){ 172 console.log("doing basic streaming"); 173 if(!confirm(wpstream_start_streaming_vars.basic_streaming_warning)){ 174 return false; 175 } 176 } 177 178 event.preventDefault(); 179 button.unbind('click'); 180 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 181 var acesta = jQuery(this); 182 var notification_area = jQuery(this).parent().find('.event_list_unit_notification'); 183 var curent_content = jQuery(this).parent().find('.server_notification'); 184 var is_record = false; 185 var is_encrypt = false; 186 var show_id = parseFloat( jQuery(this).attr('data-show-id') ); 187 var nonce = jQuery('#wpstream_start_event_nonce').val(); 188 var parent = jQuery(this).parent(); 189 190 if( jQuery(this).parent().find('.record_event').is(":checked") ){ 191 is_record = true; 192 } 193 194 if( jQuery(this).parent().find('.encrypt_event').is(":checked") ){ 195 is_encrypt = true; 196 } 197 parent.find('.wpstream_show_settings').addClass('wpstream_inactive_icon'); 198 jQuery(this).addClass('wpstream_turning_on').empty().html(wpstream_start_streaming_vars.start_streaming_action+'<div class="wpstream_loader"></div><div class="wpstream_tooltip">'+wpstream_start_streaming_vars.turning_on_tooltip+'</div>'); 199 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_turning_on); 200 201 jQuery.ajax({ 202 type: 'POST', 203 url: ajaxurl, 204 dataType: 'json', 205 timeout: 300000, 206 207 data: { 208 'action' : 'wpstream_give_me_live_uri', 209 'security' : nonce, 210 'show_id' : show_id, 211 'is_record' : is_record, 212 'is_encrypt' : is_encrypt, 213 'basic_streaming' : basicStreaming, 214 'start_onboarding' : start_onboarding, 215 216 217 }, 218 success: function (data) { 219 220 221 222 if(data.conected===true){ 223 224 if(data.event_data==='err1'){ 225 226 wpstream_show_error_on_start(wpstream_start_streaming_vars.error1,parent) 227 228 }else if(data.event_data ==='failed event creation'){ 229 230 wpstream_show_error_on_start(wpstream_start_streaming_vars.failed_event_creation,parent) 231 232 }else{ 233 curent_content.empty(); 234 var counter = setInterval( function (){ 235 wpstream_check_live_connections_on_start(parent,show_id,data.event_data,data)},10000); 236 counters['stop'+show_id]=counter; 237 238 } 239 240 241 }else{ 242 wpstream_show_error_on_start(data.error,parent) 243 } 244 245 }, 246 error: function (jqXHR,textStatus,errorThrown) { 247 } 248 }); 249 250 }); 251 252} 253 254 255/* 256*
257* Bind Stop channel action 258* 259*/ 260 261function wpstream_bind_stop_event(button){ 262 button.click(function(event){ 263 wpstream_safe_track_onboarding( 'stop_stream_clicked', 'wpstream_' + post_type ); 264 265 266 if(!confirm(wpstream_start_streaming_vars.turn_off_confirm)){ 267 return false; 268 } 269 button.unbind('click'); 270 271 272 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 273 var show_id = parseFloat( jQuery(this).attr('data-show-id') ); 274 var nonce = jQuery('#wpstream_start_event_nonce').val(); 275 var parent = jQuery(this).parent(); 276 var thisButton = jQuery(this); 277 278 thisButton.removeClass('wpstream_stop_event'); 279 thisButton.addClass('wpstream_turning_on').empty().html(wpstream_start_streaming_vars.stop_streaming_action+'<div class="wpstream_loader"></div><div class="wpstream_tooltip">'+wpstream_start_streaming_vars.turning_off_tooltip+'</div>'); 280 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_turning_off); 281 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 282 parent.find('.wpstream_stream_pro').addClass('wpstream_inactive_icon'); 283 parent.find('.wpstream_live_data').addClass('wpstream_inactive_icon'); 284 285 286 287 jQuery.ajax({ 288 type: 'POST', 289 url: ajaxurl, 290 dataType: 'json', 291 timeout: 300000, 292 293 data: { 294 'action' : 'wpstream_turn_of_channel', 295 'security' : nonce, 296 'show_id' : show_id 297 298 299 }, 300 success: function (data) { 301 302 console.log(data); 303 if(data.conected===true){ 304 305 thisButton.unbind('click'); 306 307 var counter = setInterval( function (){ 308 wpstream_check_live_connections_on_start(parent,show_id,'',data)},10000); 309 counters["stop"+show_id]=counter; 310 311 }else{ 312 313 wpstream_show_error_on_stop(data.error,parent) 314 } 315 316 }, 317 error: function (jqXHR,textStatus,errorThrown) { 318 319 } 320 }); 321 322 323 324 }); 325 326} 327 328 329/* 330* 331* Enable copy to clipboard 332* 333*/ 334 335function wpstream_enable_cliboard(parent){ 336 337 jQuery(parent).find('.copy_live_uri').click(function(){ 338 339 var value_uri = jQuery(parent).find('.wpstream_live_uri_text').text(); 340 var temp = jQuery("<input>"); 341 jQuery("body").append(temp); 342 jQuery(temp).val(value_uri).select(); 343 document.execCommand("copy"); 344 jQuery(temp).remove(); 345 346 }); 347 348 jQuery(parent).find('.copy_live_key').click(function(){ 349 var value_uri = jQuery(parent).find('.wpstream_live_key_text').text(); 350 var temp = jQuery("<input>"); 351 jQuery("body").append(temp); 352 jQuery(temp).val(value_uri).select(); 353 document.execCommand("copy"); 354 jQuery(temp).remove(); 355 356 }); 357} 358 359 360/* 361 * 362 * Check live events/channels on starts 363 * 364 * 365 * 366*/ 367 368 369function wpstream_check_live_connections_on_start( parent,show_id,server_id,data){ 370 371 // server_url is dns change 372 373 wpstream_check_event_status_in_js(show_id,'wpstream_check_live_connections_on_start', 374 function(server_status){ 375 376 if(server_status.status==='active' ){ 377 parent.find('.start_webcaster').attr('data-webcaster-url',server_status.webcaster_url); 378 parent.find('.wpstream_live_uri_text').text(server_status.obs_uri); 379 parent.find('.wpstream_live_key_text').text(server_status.obs_stream); 380 381 wpstream_event_ready_make_actions_visible(parent); 382 383 var larix_rtmp= server_status.obs_uri+server_status.obs_stream; 384 parent.find('.wpstream_larix_rtmp').text(larix_rtmp); 385 386 var larix_qr ='larix://set/v1?conn[][url]='+encodeURIComponent(larix_rtmp); 387 parent.find('.wpstream_start_with_larix_mobile').attr('href',larix_qr); 388 389 parent.find('.wpstream_larix_rtmp').text(larix_rtmp); 390 parent.find('.larrix_test').text(larix_rtmp); 391 392 393 var print_qrcode= "https://qrcode.tec-it.com/API/QRCode?size=small&dpi=110&data="+encodeURIComponent(larix_qr); 394 395 396 parent.find('.print_qrcode').attr('src',print_qrcode); 397 398 parent.parent().find('.wpstream_live_data').attr('href',server_status.live_data_url); 399 clearInterval( counters["stop"+show_id]); 400 401 402 if (typeof wpstream_integration_notifications === 'function') { 403 wpstream_integration_notifications(show_id); 404 } 405 406 407 }else if(server_status.status==='stopped' ){ 408 409 clearInterval( counters["stop"+show_id]); 410 wpstream_event_stopped_make_actions(parent); 411 412 }else if(server_status.status==='error' ){ 413 414 clearInterval( counters["stop"+show_id]); 415 var curent_content = parent.find('.wpstream_channel_status'); 416 curent_content.html('<div class="wpstream_channel_status not_ready_to_stream"><span class="dashicons dashicons-dismiss"></span>'+wpstream_start_streaming_vars.failed_event_creation+'</div>'); 417 } 418 }); 419 420} 421 422 423 424 425/* 426 * check channell id status 427 * 428 * @param {type} channel_id 429 * @param {type} callback 430 * @returns {undefined} 431 * 432 * 433*/ 434 435function wpstream_check_event_status_in_js(channel_id,notes,successCallback, errorCallback){ 436 437 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 438 var nonce = jQuery('#wpstream_start_event_nonce').val(); 439 440 jQuery.ajax({ 441 type: 'POST', 442 dataType: 'json', 443 url: ajaxurl, 444 timeout: 3000000, 445 446 data: { 447 'action' : 'wpstream_check_event_status', 448 'channel_id' : channel_id, 449 'notes' : notes, 450 'nonce' : nonce 451 }, 452 success: function (data) { 453 454 var obj = data; 455 var channel_status = obj.status; 456 457 if(channel_status=='active' || channel_status=='stopped' ){ 458 successCallback(obj); 459 }else if(channel_status=='error'){ 460 successCallback(obj); 461 }else{ 462 successCallback(false); 463 } 464 465 }, error: function (jqXHR,textStatus,errorThrown) { 466 errorCallback(); 467 } 468 }); 469} 470 471 472/* 473* 474* Make actions visible on event if ready 475* 476* 477*/ 478function wpstream_event_ready_make_actions_visible(parent){ 479 480 var actionButton = parent.find('.start_event'); 481 parent.addClass('wpstream_show_started'); 482 actionButton.unbind('click'); 483 wpstream_bind_stop_event(actionButton); 484 485 actionButton.addClass('wpstream_stop_event').removeClass('start_event').html(wpstream_start_streaming_vars.stop_streaming+'<div class="wpstream_tooltip">'+wpstream_start_streaming_vars.turned_off_tooltip+'</div>'); 486 parent.find('.wpstream-button-icon').removeClass('wpstream_inactive_icon'); 487 parent.find('.wpstream_show_settings').addClass('wpstream_inactive_icon'); 488 const channelStatus = parent.find('.wpstream_channel_status'); 489 channelStatus.each(function( index, element ) { 490 if ( !jQuery(element).hasClass('not_ready_to_stream') && jQuery(element).css('display', 'none') ) { 491 console.log('put back channel on'); 492 jQuery(element).text(wpstream_start_streaming_vars.channel_on); 493 jQuery(element).fadeIn(200); 494 } 495 if ( jQuery(element).hasClass('not_ready_to_stream') ) { 496 console.log('hide the element'); 497 jQuery(element).hide(); 498 } 499 }); 500 const stopEventButton = parent.find('.wpstream_stop_event'); 501 if ( stopEventButton.css('display', 'none') ) { 502 stopEventButton.fadeIn(200); 503 } 504 var webcasterUrl = parent.find('.start_webcaster').attr('data-webcaster-url'); 505 if (webcasterUrl === ""){ 506 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 507 parent.find('.start_webcaster .wpstream_tooltip_disabled').text('Browser Broadcasting is not Available for your plan.'); 508 } 509 510 //for onboarding 511 var check_against='3'; 512 var check_against_camera_icon='5'; 513 if(jQuery('#woocommerce-product-data').length>0){ 514 check_against='5' 515 check_against_camera_icon='7'; 516 } 517 518 519 var bubble_Step =jQuery('#wpstream_onboard_bubble').attr('data-bubble-step'); 520 521 if(bubble_Step===check_against){ 522 jQuery('#wpstream_onboard_bubble_tile').text('Channel is now ON'); 523 jQuery('#wpstream_onboard_bubble_content').text('You are ready to GO LIVE. Click Next to see how.'); 524 } 525 if(bubble_Step===check_against_camera_icon){ 526 jQuery('#wpstream_onboard_bubble_tile').html('Go LIVE'); 527 jQuery('#wpstream_onboard_bubble_content').html('To Go Live now, click the <div class=\"wpstream_sample_icon_settings wpstream_sample_icon_camera\"></div> icon. The broadcast app will open in a new window.'); 528 529 if( jQuery('.event_list_unit .wpstream_button').hasClass('wpstream_stop_event') ){ 530 jQuery('.wpstream_sample_icon_camera').css('cursor','pointer'); 531 532 jQuery('.wpstream_sample_icon_camera').on('click',function(){ 533 jQuery('.start_webcaster').trigger('click'); 534 jQuery(this).unbind('click'); 535 536 }) 537 } 538 539 } 540} 541 542function wpstream_event_error_make_actions_visible(parent){ 543 var actionButton = parent.find('.start_event'); 544 const channelStatus = parent.find('.wpstream_channel_status'); 545 actionButton.unbind('click'); 546 actionButton.hide(); 547 channelStatus.hide(); 548 549 parent.find('.server_notification').html('<div class="wpstream_channel_status not_ready_to_stream"><span class="dashicons dashicons-dismiss"></span>'+wpstream_start_streaming_vars.failed_fetching+'</div>'); 550} 551 552 553/* 554* 555* Make actions visible on event if stopped 556* 557* 558*/ 559function wpstream_event_stopped_make_actions(parent){ 560 561 var actionButton = parent.find('.wpstream_turning_on'); 562 wpstream_bind_start_event(actionButton); 563 parent.removeClass('wpstream_show_started'); 564 actionButton.removeClass('wpstream_turning_on'); 565 actionButton.addClass('start_event'); 566 actionButton.html( wpstream_start_streaming_vars.start_streaming+'<div class="wpstream_tooltip">'+wpstream_start_streaming_vars.turned_on_tooltip+'</div>'); 567 568 parent.find('.wpstream-button-icon').removeClass('wpstream_inactive_icon'); 569 parent.find('.wpstream_stream_pro').addClass('wpstream_inactive_icon'); 570 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 571 parent.find('.wpstream_statistics_channel').addClass('wpstream_inactive_icon'); 572 573 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_off); 574} 575 576 577 578function wpstream_show_error_on_start(text,parent){ 579 //You don't have enough data to start a new event! 580 jQuery('.wpstream_error_content').text(text); 581 jQuery('.wpstream_modal_background').show(); 582 jQuery('.wpstream_error_modal_notification').show(); 583 wpstream_event_stopped_make_actions(parent); 584 585} 586 587function wpstream_show_error_on_stop(text,parent){ 588 //You don't have enough data to start a new event! 589 jQuery('.wpstream_error_content').text(text); 590 jQuery('.wpstream_modal_background').show(); 591 jQuery('.wpstream_error_modal_notification').show(); 592 wpstream_event_ready_make_actions_visible(parent); 593 594} 595 596 597/* 598* 599* Streaming modal trigger functions 600* 601* 602*/ 603function wpestate_start_modal_actions(){ 604 605 jQuery('.wpstream_close_modal').on('click',function(event){ 606 jQuery(this).parent().hide(); 607 jQuery('.wpstream_modal_background').hide(); 608 }); 609 610 document.addEventListener('keydown', function(event) { 611 if(event.keyCode == 27){ 612 jQuery('.wpstream_modal_form').hide(); 613 jQuery('.wpstream_modal_background').hide(); 614 } 615 }); 616 617 618 jQuery('.wpstream-trigger-modal').on('click',function(event){ 619 620 if( jQuery(this).hasClass('wpstream_inactive_icon') ) { 621 return; 622 }; 623 624 jQuery('.wpstream_modal_background').show(); 625 var modal_class=jQuery(this).attr('data-modal'); 626 wpstream_safe_track_onboarding( 'open_modal', 'wpstream_' + post_type, 'button', modal_class ); 627 var parent =jQuery(this).closest('.event_list_unit'); 628 jQuery('.wpstream_modal_background').show(); 629 parent.find("."+modal_class).css('display','flex').css('flex-direction','column'); 630 }) 631 632 jQuery('.wpstream_external_broadcast_options').change(function(event){ 633 var new_option = jQuery(this).val(); 634 var parent = jQuery(this).parent(); 635 636 parent.find('.external_software_streaming').hide(); 637 parent.find('.'+new_option).show(); 638 }); 639 640 641} 642 643 644 645/* 646* 647* Tooltips for buttons 648* 649* 650*/ 651 652function wpstream_tooltip(){ 653 654 jQuery( ".wpstream_tooltip_wrapper" ).hover( 655 function() { 656 657 if(jQuery( this ).hasClass('wpstream_inactive_icon')){ 658 jQuery( this ).find('.wpstream_tooltip_disabled').css('opacity',1); 659 }else{ 660 jQuery( this ).find('.wpstream_tooltip').css('opacity',1); 661 } 662 663 664 }, function() { 665 jQuery( this ).find('.wpstream_tooltip').css('opacity',0); 666 jQuery( this ).find('.wpstream_tooltip_disabled').css('opacity',0); 667 } 668); 669} 670 671/* 672* 673* Modal errors 674* 675* 676*/ 677 678 679function wpestate_start_modal_error_actions(){ 680 jQuery('.wpstream_error_ok').on('click',function(event){ 681 jQuery(this).parent().hide(); 682 jQuery('.wpstream_modal_background').hide(); 683 jQuery(this).parent().find('.wpstream_error_content').text(''); 684 }); 685} 686 687 688 689 690/* 691* 692* Copy to Clipboard 693* 694* 695*/ 696 697function wpstream_copy_to_clipboard(){ 698 699 jQuery('.copy_live_uri').on('click',function(){ 700 var value_uri = jQuery(this).parent().find('.wpstream_live_uri_text').text(); 701 var temp = jQuery("<input>"); 702 jQuery("body").append(temp); 703 jQuery(temp).val(value_uri).select(); 704 document.execCommand("copy"); 705 jQuery(temp).remove(); 706 707 // Show "Copied" tooltip 708 var tooltip = jQuery('<div class="wpstream_copy_tooltip">Copied</div>'); 709 tooltip.css({ 710 position: 'absolute', 711 background: '#333', 712 color: '#fff', 713 padding: '5px 10px', 714 borderRadius: '3px', 715 fontSize: '12px', 716 zIndex: 9999, 717 pointerEvents: 'none' 718 }); 719 720 var offset = jQuery(this).offset(); 721 tooltip.css({ 722 top: offset.top - 35, 723 left: offset.left + (jQuery(this).outerWidth() / 2) - (tooltip.outerWidth() / 2) 724 }); 725 726 jQuery('body').append(tooltip); 727 tooltip.fadeIn(200); 728 729 setTimeout(function() { 730 tooltip.fadeOut(200, function() { 731 tooltip.remove(); 732 }); 733 }, 1500); 734 }); 735 736 jQuery('.copy_live_key').on('click',function(){ 737 var value_uri = jQuery(this).parent().find('.wpstream_live_key_text').text(); 738 var temp = jQuery("<input>"); 739 jQuery("body").append(temp); 740 jQuery(temp).val(value_uri).select(); 741 document.execCommand("copy"); 742 jQuery(temp).remove(); 743 }); 744} 745 746/* 747* 748* Webcaster button action 749* 750* 751*/ 752 753function wpstream_webcaster_actions(){ 754 jQuery('.start_webcaster').on('click',function(event){ 755 if(jQuery(this).hasClass('wpstream_inactive_icon')){ 756 return; 757 } 758 wpstream_safe_track_onboarding( 'open_webcaster', 'wpstream_' + post_type ); 759 var $this = jQuery(this); 760 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 761 var channelId = jQuery(this).closest('.event_list_unit').data('show-id'); 762 var whipUrl = '';
763 var pendingPopup = window.open('', '_blank', 'location=yes,scrollbars=yes,status=yes'); 764 var nonce = jQuery('#wpstream_start_event_nonce').val(); 765 766 jQuery.ajax({ 767 type: 'POST', 768 dataType: 'json', 769 url: ajaxurl, 770 timeout: 3000000, 771 data: { 772 'action': 'wpstream_check_whipurl', 773 'channel_id': channelId, 774 'nonce': nonce, 775 }, 776 success: function (data) { 777 if( data.success == true ){ 778 whipUrl = data.whip_url; 779 780 if ( whipUrl !== '' ) { 781 // Open the new broadcaster in a new window 782 var broadcasterUrl = wpstream_start_streaming_vars.broadcaster_url + channelId; 783 // window.open(broadcasterUrl, 'wpstream_broadcaster_' + channelId, 'fullscreen=yes'); 784 if (pendingPopup) { 785 pendingPopup.location.href = broadcasterUrl; 786 } else { 787 if (pendingPopup) { 788 pendingPopup.close(); 789 } 790 } 791 } 792 } else { 793 var caster_url = $this.attr('data-webcaster-url'); 794 $this.parent().find('.external_software_streaming').slideUp() 795 window.open(caster_url, '_blank', 'location=yes,scrollbars=yes,status=yes'); 796 } 797 }, 798 error: function() { 799 // fallback to the old broadcaster if the AJAX request fails 800 var caster_url = $this.attr('data-webcaster-url'); 801 $this.parent().find('.external_software_streaming').slideUp() 802 window.open(caster_url, '_blank', 'location=yes,scrollbars=yes,status=yes'); 803 } 804 }); 805 }) 806} 807 808 809 810/* 811* 812* per event - low latency vs bitrate vs encrypt 813* 814*/ 815 816 817function wpstream_adjust_settings(input_element){ 818 819 820 821 var attr_value = input_element.attr('data-attr-ajaxname'); 822 console.log(attr_value); 823 824 825 826 if( attr_value === 'adaptive_bitrate' || attr_value==='low_latency'){ 827 console.log('perform '); 828 829 var timer = setTimeout(function() { 830 831 if( jQuery('.wpstream-setting-adaptive_bitrate .wpstream_event_option_item').is(':checked') || 832 jQuery('.wpstream-setting-low_latency .wpstream_event_option_item').is(':checked') ){ 833 jQuery('.wpstream-setting-encrypt .wpstream_event_option_item') .removeAttr('checked'); 834 } 835 }, 300); 836 837 } 838 839 if( attr_value === 'encrypt'){ 840 console.log('perform2 '); 841 842 var timer = setTimeout(function() { 843 844 if( jQuery('.wpstream-setting-encrypt .wpstream_event_option_item').is(':checked') ){ 845 846 jQuery('.wpstream-setting-low_latency .wpstream_event_option_item') .removeAttr('checked'); 847 jQuery('.wpstream-setting-adaptive_bitrate .wpstream_event_option_item') .removeAttr('checked'); 848 849 } 850 851 852 }, 300); 853 854 } 855 856} 857 858/* 859* 860* Save options actions 861* 862* 863*/ 864 865function wpstream_save_options_actions(){ 866 jQuery('.wpestate_settings_modal .wpstream_event_option_item').on('click',function(){ 867 868 wpstream_adjust_settings(jQuery(this)); 869 870 var holder = jQuery(this).parents('.wpstream_event_streaming_local'); 871 var show_id = jQuery(this).parents('.event_list_unit').find('.start_event').attr('data-show-id'); 872 var optionarray ={}; 873 var nonce = jQuery('#wpstream_start_event_nonce').val(); 874 var timer = setTimeout(function() { 875 holder.find('.wpstream_event_option_item').each(function(){ 876 optionarray[jQuery(this).attr('data-attr-ajaxname')]=jQuery(this).prop("checked") ? 1 : 0 ; 877 }); 878 879 880 var myJSON = JSON.stringify(optionarray); 881 jQuery.ajax({ 882 type: 'POST', 883 url: ajaxurl, 884 timeout: 300000, 885 data: { 886 'action' : 'wpstream_update_local_event_settings', 887 'show_id' : show_id, 888 'option' : optionarray, 889 'security' : nonce 890 891 }, 892 success: function (data) { 893 }, 894 error: function (jqXHR,textStatus,errorThrown) { 895 } 896 897 }); 898 }, 300); 899 900 }); 901 902} 903 904function wpstream_save_use_global_event_options() { 905 jQuery('.wpestate_settings_modal #local_event_options_enabled').on('click',function(){ 906 var nonce = jQuery('#wpstream_start_event_nonce').val(); 907 var show_id = jQuery(this).parents('.event_list_unit').find('.start_event').attr('data-show-id'); 908 909 var use_global_settings = jQuery(this).prop("checked") ? 1 : 0 ; 910 jQuery.ajax({ 911 type: 'POST', 912 url: ajaxurl, 913 timeout: 300000, 914 data: { 915 'action' : 'wpstream_update_use_global_event_options', 916 'show_id' : show_id, 917 'use_global' : jQuery(this).prop("checked") ? 0 : 1 , 918 'security' : nonce 919 }, 920 success: function (data) { 921 jQuery('.wpestate_settings_modal .wpstream_event_option_item').each(function(){ 922 jQuery(this).prop("disabled", !jQuery('#local_event_options_enabled').prop("checked")); 923 }); 924 }, 925 error: function (jqXHR,textStatus,errorThrown) { 926 console.log('error'); 927 } 928 }); 929 }); 930} 931 932/* 933* 934* Function to check live connections 935* 936* 937*/ 938 939function wpstream_check_live_connections(){ 940 // was .pending_streaming.pending_trigger 941 if( jQuery('.event_list_unit.pending_trigger').length>0 ){ 942 jQuery('.event_list_unit.pending_trigger').each(function(){ 943 var acesta = jQuery(this); 944 var show_id = jQuery(this).attr('data-show-id'); 945 var server_id = jQuery(this).attr('data-server-id'); 946 947 wpstream_check_live_connections_from_database(acesta,show_id,server_id); 948 var counter_long = ''; 949 counter_long = setInterval( function (){ wpstream_check_live_connections_from_database(acesta,show_id,server_id)},60000); 950 counters[show_id]=counter_long; 951 952 }); 953 } 954 955} 956 957 958 959 960/* 961* 962* check live connection 963* 964* 965*/ 966 967 968function wpstream_check_live_connections_from_database( acesta,channel_id,server_id){ 969 var server_status = wpstream_check_event_status_in_js(channel_id,'wpstream_check_live_connections_from_database', 970 function(server_status){ 971 972 if(server_status.status==='active' ){ 973 974 acesta.find('.wpstream_ready_to_stream .start_webcaster').attr('data-webcaster-url',server_status.webcaster_url); 975 acesta.find('.wpstream_live_uri_text').text(server_status.obs_uri); 976 acesta.find('.wpstream_live_key_text').text(server_status.obs_stream); 977 978 wpstream_event_ready_make_actions_visible( acesta ); 979 980 var larix_rtmp= server_status.obs_uri+server_status.obs_stream; 981 acesta.find('.wpstream_larix_rtmp').text(larix_rtmp); 982 983 acesta.find('.larrix_test').text(larix_rtmp); 984 985 var larix_qr ='larix://set/v1?conn[][url]='+encodeURIComponent(larix_rtmp); 986 acesta.find('.wpstream_start_with_larix_mobile').attr('href',larix_qr); 987 988 989 var print_qrcode= "https://qrcode.tec-it.com/API/QRCode?size=small&dpi=110&data="+encodeURIComponent(larix_qr); 990 991 acesta.find('.print_qrcode').attr('src',print_qrcode); 992 acesta.find('.wpstream_live_data').attr('href',server_status.live_data_url); 993 clearInterval( counters["stop"+channel_id]); 994 995 }else if(server_status.status==='error' ){ 996 997 clearInterval( counters["stop"+channel_id]); 998 var curent_content = acesta.find('.wpstream_channel_status '); 999 1000 curent_content.html('<div class="wpstream_channel_status not_ready_to_stream"><span class="dashicons dashicons-dismiss"></span>'+wpstream_start_streaming_vars.failed_event_creation+'</div>'); 1001 } 1002 }, 1003 function(){ 1004 wpstream_event_error_make_actions_visible(acesta); 1005 } 1006 ); 1007 1008} 1009 1010 1011 1012/* 1013* 1014* Check event/channel status 1015* 1016* 1017*/ 1018 1019 1020function wpstream_check_server_status(url_param,callback) { 1021 1022 var url = url_param ; 1023 var status=''; 1024 jQuery.ajax({ 1025 url: url, 1026 type: "get", 1027 cache: false, 1028 dataType: 'jsonp', // it is for supporting crossdomain 1029 crossDomain : true, 1030 asynchronous : false, 1031 timeout : 1500, // set a timeout in milliseconds 1032 callback:'', 1033 complete : function(xhr) { 1034 1035 if(xhr.status == "200" || xhr.status == "400") { 1036 callback(true); 1037 } 1038 else { 1039 callback(false); 1040 } 1041 } 1042 }); 1043} 1044 1045function wpstream_convert_mb_to_gb(megabits) { 1046 let gigabit = megabits / 1000; 1047 gigabit = parseFloat( gigabit.toFixed( 1 ) ); 1048 1049 if ( gigabit < 0 ) { 1050 return 0 1051 } 1052 1053 return gigabit; 1054}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.