Files
Testing/mongolian1/mgVideoChat/mgVideoChat-1.14.1-min.js
sean 0e8a8b3028
Some checks failed
deploy-testing / deploy (push) Has been cancelled
Initial testing snapshot
2026-11-17 16:15:01 -05:00

1 line
46 KiB
JavaScript

(function(e,d,a,f){var c={firefox:false},b={};c.init=function(g){c.config=g.rtc;if(navigator.mozGetUserMedia){c.firefox=true}b=g};c._socket=null;c._events={};c.on=function(g,h){c._events[g]=c._events[g]||[];c._events[g].push(h)};c.fire=function(h,k){c.debug("fired ["+h+"]");var m=c._events[h];var j=Array.prototype.slice.call(arguments,1);if(!m){return}for(var l=0,g=m.length;l<g;l++){m[l].apply(null,j)}};c.connections={};c.connectionsLoaded=false;c.id=null;c.compatible=true;c.debug=function(g){if(b.debug){console.log(g)}};c.checkCompatibility=function(i,h,g){if(!g){g="call"}c.compatible=true;if(!d.WebSocket){i.websocket=true;c.compatible=false}if(!d.RTCPeerConnection&&!d.PeerConnection){if(g=="call"){i.peerconnection=true;c.compatible=false}else{h.peerconnection=true}}if(!navigator.getUserMedia){if(g=="call"){i.usermedia=true;c.compatible=false}else{h.usermedia=true}}return c.compatible};c.loadDevices=function(h){var g={audio:[],video:[]};if(!navigator||!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices){h(g);return}navigator.mediaDevices.enumerateDevices().then(function(i){i.forEach(function(j){if(j.kind==="videoinput"){g.video.push({value:j.deviceId,text:j.label})}else{if(j.kind==="audioinput"){g.audio.push({value:j.deviceId,text:j.label})}}});h(g)})};c.connect=function(g){c._socket=new WebSocket(g);c._socket.onopen=function(){c.fire("connected")};c._socket.onmessage=function(i){var h=JSON.parse(i.data);c.debug("RECEIVED MESSAGE "+h.type);c.debug(h);c.fire(h.type,h.data)};c._socket.onerror=function(h){c.debug("onerror");c.debug(h);c.fire("socket_error",h)};c._socket.onclose=function(h){c.fire("socket_closed",{})}};c.on("connections",function(g){c.connections=g;c.connectionsLoaded=true});c.on("connectionId",function(g){c.id=g.connectionId;c.fire("logged",g.data)});c.on("connection_add",function(g){c.connections[g.connectionId]=g.data});c.on("connection_remove",function(g){delete c.connections[g.connectionId]});c.on("call_invite",function(g){c.setStatus(g.connectionId,"call_invited")});c.on("call_accept",function(g){if(c.refuseIdleState(g.connectionId)){return false}c.setStatus(g.connectionId,"call_accepted");c.sdpOffer(g.connectionId)});c.setStatus=function(h,g){c.debug("status ["+g+"] for connectionId: "+h);c.connections[h].status=g;c.fire("status",h,g)};c.refuseIdleState=function(h){var g=h&&c.connections[h].status=="idle";if(g){c.debug("refusing idle state of connection id: "+h)}return g};c.send=function(g){c.debug("SENDING MSG "+g.type);c.debug(g);c._socket.send(JSON.stringify(g))};c.mediaReady=function(){c.send({type:"media_ready",data:{}})};c.rouletteNext=function(){c.send({type:"roulette_next",data:{}})};c.rouletteAccept=function(g){c.send({type:"roulette_accept",data:{connectionId:g}})};c.chatMessage=function(g,h){c.send({type:"chat_message",data:{connectionId:g,message:h}})};c.login=function(g){c.send({type:"login",data:g})};c.invite=function(h,g){c.debug("creating local media stream");c.setStatus(h,"call_inviting");c.createStream(h,g,function(i){c.debug("inviting call for id: "+h);c.send({type:"call_invite",data:{connectionId:h}})})};c.accept=function(h,g){c.debug("creating local media stream");c.createStream(h,g,function(i){c.debug("accepting call from id: "+h);c.send({type:"call_accept",data:{connectionId:h}});c.setStatus(h,"call_accepting")})};c.drop=function(h,g,i){c.debug("droping call");c.send({type:"call_drop",data:{connectionId:h}});if(c.connections[h]){c.stop(h,g,i)}};c.busy=function(g){c.debug("sending busy signal");c.send({type:"call_busy",data:{connectionId:g}})};c.stop=function(k,g,l){if(!c.connections[k]){return false}if(!g&&c.connections[k].pc){c.connections[k].pc.close();c.connections[k].pc=null}if(!l&&c.connections[k].stream){var h=c.connections[k].stream.getTracks();for(var j in h){h[j].stop()}}c.setStatus(k,"idle")};c.mergeConstraints=function(i,h){var g=i;for(var j in h.mandatory){g.mandatory[j]=h.mandatory[j]}g.optional.concat(h.optional);return g};c.onCreateSessionDescriptionError=function(g){c.debug("Failed to create session description: "+g.toString())};c.extractSdp=function(h,i){var g=h.match(i);return(g&&g.length==2)?g[1]:null};c.setDefaultCodec=function(h,l){var k=h.split(" ");var m=new Array();var g=0;for(var j=0;j<k.length;j++){if(g===3){m[g++]=l}if(k[j]!==l){m[g++]=k[j]}}return m.join(" ")};c.removeCN=function(h,m){var k=h[m].split(" ");for(var g=h.length-1;g>=0;g--){var l=c.extractSdp(h[g],/a=rtpmap:(\d+) CN\/\d+/i);if(l){var j=k.indexOf(l);if(j!==-1){k.splice(j,1)}h.splice(g,1)}}h[m]=k.join(" ");return h};c.preferAudioCodec=function(h){if(!c.config.audio_receive_codec){return h}var n=c.config.audio_receive_codec;var k=n.split("/");if(k.length!=2){return h}var g=k[0];var l=k[1];var p=h.split("\r\n");for(var j=0;j<p.length;j++){if(p[j].search("m=audio")!==-1){var q=j;break}}if(q===null){return h}for(var j=0;j<p.length;j++){if(p[j].search(g+"/"+l)!==-1){var m=new RegExp(":(\\d+) "+g+"\\/"+l,"i");var o=c.extractSdp(p[j],m);if(o){p[q]=c.setDefaultCodec(p[q],o)}break}}p=c.removeCN(p,q);h=p.join("\r\n");return h};c.remoteSDReceive=function(g,h){g.setRemoteDescription(new RTCSessionDescription(h),function(){c.debug("Set remote session description success.");var i=g.getRemoteStreams();if(i.length>0&&i[0].getVideoTracks().length>0){c.debug("Waiting for remote video tracks")}},function(i){c.debug("Set remote session description error "+i.toString())})};c.localSDSend=function(g,j,i,h){i.sdp=c.preferAudioCodec(i.sdp);c.debug("Setting local sessionDescription and sending msg "+h);c.debug(i);g.setLocalDescription(i,function(){c.debug("Set local session description success.")},function(k){c.debug("Set local session description error "+k.toString())});c.send({type:h,data:{connectionId:j,sdp:i}})};c.sdpOffer=function(h){var g=c.createPeerConnection(h);var i=c.config.offerConstraints;c.debug("Sending offer to peer, with constraints: \n '"+JSON.stringify(i)+"'.");g.createOffer(function(j){c.localSDSend(g,h,j,"sdp_offer")},c.onCreateSessionDescriptionError,i);c.setStatus(h,"sdp_offering")};c.sdpAnswer=function(h){c.debug("Answering call connectionId: "+h);var g=c.createPeerConnection(h);c.remoteSDReceive(g,c.connections[h].offerSdp);c.debug("Sending answer to peer, with constraints: \n '"+JSON.stringify({})+"'.");g.createAnswer(function(i){c.localSDSend(g,h,i,"sdp_answer")},c.onCreateSessionDescriptionError);c.setStatus(h,"sdp_answering")};c.createStream=function(h,g,k,l){k=k||function(m){};l=l||function(m){c.debug("Could not connect stream with error:");c.debug(m)};try{c.fire("media_request_start");var j=e.extend({},c.config.mediaConstraints,g);navigator.getUserMedia(j,function(n){var m=function(o){c.fire("media_request_end");if(c.refuseIdleState(h)){n.stop();return false}if(h){c.connections[h].stream=n}c.fire("stream_added",n,h);k(n)};if(j.audioAppend){c.addAudioTrack(n,m)}else{m(true)}},function(m){c.fire("media_request_end");l(m);c.fire("stream_error",m)})}catch(i){c.fire("media_request_end");c.fire("stream_error",i)}};c.addAudioTrack=function(g,h){navigator.getUserMedia({audio:true,video:false},function(i){g.addTrack(i.getAudioTracks()[0]);h(true)},function(i){h(false)})};c.createPeerConnection=function(h){c.debug("createPeerConnection for id: "+h);try{c.connections[h].pc=new d.RTCPeerConnection(c.config.pcConfig);c.connections[h].pc.onicecandidate=function(j){c.debug("pc.onicecandidate, event:");c.debug(j);if(j.candidate){c.send({type:"ice_candidate",data:{candidate:j.candidate.candidate,connectionId:h,label:j.candidate.sdpMLineIndex}})}else{c.debug("End of ICE candidates")}};c.debug("Created RTCPeerConnnection with:\n config: '"+JSON.stringify(c.config.pcConfig)+"';\n constraints: '"+JSON.stringify(c.config.pcConstraints)+"'.")}catch(i){console.error(i);c.debug("Failed to create RTCPeerConnection, exception: "+i.message);c.fire("pc_error",i);alert("Cannot create PeerConnection object; Is the 'PeerConnection' flag enabled in about:flags?");return null}var g=c.connections[h].pc;g.onconnecting=function(){c.debug("Session connecting.")};g.onopen=function(){c.debug("Session opened.");c.fire("pc_opened",h)};g.onaddstream=function(j){c.debug("Remote stream added.");c.fire("rstream_added",j.stream,h);c.setStatus(h,"call")};g.onremovestream=function(){c.debug("Remote stream removed.")};if(c.connections[h].stream){g.addStream(c.connections[h].stream)}g.onsignalingstatechange=function(){c.debug("PC Signaling state changed to: "+g.signalingState)};g.oniceconnectionstatechange=function(){c.debug("ICE connection state changed to: "+g.iceConnectionState)};return g};c.fileOffer=function(h,g){c.debug("offering file to connection "+h);c.debug(g);c.send({type:"file_offer",data:{connectionId:h,fileDesc:g}})};c.fileAccept=function(h,g){c.debug("accepting file from id: "+h);c.debug(g);c.send({type:"file_accept",data:{connectionId:h,fileDesc:g}})};c.fileCancel=function(h,g){c.debug("canceling file sending to "+h);c.debug(g);c.send({type:"file_cancel",data:{connectionId:h,fileDesc:g}})};c.fileSdpOffer=function(j,i,h){var g=c.fileGetPeerConnection(j,h,true);var k=c.config.offerConstraints;g.createOffer(function(l){g.setLocalDescription(l);c.send({type:"file_sdp_offer",data:{connectionId:j,sdp:l,fileDesc:i}})},function(l){c.debug("Failed to create session description offer: "+l.toString())},k)};c.fileSdpAnswer=function(j,i,h){c.debug("Answering call connectionId: "+j);var g=c.fileGetPeerConnection(j,h);g.setRemoteDescription(new RTCSessionDescription(c.connections[j].fileOfferSdp));g.createAnswer(function(k){g.setLocalDescription(k);c.send({type:"file_sdp_answer",data:{connectionId:j,sdp:k,fileDesc:i}})},function(k){c.debug("Failed to create session description answer: "+k.toString())})};c.fileGetPeerConnection=function(l,i,k){try{c.debug("fileGetPeerConnection for id: "+l+" does not exist, creating it");var n={optional:[]};c.connections[l].dpc=new d.RTCPeerConnection(c.config.pcConfig,n);c.connections[l].dpc.onicecandidate=function(o){if(o.candidate){c.send({type:"file_ice_candidate",data:{candidate:o.candidate.candidate,connectionId:l,label:o.candidate.sdpMLineIndex}})}}}catch(m){c.debug("Failed to create RTCPeerConnection, exception: "+m.message);c.fire("dpc_error",m);alert("Cannot create PeerConnection object; Is the 'PeerConnection' flag enabled in about:flags?");return null}var h=c.connections[l].dpc;h.onopen=function(){c.debug("File peerconnection opened for conn id: "+l)};var j=function(o){if(i.channelOnMessage){o.onmessage=i.channelOnMessage}if(i.channelOnOpen){o.onopen=i.channelOnOpen}if(i.channelOnClose){o.onclose=i.channelOnClose}if(i.channelOnError){o.onerror=i.channelOnError}};var g=function(){if(!k){return false}c.debug("creating send channel");c.connections[l].sendChannel=c.connections[l].dpc.createDataChannel("sendDataChannel"+l);c.connections[l].sendChannel.binaryType="arraybuffer";j(c.connections[l].sendChannel)};h.ondatachannel=function(o){if(!k){c.debug("creating receive channel");c.connections[l].receiveChannel=o.channel;c.connections[l].receiveChannel.binaryType="arraybuffer";j(c.connections[l].receiveChannel)}};g();return h};c.fileReceiveProgress=function(h,g,i){c.send({type:"file_receive_progress",data:{connectionId:h,fileId:g,packets:i}})};c.on("file_ice_candidate",function(h){var g=c.connections[h.connectionId].dpc;g.addIceCandidate(new RTCIceCandidate({sdpMLineIndex:h.label,candidate:h.candidate}))});e.fn.mgRtc=function(g){c.init(g);return c}})(jQuery,window,document);(function(c,b,a,d){c.fn.mgFileHelper=function(e){var f={getDesc:function(g){if(!g.id){g.id=(Math.random()*new Date().getTime()).toString(36).toUpperCase().replace(/\./g,"-")}return{name:g.name,size:g.size,type:g.type,id:g.id,connectionId:g.connectionId,firefox:e.firefox,transfered:0}},send:function(k,l,i){var m=16384,h;var g=new b.FileReader();var j=function(p,s){if(p){s=0;h=p.target.result}var o=h.byteLength<=(s+m);var r=h.slice(s,m+s);e.debug("Sending file packet of bytes:"+r.byteLength+", offset was: "+s+", of total file size: "+h.byteLength);l.send(r);var n={transfered:r.byteLength,fileId:k.id};if(i.onFileProgress){i.onFileProgress(n,k)}if(o&&i.onFileSent){i.onFileSent(n)}var q=0;if(i.calcTimeout){q=i.calcTimeout(n);if(q<0){return}}if(!o){setTimeout(function(){j(null,s+m)},q)}};g.onload=j;g.readAsArrayBuffer(k)},recContent:{},recNumberOfBytes:{},receive:function(j,k,i){var l=j.id;if(!f.recNumberOfBytes[l]){f.recNumberOfBytes[l]=0}f.recNumberOfBytes[l]+=k.byteLength;if(i.onFileProgress){i.onFileProgress({transfered:k.byteLength,fileId:l},l)}e.debug("received file packet, file name: ["+j.name+"], bytes: ["+k.byteLength+"]");if(!f.recContent[l]){f.recContent[l]=[]}f.recContent[l].push(k);if(f.recNumberOfBytes[l]===j.size){var h=new b.Blob(f.recContent[l],{type:j.type});var g=(b.URL||b.webkitURL).createObjectURL(h);if(i.autoSaveToDisk){f.saveToDisk(g,j.name)}if(i.onFileReceived){i.onFileReceived(j.name,{blob:h,dataURL:g,url:g,fileId:l})}delete f.recContent[l]}},saveToDisk:function(g,j){var i=a.createElement("a");i.href=g;i.target="_blank";i.download=j||g;var h=new MouseEvent("click",{view:b,bubbles:true,cancelable:true});i.dispatchEvent(h);setTimeout(function(){(b.URL||b.webkitURL).revokeObjectURL(i.href)},500)},dataUrlToBlob:function(k){var m=atob(k.substr(k.indexOf(",")+1));var l=[];for(var g=0;g<m.length;g++){l.push(m.charCodeAt(g))}var h;try{h=k.substr(k.indexOf(":")+1).split(";")[0]}catch(j){h="text/plain"}return new Blob([new Uint8Array(l)],{type:h})}};return f}})(jQuery,window,document);(function(c,b,a,d){c.fn.mgNotifications=function(e){var f={grant:function(g){if(this.checkActive()){return true}b.Notification.requestPermission(function(h){if(g){g(h)}})},checkActive:function(){if(!("Notification" in b)){return false}if(b.Notification.permission==="granted"){return true}if(b.Notification.permission==="denied"){return false}},notify:function(j,g,h){if(!h&&!a.hidden){return false}console.log("notify",j,h,a.hidden);if(!this.checkActive()){return false}var i=new Notification(j,g);i.onclick=function(k){k.preventDefault();b.focus();this.close()}}};return f}})(jQuery,window,document);(function(c,b,a,d){c.fn.mgDesktopShare=function(f){var e={extensionAvailable:null,screenCallback:null,isExtensionAvailable:function(h){var g=this;if(this.extensionAvailable!==null){return h(this.extensionAvailable)}b.postMessage({message:"mgIsLoaded"},"*");setTimeout(function(){if(g.extensionAvailable==null){g.extensionAvailable=false}h(g.extensionAvailable)},200)},getSourceId:function(h){var g=this;this.isExtensionAvailable(function(i){if(!i){h(false,"no-extension")}g.screenCallback=h;b.postMessage({message:"mgGetSourceId"},"*")})}};b.addEventListener("message",function(g){if(g.origin!=b.location.origin){return}switch(g.data.message){case"mgIsLoadedResult":e.extensionAvailable=true;break;case"mgGetSourceIdResult":if(g.data.success){e.screenCallback(g.data.sourceId)}else{if(e.screenCallback){e.screenCallback(false,"no-permission")}}break;default:return}});return e}})(jQuery,window,document);(function(c,b,a,d){c.fn.mgVideoChatUtils=function(i,f){i.prototype.fixPath=function(){if(this.config.dir!="{rel}"){return}var j=this;c("script").each(function(){var n=c(this).attr("src");var m="mgVideoChat-";if(n&&n.indexOf(m,this.length-m.length)!==-1){j.config.dir=n.replace(/\\/g,"/").replace(/\/[^\/]*\/?$/,"");var l=/mgVideoChat\-(\d*\.\d*\.\d*)\.js/gi;var k=l.exec(n);if(k&&k[1]){j.version=k[1]}else{l=/mgVideoChat\-(\d*\.\d*\.\d*)\-min\.js/gi;k=l.exec(n);if(k&&k[1]){j.version=k[1]}else{j.version=1}}}else{m="mgVideoChat";if(n&&n.indexOf(m,this.length-m.length)!==-1){j.config.dir=n.replace(/\\/g,"/").replace(/\/[^\/]*\/?$/,"");j.version=1}}})};i.prototype.debug=function(j){if(this.config.debug){console.log(j)}};i.prototype.getErrorText=function(k){var j=[];if(k.code){j.push(k.code)}if(k.name){j.push(k.name)}if(k.message){j.push(k.message)}if(j.length==0){j.push(k)}if(j[0]=="PermissionDeniedError"||j[0]=="PERMISSION_DENIED"){if(f.firefox){j.push(this._("Please enable requested media devices"))}else{j.push(this._("Please enable requested media devices by clicking on the right hand icon in the address bar."))}}return j.join(".\n")};i.prototype.getReadableFileSizeString=function(l){var k=-1;var j=[" kB"," MB"," GB"," TB","PB","EB","ZB","YB"];do{l=l/1024;k++}while(l>1024);return Math.max(l,0.1).toFixed(1)+j[k]};i.prototype.parseChatMessageText=function(m){function l(p,o){var n=(o||typeof o==="undefined")?"<br />":"<br>";return(p+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1"+n+"$2")}function j(o){var n=/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;return o.replace(n,"<a target=\"_blank\" href='$1'>$1</a>")}function k(r){var o,q,p,n;q=/(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;o=r.replace(q,'<a href="$1" target="_blank">$1</a>');p=/(^|[^\/])(www\.[\S]+(\b|$))/gim;o=o.replace(p,'$1<a href="http://$2" target="_blank">$2</a>');n=/(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;o=o.replace(n,'<a href="mailto:$1">$1</a>');return o}return l(k(c.fn.mgVideoChat.htmlspecialchars(m)),false)};var e={};i.prototype.tmpl=function(m,l){try{var j=!/\W/.test(m)?e[m]=e[m]||tmpl(a.getElementById(m).innerHTML):new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+m.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return l?j(l):j}catch(k){throw new Error("Error parsing template ["+m.substr(0,100)+"...]");this.debug(k)}};var h={};i.prototype.loadTplByName=function(j,k){return this.loadTpl(this.config.dir+this.config[j]+"?v="+this.version,k)};i.prototype.loadTpl=function(j,k){if(h[j]==null){c.get(j,function(l){h[j]=l;if(k){k(l)}},"html")}else{if(k){k(h[j])}}return h[j]};i.prototype.on=function(j,k){this.events[j]=this.events[j]||[];this.events[j].push(k)};i.prototype.fire=function(k,m){this.debug("mgVideoChat fired ["+k+"]");var o=this.events[k];var l=Array.prototype.slice.call(arguments,1);if(!o){return}for(var n=0,j=o.length;n<j;n++){o[n].apply(null,l)}};var g=null;i.prototype.message=function(n,l,k){if(g){b.clearTimeout(g)}var j=this;var m=j.$messagePanel.find(".alert");var o=j.$messagePanel.data("type");if(!n){j.$messagePanel.hide();return}m.removeClass("alert-"+o).addClass("alert-"+l);m.find("div.text").html(n);j.$messagePanel.data("type",l);j.$messagePanel.show();if(k){g=b.setTimeout(function(){j.$messagePanel.hide();g=null},k*1000)}};i.prototype.setCookie=function(n,k,m,j){var l=(j&&j!="localhost")?("; domain="+j):"";a.cookie=n+"="+encodeURIComponent(k)+"; max-age="+(60*60*24*m)+"; path=/"+l};i.prototype._=function(k,l,j){return c.fn.mgVideoChat._(k,l,j)}}})(jQuery,window,document);(function(c,b,a,d){c.fn.mgVideoChatRtcEvents=function(h,f,g,e){h.prototype.initRtc=function(){var i=this;f.on("connected",function(){f.login(i.loginParams);i.onConnected()});f.on("connectionId",function(l){i.connectionId=l.connectionId;i.userData=l.data.data.userData;i.roomOptions=l.room;i.usersCount=l.users_count;i.onRoomOptions();i.renderYouInfo()});f.on("logged",function(){i.fire("logged");i.onLogged()});f.on("message",function(l){i.message(l.text,l.type)});f.on("chat_message",function(m){i.fire("chat_message",m);var l=i.roomOptions.group?0:m.connectionId;i.renderChatMessage(l,m.connectionId,m.message);if(i.chatId!=m.connectionId){if(!f.connections[m.connectionId]["data"].unread){f.connections[m.connectionId]["data"].unread=0}f.connections[m.connectionId]["data"].unread++;i.renderConnection(m.connectionId);i.notifySound()}e.notify(i._("New chat message arrived"))});var j=0;f.on("call_busy",function(l){if(i.roomOptions.roulette&&j<5){i.debug("Callee is busy, try again "+j);j++;i.rouletteNext();return}i.message(i._("Callee is busy at the moment, please try later :("),"danger",3)});f.on("call_drop",function(l){f.stop(l.connectionId,false,i.roomOptions.roulette);if(i.roomOptions.roulette){f.connections={};i.renderConnections()}});f.on("media_ready",function(m){for(var l in m.data.connectionIds){f.connections[m.data.connectionIds[l]]["media_ready"]=true;if(i.localStream&&!f.connections[m.data.connectionIds[l]]["stream"]){f.connections[m.data.connectionIds[l]]["stream"]=i.localStream}}i.debug(f.connections)});f.on("connections",function(l){i.renderConnections()});var k={};f.on("roulette_next",function(l){if(!l||!l.connections){i.message(i._("No partner found at the moment. Please try later."),"warning",3);return false}i.usersCount=l.users_count;f.connections={};k=l});f.on("roulette_accept",function(l){f.connections=k.connections;k={};for(var m in f.connections){i.localVideoOpen(i.localStream,m)}i.connectAllMediaReady();i.renderConnections();i.notifySound()});f.on("roulette_invitation",function(l){i.usersCount=l.users_count;if(i.videoId){for(var m in l.connections){}i.debug("Busy for invitation from "+m);f.busy(m);f.drop(m);return false}f.connections=l.connections;for(var m in f.connections){f.connections[m].stream=i.localStream}f.rouletteAccept(m);i.localVideoOpen(i.localStream,m);i.renderConnections();i.notifySound()});f.on("connection_add",function(l){i.usersCount=l.users_count;i.renderConnection(l.connectionId)});f.on("connection_remove",function(l){i.usersCount=l.users_count;i.onConnectionClose(l.connectionId)});f.on("rstream_added",function(m,l){f.connections[l].rstream=m;if(!i.roomOptions.group){i.remoteVideoOpen(m);i.onVideoOpen(l)}else{i.remoteVideoGroupSelect()}});f.on("stream_added",function(m,l){i.localStream=m;i.localVideoOpen(m,l)});f.on("media_request_start",function(){i.$elem.find("#requestDialog").modal("show")});f.on("media_request_end",function(){i.$elem.find("#requestDialog").modal("hide")});f.on("status",function(m,l){i.fire("call_status",m,l);switch(l){case"call_inviting":i.callRing(false);break;case"call_invited":if(i.videoId){f.busy(m);f.drop(m)}else{i.inviteStart(m);e.notify(i._("New call invitation"))}break;case"call_accepting":case"call_accepted":i.$videoPanel.data("call_id",m);i.inviteStop();break;case"idle":i.callRing(true);if(i.videoId==m){i.onVideoClose()}if(i.videoInvitedId==m){i.inviteStop()}break;default:break}i.renderConnection(m)});f.on("socket_error",function(l){i.message(i._("Error connecting to media server: {error_name} {error_message}",["{error_name}","{error_message}"],[l.name,l.message]),"danger");i.onDisconnected()});f.on("socket_closed",function(l){i.message(i._("Websocket closed, please try reloading page later."),"danger");i.onDisconnected()});f.on("stream_error",function(l){i.message(i._("Error getting local media stream: {error_message}",["{error_message}"],[i.getErrorText(l)]),"danger")});f.on("pc_error",function(l){i.message(i._("Error creating peer connection: {error_name} {error_message}",["{error_name}","{error_message}"],[l.name,l.message]),"danger")});f.on("sdp_offer",function(l){if(f.refuseIdleState(l.connectionId)){return false}f.connections[l.connectionId].offerSdp=l.sdp;f.setStatus(l.connectionId,"sdp_offered");if(!i.loginParams.noPc&&!i.loginParams.noMedia){f.sdpAnswer(l.connectionId)}});f.on("sdp_answer",function(m){if(f.refuseIdleState(m.connectionId)){return false}var l=f.connections[m.connectionId].pc;f.remoteSDReceive(l,m.sdp);f.setStatus(m.connectionId,"sdp_answered")});f.on("ice_candidate",function(m){if(f.refuseIdleState(m.connectionId)){return false}if(i.loginParams.noPc||i.loginParams.noMedia){return false}var l=f.connections[m.connectionId].pc;f.debug("Adding ice candidate:");f.debug({sdpMLineIndex:m.label,candidate:m.candidate});l.addIceCandidate(new RTCIceCandidate({sdpMLineIndex:m.label,candidate:m.candidate}),function(){f.debug("Remote candidate added successfully.")},function(n){f.debug("Failed to add remote candidate: "+n.toString())})});f.on("file_offer",function(n){var m=n.connectionId;var l=f.connections[m].data.userData;i.files[n.fileDesc.id]={desc:n.fileDesc,connectionId:m,pending:true};i.renderFiles();i.$fileAcceptDialog.data("file_desc",n.fileDesc);i.$fileAcceptDialog.data("connection_id",m);i.$fileAcceptDialog.find(".username").text(l.name);if(l.image){i.$fileAcceptDialog.find(".desc").html('<img src="'+l.image+'" alt="'+l.name+'"/>')}i.$fileAcceptDialog.find(".fileName").text(n.fileDesc.name);i.$fileAcceptDialog.find(".fileSize").text(i.getReadableFileSizeString(n.fileDesc.size));i.$fileAcceptDialog.modal("show");i.notifySound();e.notify(i._("New file offer"))});f.on("file_accept",function(l){f.fileSdpOffer(l.connectionId,l.fileDesc,{channelOnOpen:function(){i.debug("channelOnOpen connId: "+l.connectionId);i.debug(l);var o=f.connections[l.connectionId].sendChannel;var m=l.fileDesc.id;var n=i.files[m].file;g.send(n,o,{onFileProgress:function(p){i.debug("onFileProgress "+m+" connId: "+l.connectionId);i.debug(p);if(i.files[p.fileId]){i.files[p.fileId].desc.transfered+=p.transfered;i.renderFileProgress(p.fileId)}},onFileSent:function(p){i.debug("onFileSent "+m+" connId: "+l.connectionId);i.debug(p);delete i.files[p.fileId];i.renderFiles()},calcTimeout:function(p){if(!i.files[p.fileId]){return -1}return(f.firefox)?5:500}})}})});f.on("file_receive_progress",function(l){if(!i.files[l.fileId]){return}i.files[l.fileId].packetsConfirmed=l.packets});f.on("file_sdp_offer",function(o){var n=o.connectionId;var l=o.fileDesc.id,m=o.fileDesc;f.connections[o.connectionId].fileOfferSdp=o.sdp;f.fileSdpAnswer(o.connectionId,o.fileDesc,{channelOnMessage:function(q){var p=q.data;i.debug("channelOnMessage connId: "+n);g.receive(m,p,{onFileProgress:function(r){i.debug("onFileProgress "+l+" connId: "+n);i.debug(r);if(i.files[r.fileId]){i.files[r.fileId].desc.transfered+=r.transfered;i.renderFileProgress(r.fileId)}},autoSaveToDisk:true,onFileReceived:function(r,s){i.debug("onFileReceived file: "+r+", file id: "+l+" connId: "+n);i.debug(s);delete i.files[s.fileId];i.renderFiles();e.notify(i._("New file received"))}})}})});f.on("file_sdp_answer",function(m){var l=f.connections[m.connectionId].dpc;l.setRemoteDescription(new RTCSessionDescription(m.sdp))});f.on("file_cancel",function(l){delete i.files[l.fileDesc.id];i.renderFiles()})}}})(jQuery,window,document);(function(c,b,a,d){c.fn.mgVideoChatUI=function(h,f,g,e){h.prototype.updateLayout=function(){var i=this.$callPanel.is(":visible")||this.$chatPanel.is(":visible");var k=this.$elem.find("#mainContent");var j=this.$elem.find("#sideMenu");if(k.data("is_visible")===i){return false}if(i){k.removeClass().addClass(k.data("chat_class"));j.removeClass().addClass(j.data("chat_class"));c("#offcanvasButton").show()}else{k.removeClass().addClass(k.data("no_chat_class"));j.removeClass().addClass(j.data("no_chat_class"))}k.data("is_visible",i)};h.prototype.renderConnections=function(){var i=this;i.debug("connections");i.debug(f.connections);this.loadTplByName("tplConnections",function(j){var k=i.tmpl(j,{rows:f.connections,roomOptions:i.roomOptions,usersCount:i.usersCount});i.$connectionsPanel.html(k);for(var l in f.connections){i.renderConnection(l)}if(!f.connections.length){i.$connectionsPanel.find("#lonely").show()}i.fire("connections",f.connections)})};h.prototype.renderConnection=function(j){var i=this;this.getConnectionElement(j,function(l){var k=i.$connectionsPanel.find("#connection_"+j);if(k.length){if(k.hasClass("active")){l.addClass("active")}k.replaceWith(l)}else{i.$connectionsPanel.find("#connections").append(l)}i.$connectionsPanel.find("#lonely").hide();i.fire("connections",f.connections)})};h.prototype.getConnectionElement=function(j,k){var i=this;if(!f.connections[j]){return false}this.loadTplByName("tplConnection",function(o){var m=f.connections[j],l=m.status?m.status:"idle";var p=m.data["loginParams"];var r=!i.loginParams.noPc&&!i.loginParams.noMedia&&!p.noPc&&!p.noMedia;var q={id:j,status:l,userData:m.data["userData"],loginParams:m.data["loginParams"],videoId:i.videoId,chatId:i.chatId,unread:(m.data.unread)?m.data.unread:0,connection:m,roomOptions:i.roomOptions,hasWebrtc:r,selfLoginParams:i.loginParams};function s(t){i.$connectionsPanel.find(".connectionItem").removeClass("active");t.addClass("active")}var n=c(i.tmpl(o,q));if(i.roomOptions.group&&m.rstream){i.videoSetStream(n.find("video"),m.rstream)}if(i.roomOptions.group){n.click(function(){s(c(this));var t=c(this).data("connection_id");if(f.connections[t].rstream){i.remoteVideoOpen(f.connections[t].rstream,t)}})}else{n.click(function(){s(c(this));i.setChat(c(this).data("connection_id"))})}n.find(".call.cmdBtn").click(function(){f.invite(c(this).data("id"),i.getMediaOptions({audio:true,video:true}))});n.find(".callDesktop.cmdBtn").click(function(){var t=this;i.getDesktopShareMedia(function(u){if(!u){return false}f.invite(c(t).data("id"),u)})});n.find(".callAudio.cmdBtn").click(function(){f.invite(c(this).data("id"),i.getMediaOptions({audio:true,video:false}))});n.find(".answer.cmdBtn").click(function(){i.debug("Clicked to answer the connectionId: "+c(this).data("id"));f.accept(c(this).data("id"),i.getMediaOptions({audio:true,video:true}))});n.find(".drop.cmdBtn").click(function(){i.debug("Clicked to drop the connectionId: "+c(this).data("id"));f.drop(c(this).data("id"),false,i.roomOptions.roulette)});n.find(".fileSend.cmdBtn").click(function(){var t=c(this).data("id");i.debug("Clicked to send file to the connectionId: "+t);c("#fileDialog").off("change");c("#fileDialog").val("");c("#fileDialog").on("change",function(u){var x=u.target.files;for(var v=0,y;y=x[v];v++){y.connectionId=t;var w=g.getDesc(y);if(i.config.fileMaxSize&&w.size>i.config.fileMaxSize){i.message(i._("This file size of over maximum defined of {max_size}",["{max_size}"],[i.getReadableFileSizeString(i.config.fileMaxSize)]),"danger");continue}f.fileOffer(t,w);i.files[y.id]={file:y,desc:w,connectionId:t};i.renderFiles()}});c("#fileDialog").trigger("click")});if(i.chatId==j){n.addClass("active")}k(n)})};h.prototype.renderFiles=function(){var i=this;i.debug("files");i.debug(i.files);this.loadTplByName("tplFile",function(l){var j="";for(var k in i.files){var m=i.tmpl(l,{file:i.files[k],fileId:k,fileSize:i.getReadableFileSizeString(i.files[k].desc.size),roomOptions:i.roomOptions});j+=m}i.$filesPanel.find("#files").html(j);i.$filesPanel.find("a.fileAccept").click(function(){var n=c(this).data("file_id");var o=i.files[n].desc;var p=i.files[n].connectionId;i.fileAccept(o,p);return false});i.$filesPanel.find("a.fileCancel").click(function(){var n=c(this).data("file_id");var o=i.files[n].desc;var p=i.files[n].connectionId;i.fileCancel(o,p);return false});if(j==""){i.$filesPanel.hide()}else{i.$filesPanel.show()}})};h.prototype.renderYouInfo=function(){var i=this;i.debug(i.userData);this.loadTplByName("tplYou",function(j){i.$youInfoPanel.find("#youInfo").html(i.tmpl(j,{userData:i.userData}));if(!i.userData){i.$youInfoPanel.hide()}else{i.$youInfoPanel.show()}})};h.prototype.renderFileProgress=function(j){var l=this.files[j].desc;if(!l){return false}var k=0;if(l.size){k=(l.transfered/l.size)*100}var i=this.$filesPanel.find("#file_"+j);i.find(".progress-bar").css("width",k+"%");i.find(".progressText").text(k+"%")};h.prototype.renderChatMessage=function(l,k,m){var j=this;var i=this.getChatDiv(l);this.loadTplByName("tplChat",function(n){var q={message:j.parseChatMessageText(m),me:false};if(k===j.connectionId){q.me=true;q.userData=j.userData}else{q.userData=f.connections[k]["data"]["userData"]}var p=j.tmpl(n,q);var o=i.find(".messages");o.append(p).scrollTop(o.get(0).scrollHeight)})};h.prototype.getChatDiv=function(l){var j=this;var i=this.$chatPanel.find("#chat_"+l);if(!i.length){var k=this.loadTplByName("tplChatInput");i=c(j.tmpl(k,{chatId:l}));i.appendTo(j.$chatPanel.find("#chats"));i.find("textarea").keypress(function(n){var m=c(this);if(n.keyCode===13&&n.shiftKey){m.val(m.val()+"\n");return false}if(n.keyCode===13){f.chatMessage(l,m.val());j.renderChatMessage(l,j.connectionId,m.val());m.val("");return false}})}return i}}})(jQuery,window,document);window.RTCPeerConnection=window.mozRTCPeerConnection||window.webkitRTCPeerConnection||window.RTCPeerConnection;window.PeerConnection=(window.webkitPeerConnection00||window.webkitPeerConnection||window.PeerConnection);navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;window.RTCSessionDescription=window.mozRTCSessionDescription||window.webkitRTCSessionDescription||window.RTCSessionDescription;window.RTCIceCandidate=window.mozRTCIceCandidate||window.webkitRTCIceCandidate||window.RTCIceCandidate;(function(g,h,i,e){var f={wsURL:"ws://localhost:8080",dir:"{rel}",tplMain:"/tpls/main.html",tplConnections:"/tpls/connections.html",tplConnection:"/tpls/connection.html",tplChat:"/tpls/chat.html",tplChatInput:"/tpls/chat_input.html",tplRoulette:"/tpls/roulette.html",tplFile:"/tpls/file.html",tplYou:"/tpls/you.html",sound:{mp3:"/sounds/ring.mp3",ogg:"/sounds/ring.ogg"},notifySound:{mp3:"/sounds/notify.mp3",ogg:"/sounds/notify.ogg"},debug:false,login:null,rtc:{pcConfig:{iceServers:[{urls:"stun:stun.l.google.com:19302"}]},pcConstraints:{optional:[{DtlsSrtpKeyAgreement:true}]},offerConstraints:{offerToReceiveAudio:1,offerToReceiveVideo:1},mediaConstraints:{audio:true,video:true},sdpConstraints:{mandatory:{OfferToReceiveAudio:true,OfferToReceiveVideo:true},optional:[{VoiceActivityDetection:false}]},audio_receive_codec:"opus/48000"},fileMaxSize:512000,chromeExtensionId:"jfepeciommhoefhfacjdpcmnclekenag",enableNotifications:true},c=null,a=null,b=null,d=null;var j=function(l,k){this.version="1";this.elem=l;this.$elem=g(l);this.$connectionsPanel=null;this.options=k;this.metadata=this.$elem.data("mgVideoChat-options");this.config=g.extend({},f,this.options);c=g.fn.mgRtc(this.config);a=g.fn.mgFileHelper(c);b=g.fn.mgDesktopShare(c);d=g.fn.mgNotifications(c);g.fn.mgVideoChatUtils(j,c);g.fn.mgVideoChatUI(j,c,a,b);g.fn.mgVideoChatRtcEvents(j,c,a,d);c.init(this.config);this.fixPath();this.init();this.$elem.data("mgVideoChat-instance",this);this.chatId=null;this.videoId=null;this.videoInvitedId=null;this.connectionId=null;this.userData={};this.roomOptions={};this.localStream=null;this.loginParams={};this.files={};this.isMuted={audio:false,video:false};this.events={}};j.prototype.init=function(){var k=this;this.loadTplByName("tplConnections",function(l){k.loadTplByName("tplMain",function(p){k.$elem.html(k.tmpl(p,{config:k.config}));k.$connectionsPanel=k.$elem.find("#connectionsPanel");k.$messagePanel=k.$elem.find("#messagePanel");k.$loginPanel=k.$elem.find("#loginPanel");k.$videoPanel=k.$elem.find("#videoPanel");k.$loginDialog=k.$elem.find("#loginDialog");k.$callPanel=k.$elem.find("#callPanel");k.$answerDialog=k.$elem.find("#answerDialog");k.$shareDialog=k.$elem.find("#shareDialog");k.$fileAcceptDialog=k.$elem.find("#fileAcceptDialog");k.$chatPanel=k.$elem.find("#chatPanel");k.$filesPanel=k.$elem.find("#filesPanel");k.$youInfoPanel=k.$elem.find("#youInfoPanel");k.loginParams={};var r={},o={},q={websocket:k._("Your browser does not support websocket."),peerconnection:k._("Your browser does not support PeerConnections."),usermedia:k._("Your browser does not support user media.")};if(!c.checkCompatibility(r,o,"chat")){k.debug(r);var n=[];for(var m in r){n.push(q[m])}n.push(k._('Please try <a href="http://www.google.com/chrome" target="_blank">Google Chrome</a> or <a href="http://www.mozilla.org/en-US/firefox" target="_blank">Mozilla Firefox</a>'));k.message(n.join("<br>"),"danger")}else{c.loadDevices(function(s){k.devices=s;k.loginParams.hasAudioDevice=k.devices.audio.length>0;k.loginParams.hasVideoDevice=k.devices.video.length>0;if(!k.loginParams.hasAudioDevice){k.$answerDialog.find("#answerAudio").hide()}if(!k.loginParams.hasVideoDevice){k.$answerDialog.find("#answer").hide()}});if(!g.isEmptyObject(o)){var n=[];for(var m in o){n.push(q[m])}n.push(k._("You will not be able to make video calls."));n.push(k._('Please try <a href="http://www.google.com/chrome" target="_blank">Google Chrome</a> or <a href="http://www.mozilla.org/en-US/firefox" target="_blank">Mozilla Firefox</a>'));k.message(n.join("<br>"),"warning",5)}if(o.peerconnection){k.loginParams.noPc=true}if(o.usermedia){k.loginParams.noMedia=true}c.connect(k.config.wsURL)}k.initDom();k.initRtc();if(k.config.enableNotifications){d.grant()}});k.loadTplByName("tplChatInput",function(m){})})};j.prototype.initDom=function(){var l=this;l.$loginPanel.find("#loginButton").click(function(){if(l.config.login){l.config.login(function(){c.login(l.loginParams)})}else{l.$loginDialog.modal("show")}});l.$loginDialog.on("shown.bs.modal",function(){l.$loginDialog.find("#userName").focus()});var m=function(){if(l.$loginDialog.find("#userName").val()){l.setCookie("mgVideoChatSimple",l.$loginDialog.find("#userName").val(),30,h.location.hostname);l.$loginDialog.modal("hide");h.location.reload()}};l.$loginDialog.find("#userName").keypress(function(n){if(n.keyCode===13){m();return false}});l.$loginDialog.find("button.login").click(m);l.$videoPanel.find("#videoFullScreen").click(function(){var n=l.$videoPanel.get(0),o=n.requestFullScreen||n.webkitRequestFullScreen||n.mozRequestFullScreen;o.call(n)});l.$videoPanel.find("#videoExitFullScreen").click(function(){var n=i.cancelFullScreen||i.webkitCancelFullScreen||i.mozCancelFullScreen;n.call(i)});l.$videoPanel.find("#callHangup").click(function(){c.drop(l.videoId)});var k=function(r,q){if(!l.localStream){return false}var o=(q=="audio")?l.localStream.getAudioTracks():l.localStream.getVideoTracks();if(o.length===0){return false}var p;for(p=0;p<o.length;p++){o[p].enabled=l.isMuted[q]}l.isMuted[q]=!l.isMuted[q];var n=(l.isMuted[q])?"off":"on";r.attr("title",r.data("title-"+n));r.find("span").removeClass(r.data("icon-on")).removeClass(r.data("icon-off")).addClass(r.data("icon-"+n))};l.$videoPanel.find("#videoMute").click(function(){k(g(this),"video")});l.$videoPanel.find("#audioMute").click(function(){k(g(this),"audio")});l.$answerDialog.find("#answer").click(function(){c.accept(l.$answerDialog.data("caller_id"),l.getMediaOptions({audio:true,video:true}));l.$answerDialog.modal("hide")});l.$answerDialog.find("#answerAudio").click(function(){c.accept(l.$answerDialog.data("caller_id"),l.getMediaOptions({audio:true,video:false}));l.$answerDialog.modal("hide")});l.$answerDialog.find("#cancelCall").click(function(){c.drop(l.$answerDialog.data("caller_id"));l.$answerDialog.modal("hide")});l.$shareDialog.find("#shareCam").click(function(){l.createGroupStream();l.$shareDialog.modal("hide")});l.$shareDialog.find("#shareDesktop").click(function(){l.getDesktopShareMedia(function(n){if(!n){return false}l.createGroupStream(n)});l.$shareDialog.modal("hide")});l.$fileAcceptDialog.find("#fileAccept").click(function(){var n=l.$fileAcceptDialog.data("file_desc");var o=l.$fileAcceptDialog.data("connection_id");l.$fileAcceptDialog.modal("hide");n.firefox=c.firefox;l.fileAccept(n,o)});l.$fileAcceptDialog.find("#fileCancel").click(function(){var n=l.$fileAcceptDialog.data("file_desc");var o=l.$fileAcceptDialog.data("connection_id");l.fileCancel(n,o);l.$fileAcceptDialog.modal("hide")});g("#connectionsPanel").on("click","#rouletteNext",function(){l.rouletteNext()});g("#offcanvasButton").click(function(){g(".row-offcanvas").toggleClass("active");event.stopPropagation()});g("body").click(function(){g(".row-offcanvas").removeClass("active")});g("#sideMenu").click(function(n){n.stopPropagation()})};j.prototype.fileAccept=function(k,l){this.files[k.id].pending=false;this.renderFiles();c.fileAccept(l,k)};j.prototype.fileCancel=function(k,l){delete this.files[k.id];this.renderFiles();c.fileCancel(l,k)};j.prototype.onConnected=function(){this.$loginPanel.show()};j.prototype.onDisconnected=function(){this.disableChat()};j.prototype.onLogged=function(){this.$loginPanel.hide()};j.prototype.onConnectionClose=function(k){this.$connectionsPanel.find("#connection_"+k).remove();this.disableChat(k);if(this.videoId==k){this.onVideoClose()}if(this.videoInvitedId==k){this.inviteStop()}delete c.connections[k];this.fire("connections",c.connections)};j.prototype.onVideoOpen=function(k){this.videoId=k;if(k){this.$callPanel.find(".panel-title").text(this._("Call with {username}",["{username}"],[c.connections[k]["data"]["userData"]["name"]]))}this.$callPanel.show();this.updateLayout();if(!this.roomOptions.group){this.renderConnections()}};j.prototype.onVideoClose=function(){var k=this;this.videoId=null;if(!this.roomOptions.group){k.$elem.find("#localVideo").attr("src","")}k.$elem.find("#remoteVideo").attr("src","");k.$callPanel.hide();k.inviteStop();this.renderConnections();this.remoteVideoGroupSelect()};j.prototype.inviteStart=function(k){this.videoAnswerDialog(k);this.videoInvitedId=k;this.callRing(false)};j.prototype.inviteStop=function(){this.$answerDialog.modal("hide");this.videoInvitedId=null;this.callRing(true)};j.prototype.videoAnswerDialog=function(m){var l=this;var k=c.connections[m].data.userData;l.$answerDialog.data("caller_id",m);l.$answerDialog.find(".username").text(k.name);if(k.image){l.$answerDialog.find(".desc").html('<img src="'+k.image+'" alt="'+k.name+'"/>')}l.$answerDialog.modal("show")};j.prototype.callRing=function(k){var l=this.$elem.find("#ringSound").get(0);if(k){l.pause()}else{l.play()}};j.prototype.notifySound=function(){this.$elem.find("#notifySound").get(0).play()};j.prototype.rouletteNext=function(){if(this.videoId){c.drop(this.videoId,false,true)}c.rouletteNext()};j.prototype.hasMedia=function(n,l){try{var k=(l=="audio")?n.getAudioTracks():n.getVideoTracks();return k.length>0}catch(m){return false}};j.prototype.videoSetStream=function(k,l){k.get(0).srcObject=l};j.prototype.localVideoOpen=function(l,k){if(l){this.videoSetStream(this.$elem.find("#localVideo"),l);this.$elem.find("#localVideo").show();this.isMuted={audio:false,video:false};if(!this.hasMedia(l,"video")){this.$elem.find("#videoMute")}if(!this.hasMedia(l,"audio")){this.$elem.find("#audioMute")}}else{this.$elem.find("#localVideo").hide()}this.onVideoOpen(k)};j.prototype.remoteVideoOpen=function(l,k){if(l){this.videoSetStream(this.$elem.find("#remoteVideo"),l);this.$elem.find("#remoteVideo").show()}else{this.$elem.find("#remoteVideo").hide()}if(k){this.onVideoOpen(k)}};j.prototype.remoteVideoGroupSelect=function(){if(!this.roomOptions.group||this.videoId){return}for(var l in c.connections){if(c.connections[l].rstream){var k=this.$connectionsPanel.find("#connection_"+l+".connectionItem");k.click()}}};j.prototype.getMediaOptions=function(k){k.video=k.video&&!this.roomOptions.disableVideo;k.audio=k.audio&&!this.roomOptions.disableAudio;return k};j.prototype.onRoomOptions=function(){var k=this;var m=navigator.userAgent.toLowerCase().indexOf("chrome")>-1;this.roomOptions.desktopShare=this.roomOptions.desktopShare&&m;if(this.roomOptions.group||this.roomOptions.roulette){if(this.roomOptions.group){this.debug("This chat is group/conference chat");this.$videoPanel.find("#callHangup").remove()}else{this.config.tplConnections=this.config.tplRoulette;this.debug("This chat is roulette chat")}c.debug("creating local media stream");if(k.loginParams.noPc||k.loginParams.noMedia||(this.roomOptions.disableVideo&&this.roomOptions.disableAudio)){c.debug("no webrtc support");k.localStream=null;k.onMediaStreamGroup(true)}else{if(this.roomOptions.desktopShare){c.debug("sharing desktop dialog option");this.$shareDialog.modal("show")}else{k.createGroupStream()}}}if(this.roomOptions.disableVideo){this.$answerDialog.find("#answer").hide();var l=this.$elem.find("#localVideoBg"),n=this.$elem.find("#remoteVideoBg");l.addClass("localAudio").show();n.addClass("remoteAudio").show();this.$elem.find("#localVideo").hide();this.$elem.find("#remoteVideo").hide()}if(this.roomOptions.disableAudio){this.$answerDialog.find("#answerAudio").hide()}};j.prototype.createGroupStream=function(k){var l=this;k=k?k:this.getMediaOptions({audio:l.loginParams.hasAudioDevice,video:l.loginParams.hasVideoDevice});c.createStream(null,k,function m(o){c.debug("local stream added");l.onMediaStreamGroup(true)},function n(o){l.localStream=null;c.debug("local stream rejected");l.onMediaStreamGroup(true)})};j.prototype.onMediaStreamGroup=function(l){var k=this;c.mediaReady();if(k.roomOptions.group){k.connectAllMediaReady();k.setChat(0)}if(k.roomOptions.roulette){k.rouletteNext()}};j.prototype.connectAllMediaReady=function(){var k=this;if(!c.connectionsLoaded){setTimeout(function(){k.connectAllMediaReady()},1000)}if(!this.roomOptions.group&&!this.roomOptions.roulette){return false}for(var l in c.connections){if(!c.connections[l].rstream&&c.connections[l].media_ready){if(!c.connections[l].stream){c.connections[l].stream=k.localStream}if(c.refuseIdleState(l)){return false}c.sdpOffer(l)}}};j.prototype.getDesktopShareMedia=function(l){var k=this;b.getSourceId(function(o,n){if(!o){if(n=="no-permission"&&location.protocol!="https:"){k.message(k._("Desktop can be shared only over https secure connection."),"danger")}if(n=="no-extension"){k.message(k._('Please <a href="#" class="btn btn-success extensionInstall">install</a> this chrome extension in order to use desktop sharing and reload this page.'),"danger");k.$elem.find(".extensionInstall").click(function(){try{chrome.webstore.install("https://chrome.google.com/webstore/detail/"+k.config.chromeExtensionId,function p(){location.reload()},function r(s){k.message(s,"danger")})}catch(q){h.open("https://chrome.google.com/webstore/detail/"+k.config.chromeExtensionId,"install")}return false})}return l(false)}var m={audio:false,video:{mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:o,maxWidth:h.screen.width,maxHeight:h.screen.height,maxFrameRate:3}}};if(!k.roomOptions.disableAudio){m.audioAppend=true}c.debug("mediaOptions");c.debug(m);return l(m)})};j.prototype.disableChat=function(k){if(!k){this.$chatPanel.find(".form-control").attr("disabled","disabled")}else{this.$chatPanel.find("#chat_"+k+" .form-control").attr("disabled","disabled")}};j.prototype.setChat=function(k){this.chatId=k;this.$chatPanel.find(".chat").hide();this.getChatDiv(k).show();if(k>0){this.$chatPanel.find(".panel-title").text(this._("Chat with {username}",["{username}"],[c.connections[k]["data"]["userData"]["name"]]))}else{this.$chatPanel.find(".panel-title").text(this._("Group chat"))}this.$chatPanel.show();this.updateLayout();if(k&&c.connections[k]["data"].unread){c.connections[k]["data"].unread=0;this.renderConnection(k)}};j.prototype.getRtc=function(){return c};g.fn.mgVideoChat=function(l,n,m){if(l==="on"){var k=g(this).data("mgVideoChat-instance");if(k){return k.on(n,m)}}else{var o=[];this.each(function(){o.push(new j(this,l))});if(o.length===1){return o[0]}return o}};g.fn.mgVideoChat._=function(n,p,m){var k=n;if(g.fn.mgVideoChat.translate&&g.fn.mgVideoChat.translate[n]){k=g.fn.mgVideoChat.translate[n]}if(!p||!p.length){return k}var o;for(var l=0;l<p.length;l++){o=new RegExp(p[l],"g");k=k.replace(o,m[l])}return k};g.fn.mgVideoChat.htmlspecialchars=function(m,r,q,l){var o=0,n=0,p=false;if(typeof r==="undefined"||r===null){r=2}m=m.toString();if(l!==false){m=m.replace(/&/g,"&amp;")}m=m.replace(/</g,"&lt;").replace(/>/g,"&gt;");var k={ENT_NOQUOTES:0,ENT_HTML_QUOTE_SINGLE:1,ENT_HTML_QUOTE_DOUBLE:2,ENT_COMPAT:2,ENT_QUOTES:3,ENT_IGNORE:4};if(r===0){p=true}if(typeof r!=="number"){r=[].concat(r);for(n=0;n<r.length;n++){if(k[r[n]]===0){p=true}else{if(k[r[n]]){o=o|k[r[n]]}}}r=o}if(r&k.ENT_HTML_QUOTE_SINGLE){m=m.replace(/'/g,"&#039;")}if(!p){m=m.replace(/"/g,"&quot;")}return m}})(jQuery,window,document);