/*
 UC Web Apprication 7.0.1 by NEC Platforms,Ltd.
*/
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,b,c){a instanceof String&&(a=String(a));for(var d=a.length,f=0;f<d;f++){var e=a[f];if(b.call(c,e,f,a))return{i:f,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(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};$jscomp.getGlobal=function(a){a=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,a];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}return globalThis};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var f=a[d];f in c||(c[f]={});c=c[f]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,c){return $jscomp.findInternal(this,a,c).v}},"es6","es3");
var CR=String.fromCharCode(13),prm_user_id=null,prm_password=null,prm_conf_id="",prm_langage="default",prm_room_no=0,prm_mode="",self_id=-1,user_id="",user_pw="",conf_id="",sc_type="sc_loading",B_FONT_SIZE=15,VF_FONT_SIZE=15,Server=null,no_closedlg_flg=!0,reconnect_flg=!1,CONF_MAX=4,ENLARGE_BUTTON=0,ENLARGE_CLICK=1,MODE_NONE=0,MODE_CTI=1,MODE_SMARTDEV=2,MODE_SIP=3,MODE_ST500=4,debuglog=0,l={log:function(a){0<debuglog&&console.log(a)},dir:function(a){1<debuglog&&console.dir(a)},warn:function(a){console.warn(a)},
error:function(a){0<=debuglog&&console.error(a)}},kovm,koVm=function(){var a=this;a.dialogMsg=ko.observable("");a.dialogBtns=ko.observableArray([]);a.confList=ko.observableArray([]);a.confResource=ko.observableArray([]);a.vqstr_h=ko.observable("");a.vqstr_l=ko.observable("");a.vmsg_rv1=ko.observable("");a.vmsg_rv2=ko.observable("");a.vmsg_rv3=ko.observable("");a.vmsg_rv4=ko.observable("");a.vmsg_rv5=ko.observable("");a.vmsg_rv6=ko.observable("");a.vmsg_rv7=ko.observable("");a.vmsg_lv=ko.observable("");
a.vmsg_lv_flg=ko.observable(!0);a.enlargeMode=ko.observable(ENLARGE_CLICK);a.enaCapture=ko.observable(!1);a.audio_flg=ko.observable(!1);a.video_flg=ko.observable(!1);a.cap_flg=ko.observable(-1);a.video_qt=ko.observable(1);a.video_qt_str=ko.pureComputed(function(){switch(a.video_qt()){case 0:return"Low (64K)";case 2:return"High(2.5M)";default:return"Mid (256K)"}});a.audio_ini_off=ko.observable(!1);a.video_ini_off=ko.observable(!1);a.isAudioDevAttached=ko.observable(!1).extend({rateLimit:500});a.isVideoDevAttached=
ko.observable(!1).extend({rateLimit:500});a.audioDevice=ko.observable({label:"No Device",deviceId:"default"});a.videoDevice=ko.observable({label:"No Device",deviceId:"default"});a.tmpAudioDevice=ko.observable(null);a.tmpVideoDevice=ko.observable(null);a.audioDeviceList=ko.observable([]);a.devReloadTmr=null;a.audioDeviceViewList=ko.pureComputed(function(){var b=a.audioDeviceList();0==b.length&&b.push({label:langTbl.no_device,deviceId:"default"});a.devReloadTmr&&(clearTimeout(a.devReloadTmr),a.devReloadTmr=
null);a.devReloadTmr=setTimeout(function(){reloadMediaCfg()},100);return b}).extend({rateLimit:500});a.videoDeviceList=ko.observable([]);a.videoDeviceViewList=ko.pureComputed(function(){var b=a.videoDeviceList();0==b.length&&b.push({label:langTbl.no_device,deviceId:"default"});a.devReloadTmr&&(clearTimeout(a.devReloadTmr),a.devReloadTmr=null);a.devReloadTmr=setTimeout(function(){reloadMediaCfg()},100);return b}).extend({rateLimit:500});a.audioDeviceId=ko.pureComputed(function(){return null==a.audioDevice()?
"default":a.audioDevice().deviceId});a.audioGroupId=ko.pureComputed(function(){return null==a.audioDevice()?"default":a.audioDevice().groupId});a.videoDeviceId=ko.pureComputed(function(){return null==a.videoDevice()?"default":a.videoDevice().deviceId});a.videoGroupId=ko.pureComputed(function(){return null==a.videoDevice()?"default":a.videoDevice().groupId})},D_BODY_DEFAULT=0,D_BODY_MEDIACFG=1,dlgBtnList=[],D_BTN_LOGOUT=0,D_BTN_CNFIM=1,D_BTN_CONFDR=2,D_BTN_CLOSED=3,D_BTN_REJOIN=4,D_BTN_CONFSTART=5,
dBtnObj=function(a,b){this.label=a;this.func=b};
function initDialog(){btns=[];label=langTbl.d_ok;btn=new dBtnObj(label,function(){closeDialog();fadein_ScLogin()});btns.push(btn);dlgBtnList.push(btns);btns=[];label=langTbl.d_ok;btn=new dBtnObj(label,function(){closeDialog()});btns.push(btn);dlgBtnList.push(btns);btns=[];label=langTbl.d_no;btn=new dBtnObj(label,function(){closeDialog()});btns.push(btn);label=langTbl.d_yes;btn=new dBtnObj(label,function(){sendJsonData({type:"event",event:"conf-timer"});closeDialog()});btns.push(btn);dlgBtnList.push(btns);
btns=[];dlgBtnList.push(btns);btns=[];label=langTbl.resume;btn=new dBtnObj(label,function(){prm_password=null;closeDialog();no_closedlg_flg=!1;Server.connect()});btns.push(btn);dlgBtnList.push(btns);btns=[];label=langTbl.start;btn=new dBtnObj(label,function(){dvc_ready&&(changeMediaDevice(),closeDialog(),fadein_ScConf())});btns.push(btn);dlgBtnList.push(btns)}function destroyDialog(){objs=dlgBtnList.removeAll();for(var a in objs)delete objs[a]}
function openDialog(a,b,c){var d=0;closeDialog();kovm.dialogMsg(setAutoLink(a));for(var f in b)kovm.dialogBtns.push(b[f]),d++;void 0==c&&(c=D_BODY_DEFAULT);$(".dialog_wrap").css("display","none");$(".dialog_btn").css("display","none");$("#dialg_mask").css("display","block");c==D_BODY_MEDIACFG?$("#mediacfg_wrap").css("display","block"):$("#maindlg_wrap").css("display","block");d&&$(".dialog_btn_"+d).css("display","block")}
function closeDialog(){$("#dialg_mask").css("display","none");$(".dialog_wrap").css("display","none");$(".dialog_btn").css("display","none");kovm.dialogMsg("");kovm.dialogBtns.removeAll()}var confObj=function(a,b){this.creater=ko.observable(a);this.memberNo=ko.observable(b)};
function initClip(){clip=new ClipboardJS("#copy-button");clip.on("success",function(a){l.dir({"Copied text to clipboard":a});openDialog(langTbl.d_conf_4+a.text,dlgBtnList[D_BTN_CNFIM]);a.clearSelection()});clip.on("error",function(a){l.error("Action:",a.action);l.error("Trigger:",a.trigger);l.dir({"Error in clipboard":a});clip.destroy();clip=null;setTimeout("initClip()",2E3)})}var dvc_ready=!1;
$(document).ready(function(){var a=!1;try{navigator.userAgent.match(/Trident\/7/g)?l.log("IE11"):null!==navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?(l.log("iOS Safari"),a=!0):chrome&&(navigator.userAgent.match(/(iPad|iPhone|iPod|Edge\/)/g)?l.log("Edge(EdgeHtml)!"):(l.log("chrome or Edge(Chromium)"),a=!0))}catch(c){l.dir(c)}kovm=new koVm;ko.applyBindings(kovm);initDialog();for(b=0;b<CONF_MAX;b++)kovm.confResource.push(!0);if(!1===a)l.log("not supported!"),openDialog(langTbl.d_error_3,dlgBtnList[D_BTN_CLOSED]);
else{for(var b=1;b<MAX_CONNECTION_COUNT;b++)pushVideoStandBy(getVideoForRemote(b));a=location.protocol+"//"+location.host;a=a.replace("http","ws");a+="/uc/ws";l.log("srvURL="+a);Server=new FancyWebSocket(a);Server.bind("open",function(){onOpened()});Server.bind("close",function(a){onClose(a)});Server.bind("message",function(a){onMessage(a)});ParseAccessUrl();"st500"==prm_mode?"visible"!==document.visibilityState?interruptConf():DispFirstPage():DispFirstPage();setLangage();adjustBodyFontSize();adjustPageBodySize();
chkEnlargeMode();$(window).on("orientationchange resize",function(a){adjustFrames();"orientationchange"===a.type&&iOS_Device()&&setTimeout("sendConfStatus(-1)",2E3)});$(".video").each(function(a,b){$(b).on("loadedmetadata resize",function(a){"loadedmetadata"==a.type&&this.id==localVideo.id&&(l.log("get frame->novideo"),a=$("#frame-"+localVideo.id).find(".novideo"),l.dir(a[0]),a[0].innerHTML='<div class="faol"><i class="fa fa-user"></i><div>',localStream&&0<localStream.getVideoTracks().length&&(l.log("show local video!"),
opacityCtrl(localVideo,!0)));adjustFrames()})});$(".videoFrame").each(function(a,b){$(b).mouseenter(function(){adjustFrames()})});$(".videoFrame").each(function(a,b){$(b).on("dragstart dragenter dragover dragleave drop dragend",function(a){handleDnD(this,a)})});"st500"==prm_mode&&document.addEventListener("visibilitychange",function(){"visible"!==document.visibilityState&&interruptConf()});try{navigator.mediaDevices.ondevicechange=function(a){"sc_loading"==sc_type&&updtVideoConstraint()}}catch(c){}}});
function setLangage(){l.log("setLangage");loadLangTbl("login_b1","button");loadLangTbl("login_id","div");loadLangTbl("login_pw","div");loadLangTbl("create_t","div");loadLangTbl("create_b1","button");loadLangTbl("create_id","div");loadLangTbl("create_list","div");loadLangTbl2("conf_gc_enlarge","title");loadLangTbl2("conf_gc_video","title");loadLangTbl2("conf_gc_audio","title");loadLangTbl2("conf_gc_videooff","title");loadLangTbl2("conf_gc_audiooff","title");loadLangTbl2("conf_gc_scshare","title");
loadLangTbl2("conf_gc_urlcopy","title");loadLangTbl2("conf_gc_quality","title");loadLangTbl2("conf_gc_valert","title");kovm.vqstr_h(langTbl.conf_gc_quality+": High");kovm.vqstr_l(langTbl.conf_gc_quality+": Low")}function loadLangTbl(a,b){var c=document.getElementById(a);if(c)switch(b){case "div":l.log("div:"+a);c.innerHTML=langTbl[a];break;case "button":l.log("button:"+a),c.value=langTbl[a]}}
function loadLangTbl2(a,b){var c=document.getElementsByClassName(a);if(c.length)for(var d in c)switch(target=c[d],b){case "div":target.innerHTML=langTbl[a];break;case "button":target.value=langTbl[a];break;case "textarea":target.placeholder=langTbl[a];break;case "title":target.title=langTbl[a]}target=null}function iOS_Device(){return null!==navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1}function Android_Device(){return null!==navigator.userAgent.match(/Android/g)?!0:!1}
function isSmartDevice(){return iOS_Device()||Android_Device()?!0:!1}function chkEnlargeMode(){}function adjustBodyFontSize(){var a=$(window).width();document.body.style.fontSize=700>a?a/700*B_FONT_SIZE+"px":B_FONT_SIZE+"px"}
function adjustPageBodySize(){var a=document.getElementById("pagebody");var b=$("#copy-button").outerWidth(!0)+1+$("#hdr_btns").outerWidth(!0)+$("#vqt_select").outerWidth(!0)+1+$("#conf-id").outerWidth(!0)-$("#conf-id").width();a.style.minWidth=270<b?b+"px":"270px";$("#conf-id").css("maxWidth","calc(100% - "+b+"px)");a.style.height="100%";var c=$("#pagebody").height();switch(sc_type){case "sc_login":b=$("#input-login").height();b>c&&(a.style.height=b+40+"px");break;case "sc_create_conf":b=$("#input-create").height(),
b>c&&(a.style.height=b+40+"px")}}var echo_count=0;function getDateTime(){var a=new Date;return">>> "+(a.getMonth()+1)+"/"+a.getDate()+" "+a.getHours()+":"+a.getMinutes()+":"+a.getSeconds()+" ["+echo_count+"]"}
function ParseAccessUrl(){var a=GetQueryString();null!==a&&(void 0!==a.u&&(prm_user_id=a.u),void 0!==a.p&&(prm_password=a.p),void 0!==a.id&&(prm_conf_id=a.id),void 0!==a.lang&&(prm_langage=a.lang),void 0!==a.m&&(prm_mode=a.m));a=document.location.pathname.split("/");"sconf"==a[2]&&(prm_room_no=parseInt(a[3],10))}
function GetQueryString(){if(1>=document.location.search.length)return null;var a=document.location.search.substring(1).split("&"),b={};if(null===b)return null;for(var c=0;c<a.length;c++){var d=a[c].split("="),f=decodeURIComponent(d[0]);d=decodeURIComponent(d[1]);b[f]=decodeURIComponent(d)}return b}
function DispFirstPage(){""===prm_conf_id?($(".sc_loading").fadeOut(500),setTimeout("fadein_ScLogin()",500)):(conf_id=prm_conf_id,user_id=prm_user_id,no_closedlg_flg=!1,Server.connect(),closeDialog())}function sendConfJoinReq(){if(""!==conf_id){var a={type:"event",event:"conf-joReq",confId:conf_id};prm_room_no&&(a.room=prm_room_no);null!==prm_user_id&&(a.id=prm_user_id);"st500"==prm_mode&&(a.tel=MODE_ST500);sendJsonData(a)}}
function login_create(){l.log(CR+"login_create()");l.log("Login: "+prm_user_id+" & Create: "+prm_conf_id);var a={type:"event",event:"conf-crReq",id:prm_user_id,pw:prm_password,confId:prm_conf_id};"st500"==prm_mode&&(a.tel=MODE_ST500);sendJsonData(a)}
function sendConfStatus(a){l.log("sendConfStatus("+a+") c:"+kovm.video_flg()+" m="+kovm.audio_flg());var b={type:"event",event:"conf-status",mic:kovm.audio_flg(),vqt:kovm.video_qt()};localStream&&(b.vsid=localStream.id);screenStream&&(b.csid=screenStream.id);0<=a&&(b.sendto=a);1===kovm.cap_flg()||localStream&&0<localStream.getVideoTracks().length&&kovm.video_flg()?b.cam=!0:b.cam=!1;l.dir(b);sendJsonData(b)}var keepAliveTimer,clip=null;
function onOpened(){l.log(getDateTime()+"*** socket opened ***");socketReady=!0;reconnect_flg=!1;keepAliveTimer=setInterval("Server.disconnect()",6E4);""===prm_conf_id&&""===conf_id?login():null===prm_user_id||null===prm_password?sendConfJoinReq():login_create()}
function onClose(a){if(Server.conn!==a)l.log(getDateTime()+"## ignore old socket closed");else{l.log(getDateTime()+"*** socket closed ***");socketReady=!1;self_id=-1;hangUp();clearInterval(keepAliveTimer);keepAliveTimer=null;if(!no_closedlg_flg)switch(1){case "sc_loading"==sc_type:etext=reconnect_flg?langTbl.d_error_5:langTbl.d_error_2;openDialog(etext,dlgBtnList[D_BTN_CLOSED]);break;case "sc_conf"==sc_type:etext=langTbl.d_conf_1;openDialog(etext,dlgBtnList[D_BTN_CLOSED]);break;case "sc_login"==sc_type:etext=
reconnect_flg?langTbl.d_error_5:langTbl.d_error_2;openDialog(etext,dlgBtnList[D_BTN_LOGOUT]);break;default:case "sc_create_conf"==sc_type:etext=langTbl.d_error_2,openDialog(etext,dlgBtnList[D_BTN_CLOSED])}no_closedlg_flg=!0;echo_count=0;null!=rsz_timer&&clearTimeout(rsz_timer);rsz_timer=null}}
function onMessage(a){l.log("--- recieve data ---");l.dir({json:a});a=JSON.parse(a);switch(a.type){case "offer":l.log(getDateTime()+"--- onOffer from("+a.from+")---");onOffer(a);break;case "answer":l.log(getDateTime()+"--- onAnswer from("+a.from+")---");onAnswer(a);break;case "candidate":l.log(getDateTime()+"--- onCandidate from("+a.from+")---");onCandidate(a);break;case "event":switch(a.event){case "login":l.log(getDateTime()+"--- onLogin ---");onLogin(a);break;case "conf-list":l.log(getDateTime()+
"--- onConfList ---");onConfList(a);break;case "conf-crReq":l.log(getDateTime()+"--- onConfCrRes ---");onConfCrRes(a);break;case "conf-joReq":l.log(getDateTime()+"--- onConfJoRes ---");onConfJoRes(a);break;case "conf-rjReq":l.log(getDateTime()+"--- onConfRjReq ---");onConfRjReq(a);break;case "conf-echo":l.log(getDateTime()+"--- onConfEcho ---");onConfEcho(a);break;case "atch_null":l.log(getDateTime()+"--- onAtchNull ---");AttachNullStream(a);break;case "conf-bye":l.log(getDateTime()+"--- onBye ---");
onBye(a);break;case "conf-timer":l.log(getDateTime()+"--- onConfTimer ---");onConfTimer(a);break;case "keep-alive":l.log(getDateTime()+"--- onKeepAlive ---");onKeepAlive(a);break;case "conf-status":l.log(getDateTime()+"--- onConfStatus ---");onConfStatus(a);break;default:l.log(getDateTime()+"--- !! event type error !! ---"),l.log("message from: "+a.from+",type: "+a.type+",event: "+a.event)}break;default:l.log("--- !! message type error !! ---"),l.log("message from: "+a.from+",type: "+a.type+",event: "+
a.event)}}function sendJsonData(a){!0===socketReady&&(a=JSON.stringify(a),l.log("--- send data ---"),l.dir({json:a}),Server.send("message",a))}function onKeepAlive(){clearInterval(keepAliveTimer);keepAliveTimer=setInterval("Server.disconnect()",6E4)}
function onConfStatus(a){var b=a.from,c=conns[b],d=getVideoInUse(b);c&&c.peer||(c=prepareNewConnection(b,a.serv));a.vsid&&(c.vsid=a.vsid);a.csid&&(c.csid=a.csid);c.video_qt=a.vqt;statusIcon(b,a.cam,a.mic,a.vqt);c.video_flg=a.cam;c.audio_flg=a.mic;d&&(!0===c.video_flg?(opacityCtrl(d,!0),d.vmute=!1):(opacityCtrl(d,!1),d.vmute=!0),adjustFrames())}
function fadein_ScLogin(){$(".sc_login").fadeIn(500).css("display","inline");sc_type="sc_login";adjustPageBodySize();document.getElementById("inputUserId").focus()}function fadein_ScCreateConf(){$(".sc_create_conf").fadeIn(500).css("display","inline");sc_type="sc_create_conf";adjustPageBodySize();document.getElementById("inputConfId").focus()}
function fadein_ScConf(){$(".sc_conf").fadeIn(500).css("display","inline");sc_type="sc_conf";adjustPageBodySize();ready_cnt=0;startVideo();var a=document.getElementById("conf-id");a.innerHTML=conf_id;a.title=conf_id;setTimeout(function(){var a=document.getElementById("frame-lv");a.style.visibility="visible";a.style.display="inline";a.classList.add("self");AddframeArray("frame-lv");adjustFrames()},500)}
function startAuth(){var a=document.getElementById("inputUserId");""!==a.value&&(user_id=a.value,a.value="",a=document.getElementById("inputUserPw"),user_pw=a.value,a.value="",no_closedlg_flg=!1,reconnect_flg=!0,Server.connect())}function login(){l.log(CR+"login()");""!==user_id&&(l.log("Login ID: "+user_id),l.log("Login PW: "+user_pw),sendJsonData({type:"event",event:"login",mode:"conf",id:user_id,pw:user_pw}))}
function onLogin(a){var b=a.res;l.log("login-res: "+b+",self:"+a.self);switch(b){case "success":self_id=a.self;$(".sc_login").fadeOut(1E3);setTimeout("fadein_ScCreateConf()",1E3);break;default:etext=langTbl.d_login_1,openDialog(etext,dlgBtnList[D_BTN_LOGOUT]),no_closedlg_flg=!0}}
function onConfList(a){var b=a.limit;a=a.list.split(",");var c=kovm.confList.removeAll(),d;for(d in c)delete c[d],c[d]=null;for(d=0;d<b;d++){c=a[d].split(":");try{var f=decodeURIComponent(c[0])}catch(g){f=c[0]}try{var e=decodeURIComponent(c[1])}catch(g){e=c[1]}"0"!=e&&(c=confObj(f,e),kovm.confList.push(c))}}
function createConf(){l.log(CR+"createConf()");target=document.getElementById("inputConfId");""!==target.value&&(conf_id=target.value,target.value="",l.log("Create: "+conf_id),sendJsonData({type:"event",event:"conf-crReq",confId:conf_id}))}
function onConfCrRes(a){var b=a.res;l.log("create-res: "+b+",self:"+a.self);if("duplicate"===b&&""!==prm_conf_id)sendConfJoinReq();else{switch(b){case "success":self_id=a.self;l.log("secpt="+a.secpt+", pt="+a.pt);$("#copy-button").attr("data-clipboard-text",getConfUrl(a.secpt,a.pt));initClip();l.log("prm_conf_id="+prm_conf_id);$(".sc").css("display","none");$(".sc_loading").css("display","inline");sc_type="sc_loading";updtVideoConstraint();openDialog("",dlgBtnList[D_BTN_CONFSTART],D_BODY_MEDIACFG);
return;case "duplicate":a=langTbl.d_create_1;break;case "non-capacity":a=langTbl.d_create_2;break;case "error":a=langTbl.d_error;break;case "no-license":a=langTbl.d_create_2;break;default:return}openDialog(a,dlgBtnList[D_BTN_CLOSED]);"sc_loading"===sc_type&&(no_closedlg_flg=!0)}}
function onConfJoRes(a){var b=a.res;l.log("join-res: "+b+",self:"+a.self);switch(b){case "success":self_id=a.self;l.log("secpt="+a.secpt+", pt="+a.pt);$("#copy-button").attr("data-clipboard-text",getConfUrl(a.secpt,a.pt));initClip();updtVideoConstraint();openDialog("",dlgBtnList[D_BTN_CONFSTART],D_BODY_MEDIACFG);return;case "error":etext=langTbl.d_error;break;case "not-exist":etext=langTbl.d_join_4;break;case "non-capacity":etext=langTbl.d_join_1;break;case "no-license":etext=langTbl.d_join_2;break;
default:return}openDialog(etext,dlgBtnList[D_BTN_CLOSED]);"sc_loading"===sc_type&&(no_closedlg_flg=!0)}function onConfRjReq(a){interruptConf()}function onInternalFailure(){openDialog(langTbl.d_error_4,dlgBtnList[D_BTN_CLOSED]);no_closedlg_flg=!0;Server.conn.close()}
function sendConfEcho(a){l.log(CR+"sendConfEcho("+a+")");var b={type:"event",event:"conf-echo",vqt:kovm.video_qt()};null!==localStream||null!==screenStream?(b.attach="true",localStream&&(b.vsid=localStream.id),screenStream?b.csid=screenStream.id:delete b.csid):b.attach="false";0<=a&&(b.sendto=a);sendJsonData(b)}
function onConfEcho(a){var b=a.from,c=a.attach,d=conns[b];if("sc_conf"===sc_type){echo_count++;if(!d){if(getConnectionCount()>=MAX_CONNECTION_COUNT)return;d=prepareNewConnection(b,a.serv)}"false"===c?getVideoInUse(b)||attachVideo(b,null):(a.vsid&&(d.vsid=a.vsid),a.csid&&(d.csid=a.csid),d.video_qt=a.vqt);sendConfStatus(b);if((!localStream||0==localStream.getVideoTracks().length&&0==localStream.getAudioTracks().length)&&!screenStream&&(sendJsonData({type:"event",event:"atch_null",sendto:b}),"false"===
c))return;sendOffer(b)}}function AttachNullStream(a){a=a.from;var b=conns[a];b&&b.peer?getVideoInUse(a)||attachVideo(a,null):l.error("no conn at AttachNullStream")}var socketReady=!1,MAX_CONNECTION_COUNT=8,conns={};function Connection(){}function getConnectionCount(){var a=0,b;for(b in conns)a++;return a}function getConnectionIndex(a){var b=0,c;for(c in conns){if(c==a)return b;b++}return-1}function stopAllConnections(){for(var a in conns)stopConnection(a)}
function stopConnection(a){conns[a]?(l.log("stop and delete connection with id="+a),conns[a].peer.close(),$(conns[a].peer).removeAttr("peerid"),delete conns[a].peer,conns[a].stream&&delete conns[a].stream,conns[a].cstream&&delete conns[a].cstream,delete conns[a].vsid,delete conns[a].csid,delete conns[a].id,conns[a].icetimer&&(clearTimeout(conns[a].icetimer),conns[a].icetimer=null),delete conns[a]):l.log("try to stop connection, but not found id="+a)}
var mediaConstraints={mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:!0}};
function sendOffer(a){var b=conns[a];if(b&&b.peer){b&&l.dir({"sendOffer peer":b.peer});var c=conns[a].peer.getTransceivers().length;if(2<c)l.error("Too much 'm=' lines (m_len > 2)");else{if(1===c)if(l.log("'m=' lines (m_len = 1)"),copyStream)if(1===copyStream.getVideoTracks().length)conns[a].peer.addTransceiver("audio",{direction:"recvonly"}),l.log("add audio track (m_len = 1) [addTransceiver]");else if(1===copyStream.getAudioTracks().length)conns[a].peer.addTransceiver("video",{direction:"recvonly"}),
l.log("add video track (m_len = 1) [addTransceiver]");else{l.error("Exception(m_len === 1)");return}else{l.log("No copyStream");return}else 0===c&&(conns[a].peer.addTransceiver("video",{direction:"recvonly"}),conns[a].peer.addTransceiver("audio",{direction:"recvonly"}),l.log("add video/audio track (m_len = 0) [addTransceiver]"));b.peer.createOffer(mediaConstraints).then(function(c){"connected"!=b.peer.iceConnectionState&&"completed"!=b.peer.iceConnectionState&&(b.icetimer=setTimeout("onIceFailed('"+
a+"')",9E4),l.log("offer id="+a),l.dir({"Set icetimer":b.icetimer}));l.log("vqt peer="+b.video_qt+", own="+kovm.video_qt());c=b.video_qt>kovm.video_qt()?bandwidthCtrl(kovm.video_qt(),c):bandwidthCtrl(b.video_qt,c);b.peer.setLocalDescription(c);var d={};d.sendto=a;d.type=c.type;d.sdp=c.sdp;sendJsonData(d);l.log("[OK] send Offer message to ["+a+"].")}).catch(function(){l.error("#### Create Offer failed id="+a);onInternalFailure()})}}else l.error("no conn at sendOffer")}
function onOffer(a){setOffer(a);sendAnswer(a)}function setOffer(a){var b=conns[a.from];b&&b.peer?(b.peer.setRemoteDescription(new RTCSessionDescription(a)),null==b.peer.remoteDescription&&l.error({"error sdp":a.sdp})):l.error("no conn at setOffer")}
function sendAnswer(a){l.log("sending Answer. Creating remote session description...");var b=a.from,c=conns[b];c?(l.dir({"sendAnswer peer":c.peer}),c.peer.createAnswer(mediaConstraints).then(function(a){"connected"!=c.peer.iceConnectionState&&"completed"!=c.peer.iceConnectionState&&(c.icetimer=setTimeout("onIceFailed('"+b+"')",9E4),l.log("answer id="+b),l.dir({"Set icetimer":c.icetimer}));l.log("vqt peer="+c.video_qt+", own="+kovm.video_qt());a=c.video_qt>kovm.video_qt()?bandwidthCtrl(kovm.video_qt(),
a):bandwidthCtrl(c.video_qt,a);c.peer.setLocalDescription(a);var d={};d.sendto=b;d.type=a.type;d.sdp=a.sdp;sendJsonData(d);l.log("[OK] send Answer message to ["+b+"].")}).catch(function(){l.error("#### Create Answer failed id="+b);onInternalFailure()})):l.error("peerConnection not exist!")}function onAnswer(a){getConnectionCount()&&setAnswer(a)}
function setAnswer(a){var b=a.from,c=conns[b];c?(c.peer.setRemoteDescription(new RTCSessionDescription(a)),l.log("[OK] recv Answer message."),sendConfStatus(b)):l.error("peerConnection not exist!")}
function onIceFailed(a){l.log("--- onIceFailed("+a+") ---");var b=conns[a];if(b&&(l.dir({icetimer:b.icetimer}),b.icetimer)){if(a=getVideoInUse(a)){l.log("get frame->novideo");var c=$("#frame-"+a.id).find(".novideo");l.dir(c[0]);c[0].innerHTML='<div class="faol"><i class="fa fa-ban"></i></div>';setVMsg(a.id,langTbl.vmsg_error_2)}clearTimeout(b.icetimer);b.icetimer=null}}
function prepareNewConnection(a,b){var c={iceServers:b};l.dir({after:c});b=null;try{b=new RTCPeerConnection(c),l.dir(b)}catch(d){l.log("Failed to create peerConnection, exception: "+d.message)}c=new Connection;c.id=a;c.peer=b;$(b).attr("peerid",a);conns[a]=c;l.log("peer connected["+a+"]...");conns[a].vidSender=null;conns[a].audSender=null;conns[a].scrSender=null;$(conns[a].peer).on("icecandidate",onIceCandidate);$(conns[a].peer).on("track",onRemoteTrack);$(conns[a].peer).on("removestream",onRemoteStreamRemoved);
$(conns[a].peer).on("iceconnectionstatechange",onIceConStatChg);c.iceReady=!0;l.log("Adding local stream...");copyStream&&0<copyStream.getVideoTracks().length?(conns[a].vidSender=conns[a].peer.addTrack(copyStream.getVideoTracks()[0],copyStream),l.log("add Video Tracks")):l.log("No Video Tracks");copyStream&&0<copyStream.getAudioTracks().length?(conns[a].audSender=conns[a].peer.addTrack(copyStream.getAudioTracks()[0],copyStream),l.log("add Audio Tracks")):l.log("No Audio Tracks");return c}
function onIceCandidate(a){a=a.originalEvent;var b=$(this).attr("peerid");l.log("--- onIceCandidate("+b+") ---");a.candidate?sendJsonData({candidate:a.candidate.candidate,sdpMLineIndex:a.candidate.sdpMLineIndex,sdpMid:a.candidate.sdpMid,type:"candidate",sendto:b}):(l.log("End of candidates. ------------------- phase="+a.eventPhase),conns[b].established=!0)}
function onRemoteStreamRemoved(a){a=a.originalEvent;var b=$(this).attr("peerid");l.log("--- onRemoteStreamRemoved("+b+") ---");if(a.stream&&(l.dir(a.stream),"default"===a.stream.id)){l.log("ignore default stream.");return}if(conns[b].vsid===a.stream.id){var c=getVideoInUse(b);c&&opacityCtrl(c,!1);conns[b]&&delete conns[b].stream}l.log("fit default size");l.dir(a.stream.getAudioTracks());adjustFrames()}
function onRemoveTrack(a){console.log("Fire onremovetrack!");console.dir(a);a=a.originalEvent;var b=a.track;if("video"===b.kind)console.log("remove video track!");else if("audio"===b.kind){console.log("remove audio track! not implemmented...");return}if(a=a.srcElement)if(l.dir(a),"default"===a.id){l.log("ignore default stream.");return}b=null;for(var c in conns)conns[c].csid===a.id&&(b=c);null==b?l.log("not found stream."):(conns[b]&&delete conns[b].stream,conns[b].cstream||(c=getVideoInUse(b))&&
opacityCtrl(c,!1),l.log("fit default size"),l.dir(a.getAudioTracks()),adjustFrames())}function onAddTrack(a){console.log("Fire onaddtrack!");console.dir(a);a=a.originalEvent;var b=a.track;if("video"===b.kind)console.log("add video track!");else if("audio"===b.kind){console.log("add audio track! not implemmented...");return}if(a=a.srcElement)l.dir(a),"default"===a.id&&l.log("ignore default stream.")}
function onRemoteTrack(a){console.log("Fire onRemoteTrack!");console.dir(a);var b=a.originalEvent;a=a.currentTarget.peerid;console.dir(b);var c=b.track;b=b.streams[0];"video"===c.kind?console.log("Add Video Track!"):"audio"===c.kind&&console.log("Add Audio Track!");if(b&&(l.dir(b),"default"===b.id)){l.log("ignore default stream.");return}ret=attachVideo(a,b);conns[a]&&ret&&(conns[a].stream=b,remoteVideoStart(a));$(conns[a].stream).on("removetrack",onRemoveTrack);$(conns[a].stream).on("addtrack",onAddTrack);
console.log("onRemoteTrack Done!")}function onIceConStatChg(a){var b=a.originalEvent;a=$(this).attr("peerid");l.log("--- onIceConStatChg("+a+") ->"+this.iceConnectionState+" ---");l.dir({evt:b,peer:this});if("connected"!=this.iceConnectionState&&"completed"!=this.iceConnectionState)"failed"==this.iceConnectionState&&onIceFailed(a);else if(b=conns[a])null==b.icetimer?l.log("already connected"):(l.dir({"clear icetimer":b.icetimer}),clearTimeout(b.icetimer),b.icetimer=null,remoteVideoStart(a))}
function remoteVideoStart(a){var b=conns[a];if(b&&b.peer&&("connected"==b.peer.iceConnectionState||"completed"==b.peer.iceConnectionState)){var c=getVideoInUse(a);if(c){l.log("get frame->novideo");var d=$("#frame-"+c.id).find(".novideo");l.dir(d[0]);d[0].innerHTML='<div class="faol"><i class="fa fa-user"></i></div>';(d=conns[a].stream)?(c.autoplay="autoplay",c=attachStream(a,d),l.dir({stream:d,tracks:d.getVideoTracks(),videoElement:c}),0===d.getVideoTracks().length||!0!==b.video_flg?(l.log("no videoTrack"),
opacityCtrl(c,!1)):(l.log("show remote video MediaStream!"),opacityCtrl(c,!0))):l.log("No Remote Stream")}}}function getIdByStreamId(a){var b=-1,c;for(c in conns){if(conns[c].vsid===a){b=c;break}if(conns[c].csid===a){b=c;break}}return b}
function onCandidate(a){if(getConnectionCount()){var b=conns[a.from];b?b.iceReady?(a=new RTCIceCandidate({sdpMLineIndex:a.sdpMLineIndex,sdpMid:a.sdpMid,candidate:a.candidate}),l.log(a),b.peer.addIceCandidate(a)):l.warn("PeerConn is not ICE ready, so ignore"):l.error("peerConnection not exist!")}}function hangUp(){l.log(CR+"hangUp()");sendJsonData({type:"event",event:"conf-bye"});stopVideo();detachAllVideo();stopAllConnections()}
function onBye(a){getConnectionCount()&&(l.log(CR+"onBye()"),detachVideo(a.from),stopConnection(a.from))}
function onConfTimer(a){var b=a.prm1;a=a.prm2;l.log("conf timer evt: "+b);switch(b){case "close":etext=langTbl.d_conf_2;openDialog(etext,dlgBtnList[D_BTN_CLOSED]);no_closedlg_flg=!0;Server.conn.close();break;case "alert":"sc_conf"===sc_type&&(""==prm_room_no?(etext1=langTbl.d_conf_3_1,etext2=langTbl.d_conf_3_2+langTbl.d_conf_3_3,openDialog(etext1+a+etext2,dlgBtnList[D_BTN_CONFDR])):(etext1=langTbl.d_conf_3_1,etext2=langTbl.d_conf_3_2,openDialog(etext1+a+etext2,dlgBtnList[D_BTN_CNFIM])))}}
function interruptConf(){openDialog(langTbl.d_error_21,dlgBtnList[D_BTN_REJOIN]);no_closedlg_flg=!0;Server.conn.close();$(".sc_conf").css("display","none");$(".sc_loading").css("display","inline");sc_type="sc_loading"}var localStream=null,selfStream=null,copyStream=null,vidElm={},localVideo=document.getElementById("lv"),videoButton=document.getElementById("video-lv"),audioButton=document.getElementById("audio-lv"),constraints={video:!1,audio:!1};
function opacityCtrl(a,b){!0===b?a&&1>a.style.opacity&&$(a).css({opacity:0,visibility:"visible"}).animate({opacity:1}):a&&0<a.style.opacity&&$(a).css({opacity:1}).animate({opacity:0})}var ready_cnt=0;function startVideo(){!0===dvc_ready?_startVideo():(l.log(CR+"wait startVideo()..."),ready_cnt++,50<ready_cnt?(openDialog(langTbl.vmsg_error_3+"AccessTimeout",dlgBtnList[D_BTN_CLOSED]),no_closedlg_flg=!0,Server.conn&&Server.conn.close()):setTimeout("startVideo()",100))}
function _startVideo(){l.log(CR+"startVideo()");l.dir(location);l.dir(navigator);try{chrome&&navigator.mediaDevices&&"getDisplayMedia"in navigator.mediaDevices?-1===navigator.userAgent.indexOf("Android")&&"https:"===location.protocol&&(l.log("capture enable!"),$(".capture-button").css("display","inline"),kovm.enaCapture(!0)):l.log("not chrome and Edge! capture disable!")}catch(d){l.log("not chrome and Edge! capture disable!"),l.dir(d)}l.dir({constraints:constraints});if(!1!==constraints.video||!1!==
constraints.audio){var a=function(a){l.log("[OK] Media is ready");localStream=a;selfStream||(selfStream=new MediaStream);copyStream||(copyStream=new MediaStream);var b=selfStream.getVideoTracks();var c=b.length;if(0<c)for(var d=0;d<c;d++)selfStream.removeTrack(b[d]);b=copyStream.getVideoTracks();c=b.length;if(0<c)for(d=0;d<c;d++)b[d].stop(),copyStream.removeTrack(b[d]);b=copyStream.getAudioTracks();c=b.length;if(0<c)for(d=0;d<c;d++)b[d].stop(),copyStream.removeTrack(b[d]);0<localStream.getVideoTracks().length&&
(selfStream.addTrack(localStream.getVideoTracks()[0]),l.log("selfStream has a videoTrack of localStream"),copyStream.addTrack(localStream.getVideoTracks()[0].clone()),l.log("copyStream has a videoTrack of localStream"),1==kovm.video_ini_off()&&(copyStream.getVideoTracks()[0].enabled=!1));0<localStream.getAudioTracks().length&&(copyStream.addTrack(localStream.getAudioTracks()[0].clone()),l.log("copyStream has a audioTrack of localStream"),1==kovm.audio_ini_off()&&(copyStream.getAudioTracks()[0].enabled=
!1));dispMyVideo();kovm.video_flg(!1);kovm.audio_flg(!1);0<a.getVideoTracks().length&&($(videoButton).css("display","inline"),0==kovm.video_ini_off()&&kovm.video_flg(!0));kovm.video_ini_off(!1);0<a.getAudioTracks().length&&($(audioButton).css("display","inline"),0==kovm.audio_ini_off()&&kovm.audio_flg(!0));kovm.audio_ini_off(!1);for(var h in conns)0<copyStream.getVideoTracks().length&&(conns[h].vidSender=conns[h].peer.addTrack(copyStream.getVideoTracks()[0],copyStream)),0<copyStream.getAudioTracks().length&&
(conns[h].audSender=conns[h].peer.addTrack(copyStream.getAudioTracks()[0],copyStream));sendConfEcho(-1);sendConfStatus(-1);statusIcon(-1,kovm.video_flg(),kovm.audio_flg(),-1)},b=function(a){l.dir({"[NG] Media is failed":a});sendConfEcho(-1);statusIcon(-1,!1,!1,-1);try{chrome&&"http:"===location.protocol?setVMsg("lv",langTbl.vmsg_error_1):setVMsg("lv",langTbl.vmsg_error_3+"["+a.name+"] "+a.message)}catch(f){setVMsg("lv",langTbl.vmsg_error_3+"["+a.name+"] "+a.message)}},c=getDeviceStream(constraints);
c?c.then(a).catch(b):l.log("Not Support Browser")}else l.log("[--] No Media exists"),sendConfEcho(-1),setVMsg("lv",langTbl.vmsg_error_3+"[SourceUnavailableError]")}
function stopVideo(){localVideo.src="";localVideo.pause();attachMediaStream(localVideo,null);opacityCtrl(localVideo,!1);localStream&&(0<localStream.getVideoTracks().length&&localStream.getVideoTracks()[0].stop(),0<localStream.getAudioTracks().length&&localStream.getAudioTracks()[0].stop(),localStream=null);copyStream&&(0<copyStream.getVideoTracks().length&&copyStream.getVideoTracks()[0].stop(),0<copyStream.getAudioTracks().length&&copyStream.getAudioTracks()[0].stop(),copyStream=null);selfStream=
null;screenStream&&(0<screenStream.getVideoTracks().length&&(screenStream.getVideoTracks()[0].stop(),screenStream.getVideoTracks()[0].onended=null),screenStream=null);kovm.vmsg_lv_flg(!0);kovm.video_flg(!1);kovm.audio_flg(!1);kovm.video_qt(1);setVMsg("lv","");document.getElementById("frame-lv").style.display="none";adjustFrames()}
function updtVideoConstraint(a){if("sc_loading"===sc_type){void 0===a&&(a=!1);dvc_ready=!1;constraints.video=!1;constraints.audio=!1;kovm.audio_ini_off(!1);kovm.video_ini_off(!1);kovm.isAudioDevAttached(!1);kovm.isVideoDevAttached(!1);kovm.audioDeviceList([]);kovm.videoDeviceList([]);var b=!0;if(navigator.mediaDevices&&navigator.mediaDevices.enumerateDevices)navigator.mediaDevices.enumerateDevices().then(function(c){var d=[],f=[],e="";c.forEach(function(a){l.log(a.kind+": "+a.label+" id = "+a.deviceId);
"videoinput"==a.kind&&(""==a.label?(b=!1,e=langTbl.video_device+(f.length+1)):e=a.label,constraints.video=!0,f.push({label:e,deviceId:a.deviceId,groupId:a.groupId}));"audioinput"==a.kind&&(""==a.label?(b=!1,e=langTbl.audio_device+(d.length+1)):e=a.label,constraints.audio=!0,dvc_id=a.deviceId,d.push({label:e,deviceId:dvc_id}))});iOS_Device()&&0==a&&(b=!1);0==b&&0==a?getDeviceStream({audio:!0,video:!1}).then(function(a){var b=a.getTracks(),c;for(c in b)b[c].stop(),a.removeTrack(b[c]);a=null;1==constraints.video?
getDeviceStream({audio:!1,video:!0}).then(function(a){var b=a.getTracks(),c;for(c in b)b[c].stop(),a.removeTrack(b[c]);updtVideoConstraint(!0)}).catch(function(a){l.dir({"Failed to access":a});constraints.video=!1;constraints.audio=!1;kovm.isAudioDevAttached(!1);kovm.isVideoDevAttached(!1);dvc_ready=!0}):updtVideoConstraint(!0)}).catch(function(a){l.dir({"Failed to access":a});constraints.video=!1;constraints.audio=!1;kovm.isAudioDevAttached(!1);kovm.isVideoDevAttached(!1);dvc_ready=!0}):(l.dir({constraints:constraints}),
dvc_ready=!0,constraints.audio&&(kovm.isAudioDevAttached(!0),kovm.audioDeviceList(d)),constraints.video&&(kovm.isVideoDevAttached(!0),kovm.videoDeviceList(f)))}).catch(function(a){l.error(a.name+": "+a.message);ConstErrDetail=a.name+": "+a.message;dvc_ready=!0});else{l.log("Legacy getSources");try{MediaStreamTrack&&MediaStreamTrack.getSources?MediaStreamTrack.getSources(function(c){l.dir({sourceInfos:c});for(var d=[],f=[],e=0;e<c.length;e++)"video"==c[e].kind?(""==c[e].label&&(b=!1,c[e].label=langTbl.video_device+
(f.length+1)),constraints.video=!0,f.push(c[e])):"audio"==c[e].kind&&(""==c[e].label&&(b=!1,c[e].label=langTbl.audio_device+(d.length+1)),constraints.audio=!0,d.push(c[e]));iOS_Device()&&0==a&&(b=!1);0==b&&0==a?getDeviceStream({audio:!0,video:!1}).then(function(a){var b=a.getTracks(),c;for(c in b)b[c].stop(),a.removeTrack(b[c]);a=null;1==constraints.video?getDeviceStream({audio:!1,video:!0}).then(function(a){var b=a.getTracks(),c;for(c in b)b[c].stop(),a.removeTrack(b[c]);updtVideoConstraint(!0)}).catch(function(a){l.dir({"Failed to access":a});
constraints.video=!1;constraints.audio=!1;kovm.isAudioDevAttached(!1);kovm.isVideoDevAttached(!1);dvc_ready=!0}):updtVideoConstraint(!0)}).catch(function(a){l.dir({"Failed to access":a});constraints.video=!1;constraints.audio=!1;kovm.isAudioDevAttached(!1);kovm.isVideoDevAttached(!1);dvc_ready=!0}):(l.dir({constraints:constraints}),dvc_ready=!0,constraints.audio&&(kovm.isAudioDevAttached(!0),kovm.audioDeviceList(d)),constraints.video&&(kovm.isVideoDevAttached(!0),kovm.videoDeviceList(f)))}):dvc_ready=
!0}catch(c){l.dir(c),l.error("WebRTC Not Support Browser."),openDialog(langTbl.d_error_3,dlgBtnList[D_BTN_CLOSED]),dvc_ready=!0}}}}
function changeMediaDevice(){if(!1!==constraints.audio)try{kovm.tmpAudioDevice().deviceId!==kovm.audioDevice().deviceId&&(kovm.audioDevice(kovm.tmpAudioDevice()),constraints.audio={deviceId:kovm.audioDeviceId(),groupId:kovm.audioGroupId()})}catch(a){}if(!1!==constraints.video)try{kovm.tmpVideoDevice().deviceId!==kovm.videoDevice().deviceId&&(kovm.videoDevice(kovm.tmpVideoDevice()),constraints.video={deviceId:kovm.videoDeviceId(),groupId:kovm.videoGroupId()})}catch(a){}}
function reloadMediaCfg(){for(var a in kovm.audioDeviceViewList()){var b=kovm.audioDeviceViewList()[a];b.deviceId==kovm.audioDevice().deviceId&&kovm.tmpAudioDevice(b)}for(a in kovm.videoDeviceViewList())b=kovm.videoDeviceViewList()[a],b.deviceId==kovm.videoDevice().deviceId&&kovm.tmpVideoDevice(b)}function audioIniSwitch(){kovm.audio_ini_off(!kovm.audio_ini_off())}function videoIniSwitch(){kovm.video_ini_off(!kovm.video_ini_off())}
function getDeviceStream(a){if(navigator.mediaDevices&&"getUserMedia"in navigator.mediaDevices)return l.log("navigator.mediaDevices.getUserMadia"),navigator.mediaDevices.getUserMedia(a);l.log("navigator.getUserMadia with No Promise");return null}function dispMyVideo(){selfStream&&(1==iOS_Device()&&(localVideo.playsInline=!0),localVideo=attachMediaStream(localVideo,selfStream),localVideo.volume=0)}
function getVideoForRemote(a){a=document.getElementById("rv"+a);a.inuse=-1;a.vid=-1;1==iOS_Device()&&(a.playsInline=!0,a.muted=!0,a.audioElm=new Audio(""),a.audioElm.playsInline=!0,a.audioElm.autoplay=!0);return a}function pushVideoStandBy(a){if(a){l.log("pushVideoStandBy id="+a.id);var b=document.getElementById("frame-"+a.id);b.style.visibility="visible";b.style.display="none";-1===a.inuse?(vidElm[a.id]=a,a.inuse=0):1===a.inuse?a.inuse=0:l.log("already standby "+a.id)}}
function popVideoStandBy(){l.log("popVideoStandBy");for(var a in vidElm)if(0===vidElm[a].inuse)return vidElm[a].inuse=1,l.log("pop id="+a),vidElm[a];return null}function pushVideoInUse(a,b){l.log("pushVideoInUse id="+a);b&&(vidElm[b.id].vid=a,$("#frame-"+b.id).find(".novideo")[0].innerHTML='<div class="faol"><i class="fa fa-spinner fa-spin"></i></div>')}
function popVideoInUse(a){l.log("popVideoInUse");if(0<=a)for(var b in vidElm)if(vidElm[b].vid==a)return l.dir(vidElm[b].parentNode),vidElm[b]=attachStream(a,null),vidElm[b].vid=-1,vidElm[b].inuse=1,l.log("pop id="+b),vidElm[b];return null}function getVideoInUse(a){l.log("getVideoInUse id="+a);if(0<=a)for(var b in vidElm)if(vidElm[b].vid==a)return vidElm[b];return null}
function attachStream(a,b){l.log("attachStream to "+a);if(0<=a)for(var c in vidElm)if(vidElm[c].vid==a){vidElm[c]=attachMediaStream(vidElm[c],b);vidElm[c].vid=a;vidElm[c].inuse=1;1==iOS_Device()&&attachMediaStream(vidElm[c].audioElm,b);var d=b=!1,f=conns[a];f&&!0===f.video_flg&&(b=!0);f&&!0===f.audio_flg&&(d=!0);statusIcon(a,b,d,-1);return vidElm[c]}return null}
function attachVideo(a,b){l.log("try to attach video. id="+a);var c=!1,d=!1,f=!1,e=getVideoInUse(a);e||(e=popVideoStandBy(),pushVideoInUse(a,e),c=!0);if(e){if(null!==b){if(!1===c){e.src&&(l.log("revoke src!"),window.URL.revokeObjectURL(e.src));var g=conns[a];if("connected"==g.peer.iceConnectionState||"completed"==g.peer.iceConnectionState)null==g.stream&&(g.stream=b,e.autoplay="autoplay",e=attachStream(a,b),l.dir({stream:b,tracks:b.getVideoTracks(),videoElement:e})),0==b.getVideoTracks().length||
!0!==g.video_flg?(l.log("no videoTrack"),opacityCtrl(e,!1)):(l.log("show remote video stream!"),opacityCtrl(e,!0));g&&!0===g.video_flg&&(d=!0);g&&!0===g.audio_flg&&(f=!0);statusIcon(a,d,f,-1)}}else l.log("get frame->novideo"),b=$("#frame-"+e.id).find(".novideo"),l.dir(b[0]),b[0].innerHTML='<div class="faol"><i class="fa fa-user"></i></div>',statusIcon(a,!1,!1,-1);!0===c&&(c="frame-"+e.id,document.getElementById(c).style.display="inline",AddframeArray(c),(g=conns[a])&&!0===g.video_flg&&(d=!0),g&&!0===
g.audio_flg&&(f=!0),statusIcon(a,d,f,1));adjustFrames();return!0}l.log("[NG] no video element stand by.");l.error("--- no video element stand by.");return!1}
function detachVideo(a){if(!(0>a)){l.log("try to detach video. id="+a);var b=popVideoInUse(a);b?(b.pause(),b.src="",delete b.vmute,attachMediaStream(b,null),1==iOS_Device()&&attachMediaStream(b.audioElm,null),l.dir(b.parentNode),$(b).css({opacity:0}),a="frame-"+b.id,pushVideoStandBy(b),setVMsg(b.id,""),DelframeArray(a),adjustFrames()):(l.log("[NG] no video element using with id="+a),l.warn("warning --- no video element using with id="+a))}}
function detachAllVideo(){for(var a in vidElm)detachVideo(vidElm[a].vid)}function getVideoCountInUse(){var a=0,b;for(b in vidElm)1===vidElm[b].inuse&&a++;return a}
function videoSwitch(){var a=null;!0===kovm.video_flg()?(l.log("videoSwitch Off"),kovm.video_flg(!1),copyStream&&(a=copyStream.getVideoTracks()),0<a.length&&!screenStream&&(a[0].enabled=!1)):!1===kovm.video_flg()&&(l.log("videoSwitch On"),kovm.video_flg(!0),copyStream&&(a=copyStream.getVideoTracks()),0<a.length&&(a[0].enabled=!0,a[0].muted=!1));sendConfStatus(-1);statusIcon(-1,kovm.video_flg(),kovm.audio_flg(),kovm.video_qt())}
function audioSwitch(){!0===kovm.audio_flg()?(l.log("audioSwitch Off"),kovm.audio_flg(!1)):!1===kovm.audio_flg()&&kovm.audio_flg(!0);copyStream&&(atrks=copyStream.getAudioTracks());atrks&&(atrks[0].enabled=kovm.audio_flg());sendConfStatus(-1);statusIcon(-1,kovm.video_flg(),kovm.audio_flg(),kovm.video_qt())}
function statusIcon(a,b,c,d){var f="";if(-1==a){f="#cil";var e="#mil";var g="#vqul";var h="#vqdl";var k="lv"}else{k=getVideoInUse(a);if(!k)return;e="#mi"+k.id.slice(-1);g="#vqu"+k.id.slice(-1);h="#vqd"+k.id.slice(-1);k=k.id;l.log("statusIcon("+f+","+e+" cam="+b+",mic="+c+",vqt="+d)}""===getVMsg(k)&&(-1==a&&(!1===b?$(f).css("display","inline"):$(f).css("display","none")),!1===c?$(e).css("display","inline"):$(e).css("display","none"),0==d?($(g).css("display","none"),$(h).css("display","inline")):1==
d?($(g).css("display","none"),$(h).css("display","none")):2==d&&($(g).css("display","inline"),$(h).css("display","none")))}var scaleScreen=null;function scale(a){a="frame-"+a;l.log("scale id="+a);var b;for(b=farr.length;0<=b&&farr[b]!==a;b--);l.log("scale array["+b+"]:"+farr[b]);scaler===a&&0<=b?(l.log("OFF! scaler="+scaler),scaler=""):0<=b?(l.log("ON! scaler="+scaler+"->"+farr[b]),scaler=a):(l.error("invalid id!"),scaler="");adjustFrames()}
function clickToEnlarge(a){kovm.enlargeMode()===ENLARGE_CLICK&&scale(a)}var screenStream=null;
function capSwitch(){if(1===kovm.cap_flg()){if(l.log("stop Capture."),0<screenStream.getVideoTracks().length)screenStream.getVideoTracks()[0].onended()}else if(-1===kovm.cap_flg()){l.log("cap_flg = pending");kovm.cap_flg(0);var a=function(a){l.log("start Capture.");gotStream(a)},b=function(a){l.log("[NG] Media is failed.");l.error("An error occurred: ["+a+"]");kovm.cap_flg(-1)},c=getDisplayStream({audio:!1,video:{mandatory:{maxWidth:1280,maxHeight:720,maxFrameRate:60}}});c?c.then(a).catch(b):(l.log("Not Support Browser"),
kovm.cap_flg(-1))}else l.log("Capture ignore.")}function getDisplayStream(a){if(navigator.mediaDevices&&"getDisplayMedia"in navigator.mediaDevices)return l.log("navigator.mediaDevices.getDisplayMedia"),navigator.mediaDevices.getDisplayMedia(a);l.log("navigator.getDisplayMedia Not Defined");return null}
function gotStream(a){l.log("cap_flg = on");kovm.cap_flg(1);l.log("[OK] Screen Sharing is ready.");screenStream=a;l.dir(localVideo);selfStream||(selfStream=new MediaStream);copyStream||(copyStream=new MediaStream);a=[];var b=0;a=selfStream.getVideoTracks();b=a.length;if(0<b)for(var c=0;c<b;c++)selfStream.removeTrack(a[c]);a=copyStream.getVideoTracks();b=a.length;if(0<b)for(c=0;c<b;c++)a[c].stop(),copyStream.removeTrack(a[c]);0<screenStream.getVideoTracks().length&&(selfStream.addTrack(screenStream.getVideoTracks()[0]),
l.log("selfStream has a videoTrack of screenStream"),copyStream.addTrack(screenStream.getVideoTracks()[0].clone()),l.log("copyStream has a videoTrack of screenStream"));dispMyVideo();screenStream.getVideoTracks()[0].onended=function(){if(-1!==kovm.cap_flg()){l.log("cap_flg = off");kovm.cap_flg(-1);l.log("ended screenStream.");"live"==this.readyState&&this.stop();l.log("finish screen share");if(localStream&&0!==localStream.getVideoTracks().length){for(a in conns)conns[a].vidSender.replaceTrack(localStream.getVideoTracks()[0]);
var a=selfStream.getVideoTracks();var b=a.length;if(0<b)for(c=0;c<b;c++)selfStream.removeTrack(a[c]);a=copyStream.getVideoTracks();b=a.length;if(0<b)for(c=0;c<b;c++)a[c].stop(),copyStream.removeTrack(a[c]);0<localStream.getVideoTracks().length&&(selfStream.addTrack(localStream.getVideoTracks()[0]),l.log("selfStream has a videoTrack of localStream"),copyStream.addTrack(localStream.getVideoTracks()[0].clone()),l.log("copyStream has a videoTrack of localStream"),!1===kovm.video_flg()&&(copyStream.getVideoTracks()[0].enabled=
!1))}else{for(a in conns)conns[a].vidSender.track.enabled=!1;opacityCtrl(localVideo,!1);localStream||kovm.vmsg_lv_flg(!0);a=selfStream.getVideoTracks();b=a.length;if(0<b)for(var c=0;c<b;c++)selfStream.removeTrack(a[c]);a=copyStream.getVideoTracks();b=a.length;if(0<b)for(c=0;c<b;c++)a[c].stop(),copyStream.removeTrack(a[c])}screenStream=screenStream.getVideoTracks()[0].onended=null;sendConfStatus(-1);adjustFrames()}};for(var d in conns)if(0<copyStream.getVideoTracks().length)l.log("add screenStream to ["+
d+"]"),conns[d].vidSender?conns[d].vidSender.replaceTrack(copyStream.getVideoTracks()[0]):(conns[d].vidSender=conns[d].peer.addTrack(copyStream.getVideoTracks()[0],copyStream),sendConfEcho(d));else{l.error("iregular case");screenStream.getVideoTracks()[0].onended();return}localStream&&0!==localStream.getVideoTracks().length||(opacityCtrl(localVideo,!0),localStream||kovm.vmsg_lv_flg(!1));sendConfStatus(-1);adjustFrames()}
function attachMediaStream(a,b){l.log("Call attachMediaStream");a&&(b?(a.srcObject=b,a.play()):delete a.srcObject);return a}var rsz_timer=null,farr=null,scaler="";function AddframeArray(a){if(null==farr)farr=Array(a);else{for(var b=farr.length;b--;)if(farr[b]===a)return;farr.unshift(a)}}function DelframeArray(a){if(null==farr)l.log("No Array, cannot delete: "+a);else for(var b=0;farr.length>b;b++)if(farr[b]===a){scaler===a&&(scaler="");farr.splice(b,1);break}}
function frameResize(a,b,c,d,f){if(farr[a]){var e="#"+farr[a],g=$(e).attr("vid");if(g){var h=g.replace("v","c");"block"===$("#"+h).css("display")&&(g=h,l.log("capture id="+g))}h=d-2;var k=f-2,m=640,p=480,n=document.getElementById(g);null!=n&&0!==n.videoWidth&&0!==n.videoHeight&&null!==n.srcObject?!0!==n.vmute&&(m=n.videoWidth,p=n.videoHeight):l.log(g+":cannot get video size default[640,480]");g=h/m;n=k/p;g<n?k=p*g:h=m*n;b=b+d/2-h/2;c=c+f/2-k/2;d=farr[a]===scaler?1:2;$(e).animate({top:c,left:b,width:h,
height:k,zIndex:d},300);300>h?(b=h/300*VF_FONT_SIZE,document.getElementById(farr[a]).style.fontSize=b+"px"):document.getElementById(farr[a]).style.fontSize=VF_FONT_SIZE+"px"}}function adjustFrames(){null!=rsz_timer&&clearTimeout(rsz_timer);rsz_timer=setTimeout(function(){var a=1+getVideoCountInUse();l.log("adjustFrames count="+a);adjustBodyFontSize();adjustPageBodySize();null!=farr&&(""!=scaler?2>=a?adjustFrames_full():adjustFrames_expand():adjustFrames_uniformly(),rsz_timer=null)},300)}
function adjustFrames_uniformly(){var a=1+getVideoCountInUse();l.log("adjustFrames count="+a);if(a){var b=$("#video-area").innerWidth(),c=$("#video-area").innerHeight();if(0>=b||0>=c)l.log("### cannot get area size vaw="+b+",vah="+c);else{b>=c?(va_l=b,va_s=c):(va_l=c,va_s=b);var d=0,f=0,e=1,g=a;temp_l=g;for(temp_s=e;temp_l>=temp_s;){var h=va_l/temp_l;var k=va_s/temp_s;var m=h<k?h:k;h*=k;if(m>d||m===d&&h>f)d=m,f=h,g=temp_l,e=temp_s;temp_s++;temp_l=Math.ceil(a/temp_s)}l.log(a+":"+g+"\u00d7"+e);for(i=
e;0<i;i--)for(j=g=Math.ceil(a/i);0<j;j--)b>=c?(m=b*(j-1)/g,d=c*(i-1)/e,f=b/g,h=c/e):(m=b*(i-1)/e,d=c*(j-1)/g,f=b/e,h=c/g),l.log(a-1+": ("+m+","+d+","+f+","+h+")"),frameResize(a-1,m,d,f,h),a--}}}
function adjustFrames_expand(){var a=1+getVideoCountInUse();l.log("adjustFrames count="+a);if(!(2>=a)){var b=$("#video-area").innerWidth(),c=$("#video-area").innerHeight();if(0>=b||0>=c)l.log("### cannot get area size vaw="+b+",vah="+c);else for(var d,f,e,g,h=0,k=farr.length;k--;)farr[k]===scaler?(f=d=0,b<c?(e=b,g=.85*c):(e=.85*b,g=c)):(b<c?(d=b/(a-1)*h,f=.85*c,e=b/(a-1),g=c*(1-.85)):(d=.85*b,f=c/(a-1)*h,e=b*(1-.85),g=c/(a-1)),h++),frameResize(k,d,f,e,g)}}
function adjustFrames_full(){var a=1+getVideoCountInUse();l.log("adjustFrames count="+a);if(a&&!(2<a)){a=$("#video-area").innerWidth();var b=$("#video-area").innerHeight();if(0>=a||0>=b)l.log("### cannot get area size vaw="+a+",vah="+b);else for(var c,d,f,e,g=farr.length;g--;)farr[g]===scaler?(d=c=0,f=a,e=b):(c=.85*a,d=.85*b,f=a*(1-.85),e=b*(1-.85)),frameResize(g,c,d,f,e)}}var dragSrcEl=null,dragDstEl=null;
function handleDnD(a,b){if(!isSmartDevice()&&""==scaler)switch(b.type){case "dragstart":l.log("dragstart: "+a.id);a.style.opacity="0.4";dragSrcEl=a;b.originalEvent.dataTransfer.effectAllowed="move";b.originalEvent.dataTransfer.setData("text",a.id);break;case "dragover":b.originalEvent.preventDefault&&b.originalEvent.preventDefault();b.originalEvent.dataTransfer.dropEffect="move";dragSrcEl!==a&&null===dragDstEl&&(a.classList.add("over"),dragDstEl=a);break;case "dragenter":dragSrcEl!==a&&null===dragDstEl&&
(a.classList.add("over"),dragDstEl=a);break;case "dragleave":dragSrcEl!==a&&dragDstEl===a&&(a.classList.remove("over"),dragDstEl=null);break;case "drop":l.log("drop: "+a.id);b.originalEvent.stopPropagation&&b.originalEvent.stopPropagation();if(dragSrcEl!=a){var c=!1,d;for(d in farr)if(farr[d]==dragSrcEl.id){c=!0;break}if(0!=c){b=b.originalEvent.dataTransfer.getData("text");a=a.id;l.log("src:"+b+" <->dst:"+a);for(d=farr.length;0<=d;d--)farr[d]===b?farr[d]=a:farr[d]===a&&(farr[d]=b);adjustFrames()}dragDstEl=
dragSrcEl=null}break;case "dragend":$(".videoFrame").each(function(a,b){b.classList.remove("over")});a.style.opacity="1.0";dragDstEl=dragSrcEl=null;break;default:l.log("#### handDnD undefined"),l.dir(a),l.dir(b)}}
function getConfUrl(a,b){if("undefined"===conf_id)return l.log("Conf URL: ERROR"),null;if(0!=a){var c="https://"+location.hostname;"443"!=a&&(c=c+":"+a)}else c="http://"+location.hostname,void 0!==b&&"80"!=b&&(c=c+":"+b);c=0==prm_room_no?c+"/uc/conf?id="+conf_id:c+"/uc/sconf/"+prm_room_no+"?id="+conf_id;l.log("Conf URL: "+c);return c}function jumpToUCMode(){location.href=location.protocol+"//"+location.host+"/uc/"}
function vqt_change(a){kovm.video_qt(a);l.log("vqt_change->"+kovm.video_qt());sendConfEcho(-1);sendConfStatus(-1);statusIcon(-1,kovm.video_flg(),kovm.audio_flg(),kovm.video_qt())}function showVqtList(){$("#vqt_mask").css("display","block")}function closeVqtList(){$("#vqt_mask").css("display","none")}
function bandwidthCtrl(a,b){l.log("bandwidthCtrl->"+a);b.sdp=b.sdp.replace(/b=AS([^\r\n]+\r\n)/g,"");var c=b.sdp.indexOf("m=audio"),d=b.sdp.indexOf("\r\n",c);c=b.sdp.slice(c,d);d=b.sdp.indexOf("m=video");var f=b.sdp.indexOf("\r\n",d);d=b.sdp.slice(d,f);b.sdp=b.sdp.replace(c,c.concat("\r\nb=AS:50"));b.sdp=0===a?b.sdp.replace(d,d.concat("\r\nb=AS:64")):1===a?b.sdp.replace(d,d.concat("\r\nb=AS:256")):b.sdp.replace(d,d.concat("\r\nb=AS:2500"));return b}
function setVMsg(a,b){if(void 0!=kovm)switch(a){case "rv1":kovm.vmsg_rv1(b);break;case "rv2":kovm.vmsg_rv2(b);break;case "rv3":kovm.vmsg_rv3(b);break;case "rv4":kovm.vmsg_rv4(b);break;case "rv5":kovm.vmsg_rv5(b);break;case "rv6":kovm.vmsg_rv6(b);break;case "rv7":kovm.vmsg_rv7(b);break;case "lv":kovm.vmsg_lv(b)}}
function getVMsg(a){var b="";if(void 0==kovm)return b;switch(a){case "rv1":b=kovm.vmsg_rv1();break;case "rv2":b=kovm.vmsg_rv2();break;case "rv3":b=kovm.vmsg_rv3();break;case "rv4":b=kovm.vmsg_rv4();break;case "rv5":b=kovm.vmsg_rv5();break;case "rv6":b=kovm.vmsg_rv6();break;case "rv7":b=kovm.vmsg_rv7();break;case "lv":b=kovm.vmsg_lv()}return b}function openVideoAlert(a){(a=getVMsg(a))&&openDialog(a,dlgBtnList[D_BTN_CNFIM])}
function setAutoLink(a){return a=a.replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g,"<span class='url_link' onClick=\"window.open('$1')\">$1</span>")};
