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('stream_attempted', 'wpstream_' + post_type); 170 wpstream_safe_track_onboarding('start_stream_clicked', 'wpstream_' + post_type); 171 var basicStreaming = jQuery('#wpstream_basic_streaming').val() === 'true'; 172 if (basicStreaming){ 173 console.log("doing basic streaming"); 174 if(!confirm(wpstream_start_streaming_vars.basic_streaming_warning)){ 175 return false; 176 } 177 } 178 179 event.preventDefault(); 180 button.unbind('click'); 181 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 182 var acesta = jQuery(this); 183 var notification_area = jQuery(this).parent().find('.event_list_unit_notification'); 184 var curent_content = jQuery(this).parent().find('.server_notification'); 185 var is_record = false; 186 var is_encrypt = false; 187 var show_id = parseFloat( jQuery(this).attr('data-show-id') ); 188 var nonce = jQuery('#wpstream_start_event_nonce').val(); 189 var parent = jQuery(this).parent(); 190 191 if( jQuery(this).parent().find('.record_event').is(":checked") ){ 192 is_record = true; 193 } 194 195 if( jQuery(this).parent().find('.encrypt_event').is(":checked") ){ 196 is_encrypt = true; 197 } 198 parent.find('.wpstream_show_settings').addClass('wpstream_inactive_icon'); 199 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>'); 200 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_turning_on); 201 202 jQuery.ajax({ 203 type: 'POST', 204 url: ajaxurl, 205 dataType: 'json', 206 timeout: 300000, 207 208 data: { 209 'action' : 'wpstream_give_me_live_uri', 210 'security' : nonce, 211 'show_id' : show_id, 212 'is_record' : is_record, 213 'is_encrypt' : is_encrypt, 214 'basic_streaming' : basicStreaming, 215 'start_onboarding' : start_onboarding, 216 217 218 }, 219 success: function (data) { 220 221 222 223 if(data.conected===true){ 224 225 if(data.event_data==='err1'){ 226 wpstream_safe_track_onboarding('stream_start_failed', 'wpstream_' + post_type, 'system', 'err1'); 227 228 wpstream_show_error_on_start(wpstream_start_streaming_vars.error1,parent) 229 230 }else if(data.event_data ==='failed event creation'){ 231 wpstream_safe_track_onboarding('stream_start_failed', 'wpstream_' + post_type, 'system', 'failed_event_creation'); 232 233 wpstream_show_error_on_start(wpstream_start_streaming_vars.failed_event_creation,parent) 234 235 }else{ 236 curent_content.empty(); 237 var counter = setInterval( function (){ 238 wpstream_check_live_connections_on_start(parent,show_id,data.event_data,data) 239 },10000); 240 counters['stop'+show_id]=counter; 241 242 } 243 244 245 }else{ 246 wpstream_safe_track_onboarding('stream_start_failed', 'wpstream_' + post_type, 'system', 'api_not_connected'); 247 wpstream_show_error_on_start(data.error,parent) 248 } 249 250 }, 251 error: function (jqXHR,textStatus,errorThrown) { 252 wpstream_safe_track_onboarding('stream_start_failed', 'wpstream_' + post_type, 'system', 'ajax_error'); 253 } 254 }); 255 256 }); 257 258} 259 260 261/* 262*
263* Bind Stop channel action 264* 265*/ 266 267function wpstream_bind_stop_event(button){ 268 button.click(function(event){ 269 wpstream_safe_track_onboarding( 'stop_stream_clicked', 'wpstream_' + post_type ); 270 271 272 if(!confirm(wpstream_start_streaming_vars.turn_off_confirm)){ 273 return false; 274 } 275 button.unbind('click'); 276 277 278 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 279 var show_id = parseFloat( jQuery(this).attr('data-show-id') ); 280 var nonce = jQuery('#wpstream_start_event_nonce').val(); 281 var parent = jQuery(this).parent(); 282 var thisButton = jQuery(this); 283 284 thisButton.removeClass('wpstream_stop_event'); 285 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>'); 286 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_turning_off); 287 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 288 parent.find('.wpstream_stream_pro').addClass('wpstream_inactive_icon'); 289 parent.find('.wpstream_live_data').addClass('wpstream_inactive_icon'); 290 291 292 293 jQuery.ajax({ 294 type: 'POST', 295 url: ajaxurl, 296 dataType: 'json', 297 timeout: 300000, 298 299 data: { 300 'action' : 'wpstream_turn_of_channel', 301 'security' : nonce, 302 'show_id' : show_id 303 304 305 }, 306 success: function (data) { 307 308 if(data.conected===true){ 309 310 thisButton.unbind('click'); 311 312 var counter = setInterval( function (){ 313 wpstream_check_live_connections_on_start(parent,show_id,'',data)},10000); 314 counters["stop"+show_id]=counter; 315 316 }else{ 317 318 wpstream_show_error_on_stop(data.error,parent) 319 } 320 321 }, 322 error: function (jqXHR,textStatus,errorThrown) { 323 324 } 325 }); 326 327 328 329 }); 330 331} 332 333 334/* 335* 336* Enable copy to clipboard 337* 338*/ 339 340function wpstream_enable_cliboard(parent){ 341 342 jQuery(parent).find('.copy_live_uri').click(function(){ 343 344 var value_uri = jQuery(parent).find('.wpstream_live_uri_text').text(); 345 var temp = jQuery("<input>"); 346 jQuery("body").append(temp); 347 jQuery(temp).val(value_uri).select(); 348 document.execCommand("copy"); 349 jQuery(temp).remove(); 350 351 }); 352 353 jQuery(parent).find('.copy_live_key').click(function(){ 354 var value_uri = jQuery(parent).find('.wpstream_live_key_text').text(); 355 var temp = jQuery("<input>"); 356 jQuery("body").append(temp); 357 jQuery(temp).val(value_uri).select(); 358 document.execCommand("copy"); 359 jQuery(temp).remove(); 360 361 }); 362} 363 364 365/* 366 * 367 * Check live events/channels on starts 368 * 369 * 370 * 371*/ 372 373 374function wpstream_check_live_connections_on_start( parent,show_id,server_id,data){ 375 376 // server_url is dns change 377 378 wpstream_check_event_status_in_js(show_id,'wpstream_check_live_connections_on_start', 379 function(server_status){ 380 381 if(server_status.status==='active' ){ 382 parent.find('.start_webcaster').attr('data-webcaster-url',server_status.webcaster_url); 383 parent.find('.wpstream_live_uri_text').text(server_status.obs_uri); 384 parent.find('.wpstream_live_key_text').text(server_status.obs_stream); 385 386 wpstream_event_ready_make_actions_visible(parent); 387 388 var larix_rtmp= server_status.obs_uri+server_status.obs_stream; 389 parent.find('.wpstream_larix_rtmp').text(larix_rtmp); 390 391 var larix_qr ='larix://set/v1?conn[][url]='+encodeURIComponent(larix_rtmp); 392 parent.find('.wpstream_start_with_larix_mobile').attr('href',larix_qr); 393 394 parent.find('.wpstream_larix_rtmp').text(larix_rtmp); 395 parent.find('.larrix_test').text(larix_rtmp); 396 397 398 var print_qrcode= "https://qrcode.tec-it.com/API/QRCode?size=small&dpi=110&data="+encodeURIComponent(larix_qr); 399 400 401 parent.find('.print_qrcode').attr('src',print_qrcode); 402 403 parent.parent().find('.wpstream_live_data').attr('href',server_status.live_data_url); 404 clearInterval( counters["stop"+show_id]); 405 406 if (counters[show_id]) { 407 clearInterval(counters[show_id]); 408 } 409 var server_id = jQuery(this).attr('data-server-id'); 410 counters[show_id] = setInterval( function (){ 411 wpstream_check_live_connections_from_database(parent,show_id,server_id); 412 },60000); 413 414 if (typeof wpstream_integration_notifications === 'function') { 415 wpstream_integration_notifications(show_id); 416 } 417 418 419 }else if(server_status.status==='stopped' ){ 420 console.log('stopped status from _on_start'); 421 clearInterval( counters["stop"+show_id]); 422 wpstream_event_stopped_make_actions(parent); 423 424 }else if(server_status.status==='error' ){ 425 wpstream_safe_track_onboarding('stream_start_failed', 'wpstream_' + post_type, 'system', 'status_error'); 426 427 clearInterval( counters["stop"+show_id]); 428 var curent_content = parent.find('.wpstream_channel_status'); 429 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>'); 430 } 431 }); 432 433} 434 435 436 437 438/* 439 * check channell id status 440 * 441 * @param {type} channel_id 442 * @param {type} callback 443 * @returns {undefined} 444 * 445 * 446*/ 447 448function wpstream_check_event_status_in_js(channel_id,notes,successCallback, errorCallback){ 449 450 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 451 var nonce = jQuery('#wpstream_start_event_nonce').val(); 452 453 jQuery.ajax({ 454 type: 'POST', 455 dataType: 'json', 456 url: ajaxurl, 457 timeout: 3000000, 458 459 data: { 460 'action' : 'wpstream_check_event_status', 461 'channel_id' : channel_id, 462 'notes' : notes, 463 'nonce' : nonce 464 }, 465 success: function (data) { 466 467 var obj = data; 468 var channel_status = obj.status; 469 470 if(channel_status=='active' || channel_status=='stopped' ){ 471 successCallback(obj); 472 }else if(channel_status=='error'){ 473 successCallback(obj); 474 }else{ 475 successCallback(false); 476 } 477 478 }, error: function (jqXHR,textStatus,errorThrown) { 479 errorCallback(); 480 } 481 }); 482} 483 484 485/* 486* 487* Make actions visible on event if ready 488* 489* 490*/ 491function wpstream_event_ready_make_actions_visible(parent){ 492 493 var actionButton = parent.find('.start_event'); 494 parent.addClass('wpstream_show_started'); 495 actionButton.unbind('click'); 496 wpstream_bind_stop_event(actionButton); 497 498 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>'); 499 parent.find('.wpstream-button-icon').removeClass('wpstream_inactive_icon'); 500 parent.find('.wpstream_show_settings').addClass('wpstream_inactive_icon'); 501 const channelStatus = parent.find('.wpstream_channel_status'); 502 channelStatus.each(function( index, element ) { 503 if ( !jQuery(element).hasClass('not_ready_to_stream') && jQuery(element).css('display', 'none') ) { 504 console.log('put back channel on'); 505 jQuery(element).text(wpstream_start_streaming_vars.channel_on); 506 jQuery(element).fadeIn(200); 507 } 508 if ( jQuery(element).hasClass('not_ready_to_stream') ) { 509 console.log('hide the element'); 510 jQuery(element).hide(); 511 } 512 }); 513 const stopEventButton = parent.find('.wpstream_stop_event'); 514 if ( stopEventButton.css('display', 'none') ) { 515 stopEventButton.fadeIn(200); 516 } 517 var webcasterUrl = parent.find('.start_webcaster').attr('data-webcaster-url'); 518 if (webcasterUrl === ""){ 519 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 520 parent.find('.start_webcaster .wpstream_tooltip_disabled').text('Browser Broadcasting is not Available for your plan.'); 521 } 522 523 //for onboarding 524 var check_against='3'; 525 var check_against_camera_icon='5'; 526 if(jQuery('#woocommerce-product-data').length>0){ 527 check_against='5' 528 check_against_camera_icon='7'; 529 } 530 531 532 var bubble_Step =jQuery('#wpstream_onboard_bubble').attr('data-bubble-step'); 533 534 if(bubble_Step===check_against){ 535 jQuery('#wpstream_onboard_bubble_tile').text('Channel is now ON'); 536 jQuery('#wpstream_onboard_bubble_content').text('You are ready to GO LIVE. Click Next to see how.'); 537 } 538 if(bubble_Step===check_against_camera_icon){ 539 jQuery('#wpstream_onboard_bubble_tile').html('Go LIVE'); 540 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.'); 541 542 if( jQuery('.event_list_unit .wpstream_button').hasClass('wpstream_stop_event') ){ 543 jQuery('.wpstream_sample_icon_camera').css('cursor','pointer'); 544 545 jQuery('.wpstream_sample_icon_camera').on('click',function(){ 546 jQuery('.start_webcaster').trigger('click'); 547 jQuery(this).unbind('click'); 548 549 }) 550 } 551 552 } 553 554 // console.log('adding pending trigger'); 555 // parent.addClass('pending_trigger'); 556 // console.log('adding check for status'); 557 // // wpstream_check_live_connections(); 558 // console.log('parent ' , parent); 559} 560 561function wpstream_event_error_make_actions_visible(parent){ 562 var actionButton = parent.find('.start_event'); 563 const channelStatus = parent.find('.wpstream_channel_status'); 564 actionButton.unbind('click'); 565 actionButton.hide(); 566 channelStatus.hide(); 567 568 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>'); 569} 570 571 572/* 573* 574* Make actions visible on event if stopped 575* 576* 577*/ 578function wpstream_event_stopped_make_actions(parent){ 579 580 var actionButton = parent.find('.wpstream_turning_on'); 581 wpstream_bind_start_event(actionButton); 582 parent.removeClass('wpstream_show_started'); 583 actionButton.removeClass('wpstream_turning_on'); 584 actionButton.addClass('start_event'); 585 actionButton.html( wpstream_start_streaming_vars.start_streaming+'<div class="wpstream_tooltip">'+wpstream_start_streaming_vars.turned_on_tooltip+'</div>'); 586 587 parent.find('.wpstream-button-icon').removeClass('wpstream_inactive_icon'); 588 parent.find('.wpstream_stream_pro').addClass('wpstream_inactive_icon'); 589 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 590 parent.find('.wpstream_statistics_channel').addClass('wpstream_inactive_icon'); 591 592 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_off); 593} 594 595/* 596* 597* Make actions visible on event if stopped 598* 599* 600*/ 601function wpstream_event_stopped_after_status_check(parent){ 602 603 var actionButton = parent.find('.wpstream_turning_on'); 604 if (actionButton.length === 0) { 605 actionButton = parent.find('.wpstream_stop_event'); 606 } 607 actionButton.unbind('click'); 608 wpstream_bind_start_event(actionButton); 609 parent.removeClass('wpstream_show_started'); 610 actionButton.removeClass('wpstream_turning_on wpstream_stop_event'); 611 actionButton.addClass('start_event'); 612 actionButton.html( wpstream_start_streaming_vars.start_streaming+'<div class="wpstream_tooltip">'+wpstream_start_streaming_vars.turned_on_tooltip+'</div>'); 613 614 parent.find('.wpstream-button-icon').removeClass('wpstream_inactive_icon'); 615 parent.find('.wpstream_stream_pro').addClass('wpstream_inactive_icon'); 616 parent.find('.start_webcaster').addClass('wpstream_inactive_icon'); 617 parent.find('.wpstream_statistics_channel').addClass('wpstream_inactive_icon'); 618 619 parent.find('.wpstream_channel_status').text(wpstream_start_streaming_vars.channel_off); 620} 621 622 623 624function wpstream_show_error_on_start(text,parent){ 625 //You don't have enough data to start a new event! 626 jQuery('.wpstream_error_content').text(text); 627 jQuery('.wpstream_modal_background').show(); 628 jQuery('.wpstream_error_modal_notification').show(); 629 wpstream_event_stopped_make_actions(parent); 630 631} 632 633function wpstream_show_error_on_stop(text,parent){ 634 //You don't have enough data to start a new event! 635 jQuery('.wpstream_error_content').text(text); 636 jQuery('.wpstream_modal_background').show(); 637 jQuery('.wpstream_error_modal_notification').show(); 638 wpstream_event_ready_make_actions_visible(parent); 639 640} 641 642 643/* 644* 645* Streaming modal trigger functions 646* 647* 648*/ 649function wpestate_start_modal_actions(){ 650 651 jQuery('.wpstream_close_modal').on('click',function(event){ 652 jQuery(this).parent().hide(); 653 jQuery('.wpstream_modal_background').hide(); 654 }); 655 656 document.addEventListener('keydown', function(event) { 657 if(event.keyCode == 27){ 658 jQuery('.wpstream_modal_form').hide(); 659 jQuery('.wpstream_modal_background').hide(); 660 } 661 }); 662 663 664 jQuery('.wpstream-trigger-modal').on('click',function(event){ 665 666 if( jQuery(this).hasClass('wpstream_inactive_icon') ) { 667 return; 668 }; 669 670 jQuery('.wpstream_modal_background').show(); 671 var modal_class=jQuery(this).attr('data-modal'); 672 wpstream_safe_track_onboarding( 'open_modal', 'wpstream_' + post_type, 'button', modal_class ); 673 var parent =jQuery(this).closest('.event_list_unit'); 674 jQuery('.wpstream_modal_background').show(); 675 parent.find("."+modal_class).css('display','flex').css('flex-direction','column'); 676 }) 677 678 jQuery('.wpstream_external_broadcast_options').change(function(event){ 679 var new_option = jQuery(this).val(); 680 var parent = jQuery(this).parent(); 681 682 parent.find('.external_software_streaming').hide(); 683 parent.find('.'+new_option).show(); 684 }); 685 686 687} 688 689 690 691/* 692* 693* Tooltips for buttons 694* 695* 696*/ 697 698function wpstream_tooltip(){ 699 700 jQuery( ".wpstream_tooltip_wrapper" ).hover( 701 function() { 702 703 if(jQuery( this ).hasClass('wpstream_inactive_icon')){ 704 jQuery( this ).find('.wpstream_tooltip_disabled').css('opacity',1); 705 }else{ 706 jQuery( this ).find('.wpstream_tooltip').css('opacity',1); 707 } 708 709 710 }, function() { 711 jQuery( this ).find('.wpstream_tooltip').css('opacity',0); 712 jQuery( this ).find('.wpstream_tooltip_disabled').css('opacity',0); 713 } 714); 715} 716 717/* 718* 719* Modal errors 720* 721* 722*/ 723 724 725function wpestate_start_modal_error_actions(){ 726 jQuery('.wpstream_error_ok').on('click',function(event){ 727 jQuery(this).parent().hide(); 728 jQuery('.wpstream_modal_background').hide(); 729 jQuery(this).parent().find('.wpstream_error_content').text(''); 730 }); 731} 732 733 734 735 736/* 737* 738* Copy to Clipboard 739* 740* 741*/ 742 743function wpstream_copy_to_clipboard(){ 744 745 jQuery('.copy_live_uri').on('click',function(){ 746 var value_uri = jQuery(this).parent().find('.wpstream_live_uri_text').text(); 747 var temp = jQuery("<input>"); 748 jQuery("body").append(temp); 749 jQuery(temp).val(value_uri).select(); 750 document.execCommand("copy"); 751 jQuery(temp).remove(); 752 753 // Show "Copied" tooltip 754 var tooltip = jQuery('<div class="wpstream_copy_tooltip">Copied</div>'); 755 tooltip.css({ 756 position: 'absolute', 757 background: '#333', 758 color: '#fff', 759 padding: '5px 10px', 760 borderRadius: '3px', 761 fontSize: '12px', 762 zIndex: 9999, 763 p
763ointerEvents: 'none' 764 }); 765 766 var offset = jQuery(this).offset(); 767 tooltip.css({ 768 top: offset.top - 35, 769 left: offset.left + (jQuery(this).outerWidth() / 2) - (tooltip.outerWidth() / 2) 770 }); 771 772 jQuery('body').append(tooltip); 773 tooltip.fadeIn(200); 774 775 setTimeout(function() { 776 tooltip.fadeOut(200, function() { 777 tooltip.remove(); 778 }); 779 }, 1500); 780 }); 781 782 jQuery('.copy_live_key').on('click',function(){ 783 var value_uri = jQuery(this).parent().find('.wpstream_live_key_text').text(); 784 var temp = jQuery("<input>"); 785 jQuery("body").append(temp); 786 jQuery(temp).val(value_uri).select(); 787 document.execCommand("copy"); 788 jQuery(temp).remove(); 789 }); 790} 791 792/* 793* 794* Webcaster button action 795* 796* 797*/ 798 799function wpstream_webcaster_actions(){ 800 jQuery('.start_webcaster').on('click',function(event){ 801 if(jQuery(this).hasClass('wpstream_inactive_icon')){ 802 return; 803 } 804 wpstream_safe_track_onboarding( 'open_webcaster', 'wpstream_' + post_type ); 805 var $this = jQuery(this); 806 var ajaxurl = wpstream_start_streaming_vars.admin_url + 'admin-ajax.php'; 807 var channelId = jQuery(this).closest('.event_list_unit').data('show-id'); 808 var whipUrl = ''; 809 var pendingPopup = window.open('', '_blank', 'location=yes,scrollbars=yes,status=yes'); 810 var nonce = jQuery('#wpstream_start_event_nonce').val(); 811 812 jQuery.ajax({ 813 type: 'POST', 814 dataType: 'json', 815 url: ajaxurl, 816 timeout: 3000000, 817 data: { 818 'action': 'wpstream_check_whipurl', 819 'channel_id': channelId, 820 'nonce': nonce, 821 }, 822 success: function (data) { 823 if( data.success == true ){ 824 whipUrl = data.whip_url; 825 826 if ( whipUrl !== '' ) { 827 // Open the new broadcaster in a new window 828 var broadcasterUrl = wpstream_start_streaming_vars.broadcaster_url + channelId; 829 if ( wpstream_start_streaming_vars.is_onboarding == 'yes' ) { 830 broadcasterUrl += '/?onboarding=1'; 831 if (pendingPopup) { 832 var popupSessionId = (new URLSearchParams(window.location.search)).get('session_id') || ''; 833 var popupPayload = { 834 wpstream_onboarding_popup_payload: { 835 session_id: popupSessionId, 836 } 837 }; 838 839 try { 840 pendingPopup.name = JSON.stringify(popupPayload); 841 } catch (e) { 842 pendingPopup.name = ''; 843 } 844 } 845 } 846 // window.open(broadcasterUrl, 'wpstream_broadcaster_' + channelId, 'fullscreen=yes'); 847 if (pendingPopup) { 848 pendingPopup.location.href = broadcasterUrl; 849 } else { 850 if (pendingPopup) { 851 pendingPopup.close(); 852 } 853 } 854 } 855 } else { 856 var caster_url = $this.attr('data-webcaster-url'); 857 $this.parent().find('.external_software_streaming').slideUp() 858 window.open(caster_url, '_blank', 'location=yes,scrollbars=yes,status=yes'); 859 } 860 }, 861 error: function() { 862 // fallback to the old broadcaster if the AJAX request fails 863 var caster_url = $this.attr('data-webcaster-url'); 864 $this.parent().find('.external_software_streaming').slideUp() 865 window.open(caster_url, '_blank', 'location=yes,scrollbars=yes,status=yes'); 866 } 867 }); 868 }) 869} 870 871 872 873/* 874* 875* per event - low latency vs bitrate vs encrypt 876* 877*/ 878 879 880function wpstream_adjust_settings(input_element){ 881 882 883 884 var attr_value = input_element.attr('data-attr-ajaxname'); 885 console.log(attr_value); 886 887 888 889 if( attr_value === 'adaptive_bitrate' || attr_value==='low_latency'){ 890 console.log('perform '); 891 892 var timer = setTimeout(function() { 893
894 if( jQuery('.wpstream-setting-adaptive_bitrate .wpstream_event_option_item').is(':checked') || 895 jQuery('.wpstream-setting-low_latency .wpstream_event_option_item').is(':checked') ){ 896 jQuery('.wpstream-setting-encrypt .wpstream_event_option_item') .removeAttr('checked'); 897 } 898 }, 300); 899 900 } 901 902 if( attr_value === 'encrypt'){ 903 console.log('perform2 '); 904 905 var timer = setTimeout(function() { 906 907 if( jQuery('.wpstream-setting-encrypt .wpstream_event_option_item').is(':checked') ){ 908 909 jQuery('.wpstream-setting-low_latency .wpstream_event_option_item') .removeAttr('checked'); 910 jQuery('.wpstream-setting-adaptive_bitrate .wpstream_event_option_item') .removeAttr('checked'); 911 912 } 913 914 915 }, 300); 916 917 } 918 919} 920 921/* 922* 923* Save options actions 924* 925* 926*/ 927 928function wpstream_save_options_actions(){ 929 jQuery('.wpestate_settings_modal .wpstream_event_option_item').on('click',function(){ 930 931 wpstream_adjust_settings(jQuery(this)); 932 933 var holder = jQuery(this).parents('.wpstream_event_streaming_local'); 934 var show_id = jQuery(this).parents('.event_list_unit').find('.start_event').attr('data-show-id'); 935 var optionarray ={}; 936 var nonce = jQuery('#wpstream_start_event_nonce').val(); 937 var timer = setTimeout(function() { 938 holder.find('.wpstream_event_option_item').each(function(){ 939 optionarray[jQuery(this).attr('data-attr-ajaxname')]=jQuery(this).prop("checked") ? 1 : 0 ; 940 }); 941 942 943 var myJSON = JSON.stringify(optionarray); 944 jQuery.ajax({ 945 type: 'POST', 946 url: ajaxurl, 947 timeout: 300000, 948 data: { 949 'action' : 'wpstream_update_local_event_settings', 950 'show_id' : show_id, 951 'option' : optionarray, 952 'security' : nonce 953 954 }, 955 success: function (data) { 956 }, 957 error: function (jqXHR,textStatus,errorThrown) { 958 } 959 960 }); 961 }, 300); 962 963 }); 964 965} 966 967function wpstream_save_use_global_event_options() { 968 jQuery('.wpestate_settings_modal #local_event_options_enabled').on('click',function(){ 969 var nonce = jQuery('#wpstream_start_event_nonce').val(); 970 var show_id = jQuery(this).parents('.event_list_unit').find('.start_event').attr('data-show-id'); 971 972 var use_global_settings = jQuery(this).prop("checked") ? 1 : 0 ; 973 jQuery.ajax({ 974 type: 'POST', 975 url: ajaxurl, 976 timeout: 300000, 977 data: { 978 'action' : 'wpstream_update_use_global_event_options', 979 'show_id' : show_id, 980 'use_global' : jQuery(this).prop("checked") ? 0 : 1 , 981 'security' : nonce 982 }, 983 success: function (data) { 984 jQuery('.wpestate_settings_modal .wpstream_event_option_item').each(function(){ 985 jQuery(this).prop("disabled", !jQuery('#local_event_options_enabled').prop("checked")); 986 }); 987 }, 988 error: function (jqXHR,textStatus,errorThrown) { 989 console.log('error'); 990 } 991 }); 992 }); 993} 994 995/* 996* 997* Function to check live connections 998* 999* 1000*/ 1001 1002function wpstream_check_live_connections(){ 1003 // was .pending_streaming.pending_trigger 1004 if( jQuery('.event_list_unit.pending_trigger').length>0 ){ 1005 jQuery('.event_list_unit.pending_trigger').each(function(){ 1006 var acesta = jQuery(this); 1007 var show_id = jQuery(this).attr('data-show-id'); 1008 var server_id = jQuery(this).attr('data-server-id'); 1009 1010 wpstream_check_live_connections_from_database(acesta,show_id,server_id); 1011 var counter_long = ''; 1012 counter_long = setInterval( function (){ 1013 wpstream_check_live_connections_from_database(acesta,show_id,server_id) 1014 },60000); 1015 counters[show_id]=counter_long; 1016 1017 }); 1018 } 1019 1020} 1021 1022 1023 1024 1025/* 1026* 1027* check live connection 1028* 1029* 1030*/ 1031 1032 1033function wpstream_check_live_connections_from_database( acesta,channel_id,server_id){ 1034 var server_status = wpstream_check_event_status_in_js(channel_id,'wpstream_check_live_connections_from_database', 1035 function(server_status){ 1036 1037 if(server_status.status==='active' ){ 1038 1039 acesta.find('.wpstream_ready_to_stream .start_webcaster').attr('data-webcaster-url',server_status.webcaster_url); 1040 acesta.find('.wpstream_live_uri_text').text(server_status.obs_uri); 1041 acesta.find('.wpstream_live_key_text').text(server_status.obs_stream); 1042 1043 wpstream_event_ready_make_actions_visible( acesta ); 1044 1045 var larix_rtmp= server_status.obs_uri+server_status.obs_stream; 1046 acesta.find('.wpstream_larix_rtmp').text(larix_rtmp); 1047 1048 acesta.find('.larrix_test').text(larix_rtmp); 1049 1050 var larix_qr ='larix://set/v1?conn[][url]='+encodeURIComponent(larix_rtmp); 1051 acesta.find('.wpstream_start_with_larix_mobile').attr('href',larix_qr); 1052 1053 1054 var print_qrcode= "https://qrcode.tec-it.com/API/QRCode?size=small&dpi=110&data="+encodeURIComponent(larix_qr); 1055 1056 acesta.find('.print_qrcode').attr('src',print_qrcode); 1057 acesta.find('.wpstream_live_data').attr('href',server_status.live_data_url); 1058 clearInterval( counters["stop"+channel_id]); 1059 1060 }else if(server_status.status==='stopped' ){ 1061 clearInterval( counters["stop"+channel_id]); 1062 wpstream_event_stopped_after_status_check(acesta); 1063 }else if(server_status.status==='error' ){ 1064 1065 clearInterval( counters["stop"+channel_id]); 1066 var curent_content = acesta.find('.wpstream_channel_status '); 1067 1068 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>'); 1069 } 1070 }, 1071 function(){ 1072 wpstream_event_error_make_actions_visible(acesta); 1073 } 1074 ); 1075 1076} 1077 1078 1079 1080/* 1081* 1082* Check event/channel status 1083* 1084* 1085*/ 1086 1087 1088function wpstream_check_server_status(url_param,callback) { 1089 1090 var url = url_param ; 1091 var status=''; 1092 jQuery.ajax({ 1093 url: url, 1094 type: "get", 1095 cache: false, 1096 dataType: 'jsonp', // it is for supporting crossdomain 1097 crossDomain : true, 1098 asynchronous : false, 1099 timeout : 1500, // set a timeout in milliseconds 1100 callback:'', 1101 complete : function(xhr) { 1102 1103 if(xhr.status == "200" || xhr.status == "400") { 1104 callback(true); 1105 } 1106 else { 1107 callback(false); 1108 } 1109 } 1110 }); 1111} 1112 1113function wpstream_convert_mb_to_gb(megabits) { 1114 let gigabit = megabits / 1000; 1115 gigabit = parseFloat( gigabit.toFixed( 1 ) ); 1116 1117 if ( gigabit < 0 ) { 1118 return 0 1119 } 1120 1121 return gigabit; 1122}
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.