Files
Testing/mongolian/mgVideoChat/mgVideoChat-1.18.0-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

99 lines
46 KiB
JavaScript

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