if(window.__VARS__.room_status==="public"){let socket=new WebSocket(window.__VARS__.wschat_host);socket.onopen=function(e){socket.send(JSON.stringify(['{"method":"connect","data":{"user":"'+window.__VARS__.chat_username+'","password":"'+window.__VARS__.chat_password+'","room":"'+window.__VARS__.broadcaster_username+'","room_password":"'+window.__VARS__.room_pass+'"}}']));socket.send(JSON.stringify(['{"method":"joinRoom","data":{"room":"'+window.__VARS__.broadcaster_username+'","exploringHashTag":""}}']))};socket.onmessage=function(event){if(event.data.charAt(0)!=="a")return;$("#bChat .sendInput").css("visibility","visible");$("#bChat .sendInput, #bChat .sendButton").prop("disabled",false);var jsonData=JSON.parse(event.data.substring(1));var args=JSON.parse(jsonData[0]);if(args.method==="onRoomMsg"){var code=JSON.parse(args.args[1]);var color=code.c?"color:"+code.c+";":"";var font_family=code.f!=="default"?"font-family:"+code.f+";":"";var style=color+font_family;var msg='
\n'+'
\n'+'
\n'+" "+code.user+"\n"+"
\n"+'
'+ch_emotion(code.m)+"
\n"+"
\n"+"
";$(document).find(".historyContainer .history .messages").append(msg);messagesScroll()}else if(args.method==="onNotify"){var code=JSON.parse(args.args[0]);if(code.type==="appnotice"){var color=code.color?"color:"+code.color+";":"";var background=code.background?"background:"+code.background+";":"";var foreground=code.foreground?"color:"+code.foreground+";":"";var weight=code.weight?"font-weight:"+code.weight+";":"";var style=color+background+weight+foreground;var message=ch_emotion(code.msg[0]);var msg='
Уведомление: '+message+"
"}else if(code.type==="tip_alert"){var tipped="подарил";var tokens=ru_plural(code.amount,["токен","токена","токенов"]);var msg='
'+'
'+'
'+code.from_username+" "+tipped+" "+code.amount+' '+tokens+"!
"+"
"+"
"}$(document).find(".historyContainer .history .messages").append(msg);messagesScroll()}else if(args.method==="onTitleChange"){if(args.args[0]){$(document).find(".bChatTopic").html(args.args[0])}}};socket.onclose=function(event){};socket.onerror=function(error){console.log("[error] ${error.message}")};function messagesScroll(){$(document).find(".history").stop().animate({scrollTop:$(document).find(".messages .msg_wrp:last-child").position().top},"slow")}window.guest_chat=0;$(document).on("click touch",".chatBtn",function(){var sendInput=$(document).find("#bChat .sendInput");if(sendInput.val()){var messageText=sendInput.val();$.post("/message",{type:"sendMessage",code:messageText,gChat:window.guest_chat},function(data){$(document).find(".historyContainer .history .messages").append(data);messagesScroll()});if(window.guest_chat==0){window.guest_chat=1}}sendInput.val("")});$("#bChat .sendInput").keyup(function(e){if(e.keyCode==13){$(".chatBtn").trigger("click")}});$("#smileButton").click(function(){if(window.__VARS__.loggedIn){var emoWrap=$("#emotions-wrap");emoWrap.toggle();if(emoWrap.is(":visible")){getEmotions()}else{emoWrap.html("")}}});$(document).on("click touch","#emotions-wrap img",function(){var emoWrap=$("#emotions-wrap");var sendInput=$(document).find("#bChat .sendInput");var emo=$(this);var emoText=emo.attr("data-smile");sendInput.val(sendInput.val()+" ["+emoText+"]");emoWrap.hide();emoWrap.html("")});$("#smileButton").on("show.bs.popover",function(){getEmotions()});function getEmotions(){$.ajax({url:"/ajax/emotions",dataType:"html",success:function(data){$("#emotions-wrap").html(data)}})}$(document).ready(function(){$(window).resize()});$(window).resize(function(){if($(window).width()<=991){var chatHeight=$(window).height()-$(document).find(".cam-column").height()-$(document).find(".column-header-topic").height()-150;$(document).find(".chat-tab .chat_history").height(chatHeight);$(document).find(".inputContainer").insertBefore(".historyContainer")}else{$(document).find(".chat-tab .chat_history").height("62vh");$(document).find(".inputContainer").insertAfter(".historyContainer")}});var fullscreenLabel="";if(!window.__VARS__.loggedIn){fullscreenLabel='Полноэкранный режим возможен только для зарегистрированных пользователей\n'}var controls='
\n'+'
\n'+" LIVE\n"+"
\n"+' \n"+'
\n'+' \n'+"
\n"+' \n"+"
";localStorage.setItem("plyr",'{"volume":1,"muted":true}');const source=window.__VARS__.hls_source;const video=document.querySelector("video"); if(window.__VARS__.loggedIn){ const player=new Plyr(video,{controls:controls,clickToPlay:false,fullscreen:{enabled:true}}); $(document).on("click",".fullscreen-btn",function(){player.fullscreen.toggle()})} else { const player=new Plyr(video,{controls:controls,clickToPlay:false,fullscreen:{enabled:false}})} if(!Hls.isSupported()){video.src=source}else{const hls=new Hls;hls.loadSource(source);hls.attachMedia(video);window.hls=hls}hls.on(Hls.Events.ERROR,function(event,data){if(data.fatal){switch(data.type){case Hls.ErrorTypes.NETWORK_ERROR:hls.startLoad();if(window.__VARS__.m==="m"){player.poster="/images/offline/gay/ru.jpg"}else if(window.__VARS__.m==="t"){player.poster="/images/offline/trans/ru.jpg"}else{player.poster="/images/offline/female/ru.jpg"}$(document).find(".plyr__controls").css("display","none");break;case Hls.ErrorTypes.MEDIA_ERROR:hls.recoverMediaError();break;default:hls.destroy();break}}})}else{$(document).ready(function(){$(window).resize()});$(window).resize(function(){var g;switch(window.__VARS__.m){case"m":g="gay";break;case"t":g="trans";break;default:g="female"}if($(window).width()<=991){$(document).find(".chat-tab .chat_history").height("30vh");$(document).find(".videoContainer").height("25vh");$(document).find(".videoContainer").css("background-image","url(/images/offline/"+g+"/ru.jpg)")}else{$(document).find(".chat-tab .chat_history").height("60vh");var chatHeight=$(document).find("#bChat").height()-35;$(document).find(".videoContainer").height(chatHeight);$(document).find(".videoContainer").css("background-image","url(/images/offline/"+g+"/ru.jpg)")}$(document).find(".model-cam-controls").hide()})}function replacer(match,p1,offset,string){let a=p1.split("|");return''}function ch_emotion(str){return str.replace(/%%%\[emoticon(.+)\]%%%/,replacer)}function ru_plural(number,titles){var cases=[2,0,1,1,1,2];return titles[number%100>4&&number%100<20?2:cases[Math.min(number%10,5)]]}