PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.8.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.8.2
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 / public / js / start_streaming.js

start_streaming.js in WpStream – Live Streaming, Video on Demand, Pay Per View 4.8.2, at public/js/start_streaming.js

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