<!doctypehtml><html lang=ar style=height:100%><title>{{{title}}} - Messenger</title><meta http-equiv=X-UA-Compatible content="IE=edge"><meta content="text/html;charset=utf-8"http-equiv=Content-Type><meta name=viewport content="user-scalable=1,initial-scale=1,minimum-scale=1,maximum-scale=1"><meta name=format-detection content="telephone=no"><meta name=robots content=noindex,nofollow><link type=text/css href=styles/style.css media=screen rel=stylesheet title=CSS><link type=text/css href=styles/messenger.css media=screen rel=stylesheet title=CSS><body style=font-family:Arial,Helvetica,sans-serif>{{{customCSSTags}}}<link rel=apple-touch-icon href=/favicon-303x303.png><script src=scripts/common-0.0.1{{min}}.js></script><script src=scripts/filesaver.min.js></script>{{{customJSTags}}}<div id=xtop style="position:absolute;left:0;right:0;top:0;height:38px;background-color:#036;color:#eee;box-shadow:3px 3px 10px gray"><img style=float:left height=38 src=messenger.png><div style=position:absolute;background-color:#036;right:0;height:38px><div id=saveButton class="icon15 topButton"style=margin-right:4px title="Save conversation"onclick=saveChatSession()></div><div id=notifyButton class="icon13 topButton"style=display:none title="Enable browser notification"onclick=enableNotificationsButtonClick()></div><div id=fileButton class="icon4 topButton"title="Share a file"style=display:none onclick=fileButtonClick()></div><div id=camButton class="icon2 topButton"title="Activate camera &amp; microphone"style=display:none onclick=camButtonClick()></div><div id=micButton class="icon6 topButton"title="Activate microphone"style=display:none onclick=micButtonClick()></div><div id=hangupButton class="icon11 topRedButton"title="Hang up"style=display:none onclick=hangUpButtonClick(1)></div><div id=recordIcon class=deskareaicon title="Server is recording this session"style=background-color:red;margin:6px;margin-top:7px;border-radius:12px;height:24px;width:24px;float:right;display:none></div></div><div style=padding-top:9px;padding-left:6px;font-size:20px;display:inline-block><b><span id=xtitle></span></b></div></div><div id=xmiddle style=position:absolute;left:0;right:0;top:38px;bottom:36px;font-size:18px><div id=xmsgparent style=position:absolute;left:0;right:0;bottom:0;max-height:100%;overflow-y:auto><div id=xmsg style=padding:5px></div><div id=typingIndicator style=display:none;margin-left:5px;clear:both><img src=images/3dots-24.gif srcset="images/3dots-48.gif 2x"></div></div></div><div id=xbottom style=position:absolute;left:0;right:0;bottom:0;height:36px;background-color:#036;font-size:18px><table style=width:100%><tr><td><input id=xouttext style=box-sizing:border-box;width:100%;font-size:18px onfocus=onUserInputFocus(1) onblur=onUserInputFocus(0) onkeyup=updateLocalOutText()><td style=width:1px><input type=button id=sendButton value=Send style=box-sizing:border-box;float:right;font-size:18px onclick=xsend(event)><td style=width:1px><input type=button id=clearButton value=Clear style=box-sizing:border-box;float:right;font-size:18px onclick=displayClear()></table></div><div id=remoteVideo style="position:absolute;right:24px;top:45px;width:320px;height:calc(240px + 30px);background-color:gray;border-radius:12px 12px 12px 12px;box-shadow:3px 3px 10px gray;display:none"><div style=position:absolute;right:0;left:0;top:2.5px;text-align:center>Remote</div><video id=remoteVideoCanvas autoplay style="position:absolute;top:20px;left:0;width:100%;height:calc(100% - 30px);background-color:#000"onclick=remotePlay(event)></video><div id=remoteClickToView style="position:absolute;top:20px;left:0;width:100%;height:calc(100% - 30px);color:#fff;text-align:center;padding-top:20px;display:none"onclick=remotePlay(event)>Click here to view.</div></div><div id=localVideo style="position:absolute;right:24px;top:320px;width:160px;height:calc(120px + 30px);background-color:gray;border-radius:12px 12px 12px 12px;box-shadow:3px 3px 10px gray;display:none"><div style=position:absolute;right:0;left:0;top:2.5px;text-align:center>Local</div><video id=localVideoCanvas autoplay muted style="position:absolute;top:20px;left:0;right:100%;height:calc(100% - 30px);background-color:#000"></video></div><canvas width=256 height=256 id=remoteImage style="position:absolute;right:24px;top:45px;width:200px;height:200px;background-color:gray;border-radius:12px 12px 12px 12px;box-shadow:3px 3px 10px gray;display:none"><input id=uploadFileInput type=file multiple style=display:none><script onunload=onUnLoad()>var random="{{{randomlength}}}",userInputFocus=0,socket=null,state=0,args=XparseUriArgs();args.key&&0==isAlphaNumeric(args.key)&&delete args.key,args.locale&&0==isAlphaNumeric(args.locale)&&delete args.locale;var pushMessaging=1==args.pmt,webrtcSessions=(random=Math.random(),{}),webchannel=null,localStream=null,remoteStream=null,multiWebRtc=!0,userMediaSupport=0,notification=null;getUserMediaSupport(function(e){userMediaSupport=e});var meshMessengerTitle="{{{meshMessengerTitle}}}",meshMessengerImage="{{{meshMessengerImage}}}",remoteUserName="{{{username}}}",remoteUserId="{{{userid}}}",webrtcconfiguration="{{{webrtcconfig}}}";if(""==webrtcconfiguration)webrtcconfiguration=null;else try{webrtcconfiguration=JSON.parse(decodeURIComponent(webrtcconfiguration))}catch(e){console.log('Invalid WebRTC config: "'+webrtcconfiguration+'".'),webrtcconfiguration=null}var chatTextSession=(new Date).toString()+"\r\n",localOutText=!1,remoteOutText=!1,remoteImage=!1,serverRecording=!1,notificationSupport=!0,fileUploads=[],fileDownloads={},currentFileUpload=null,currentFileDownload=null;function resizeVideos(){var e=0;null!=remoteStream?(e=320*Q("remoteVideoCanvas").videoHeight/Q("remoteVideoCanvas").videoWidth,QS("remoteVideo").height="calc("+e+"px + 30px)"):1==remoteImage&&(e+=200),null!=localStream&&(QS("localVideo").height="calc("+160*Q("localVideoCanvas").videoHeight/Q("localVideoCanvas").videoWidth+"px + 30px)",QS("localVideo").top=e+50+(null!=remoteStream?30:0)+"px")}setInterval(resizeVideos,1e3);var newTitle="";args.title?(newTitle=decodeURIComponent(args.title),document.title=document.title+" - "+decodeURIComponent(args.title)):newTitle="!"==meshMessengerTitle?"MeshMessenger":decodeURIComponent(meshMessengerTitle),newTitle=newTitle.split("{0}").join(decodeURIComponent(remoteUserName)).split("{1}").join(decodeURIComponent(remoteUserId)),QH("xtitle",EscapeHtml(newTitle).split(" ").join("&nbsp"));try{Notification&&QV("notifyButton","granted"!=Notification.permission)}catch(e){notificationSupport=!1}function onUserInputFocus(e){userInputFocus=e}function displayClear(){chatTextSession=(new Date).toString()+"\r\n",QH("xmsg",""),cancelAllFileTransfers(),fileUploads=[],fileDownloads={}}function getUserMediaSupport(e){try{navigator.mediaDevices.enumerateDevices().then(function(t){try{var n=0,i=0;t.forEach(function(e){"audioinput"===e.kind&&(n=1),"videoinput"===e.kind&&(i=1)}),0==n&&e(0),e(n+i)}catch(e){}})}catch(e){}}function displayControl(e){chatTextSession+=(new Date).toLocaleTimeString()+" - Control> "+e+"\r\n",QA("xmsg",'<div style="clear:both"><div style="color:gray;float:left;margin-bottom:2px">'+EscapeHtml(e)+"</div><div></div></div>"),Q("xmsgparent").scrollTop=Q("xmsgparent").scrollHeight}function displayLocalVideo(e){QV("localVideo",e),adjustVideoWindows()}function displayRemoteVideo(e){QV("remoteVideo",e),adjustVideoWindows()}function adjustVideoWindows(){QS("localVideo").display;var e="none"!=QS("remoteVideo").display;QV("remoteImage",1==remoteImage&&0==e),QS("localVideo").top=e||remoteImage?"320px":"45px",resizeVideos()}function displayRemote(e){chatTextSession+=(new Date).toLocaleTimeString()+" - Remote> "+e+"\r\n",QA("xmsg",'<div style="clear:both"><div class="remoteBubble">'+EscapeHtml(e)+"</div><div></div></div>"),Q("xmsgparent").scrollTop=Q("xmsgparent").scrollHeight,notificationSupport&&(Notification&&QV("notifyButton","granted"!=Notification.permission),Notification&&"hidden"===document.visibilityState&&"granted"==Notification.permission&&(null!=notification&&(notification.close(),notification=null),(notification=new Notification(Q("xtitle").innerHTML.split("&nbsp;").join(" "),{body:e})).onclick=function(e){e.preventDefault(),"hidden"===document.visibilityState&&window.focus(),notification.close()}))}function xsend(e){notificationSupport&&(null!=notification&&(notification.close(),notification=null),Notification&&QV("notifyButton","granted"!=Notification.permission));var t=Q("xouttext").value;t.length>0&&(chatTextSession+=(new Date).toLocaleTimeString()+" - Local> "+t+"\r\n",QA("xmsg",'<div style="clear:both"><div class="localBubble">'+EscapeHtml(t)+"</div><div></div></div>"),Q("xmsgparent").scrollTop=Q("xmsgparent").scrollHeight,(2==state||pushMessaging)&&send({action:"chat",msg:t}),Q("xouttext").value="",Q("xouttext").focus(),localOutText=!1)}function haltEvent(e){return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1}function updateControls(){QE("sendButton",2==state||pushMessaging),QE("clearButton",2==state||pushMessaging),QE("xouttext",2==state||pushMessaging),QV("fileButton",2==state),QV("camButton",webchannel&&webchannel.ok&&!localStream&&2==userMediaSupport),QV("micButton",webchannel&&webchannel.ok&&!localStream&&userMediaSupport>0),QV("hangupButton",webchannel&&webchannel.ok&&localStream),updateLocalOutText()}function startWebRTC(e,t){if(null!=webrtcSessions[0]&&0==multiWebRtc)return webrtcSessions[0];var n=null;return"undefined"!=typeof RTCPeerConnection?n=new RTCPeerConnection(webrtcconfiguration):"undefined"!=typeof webkitRTCPeerConnection&&(n=new webkitRTCPeerConnection(webrtcconfiguration)),null==n?null:(n.id=e,n.onicecandidate=function(e){try{null!=e.candidate&&sendws({action:"webRtcIce",ice:e.candidate,id:this.id})}catch(e){}},n.oniceconnectionstatechange=function(){n&&"failed"==n.iceConnectionState&&(n.close(),webrtcSessions[n.id]&&delete webrtcSessions[n.id])},n.ondatachannel=function(e){(webchannel=e.channel).onmessage=function(e){processMessage(e.data,2)},webchannel.onopen=function(){webchannel.ok=!0,updateControls(),0==serverRecording&&sendws({action:"rtcSwitch",v:0})},webchannel.onclose=function(e){webchannel&&webchannel.ok?disconnect():hangUpButtonClick(0)}},n.onnegotiationneeded=function(t){null==n.holdTimer&&(n.holdTimer=setTimeout(function(){n.holdTimer=null,n.createOffer(function(t){n.setLocalDescription(t,function(){sendws({action:"webRtcSdp",sdp:t,id:e})},function(){hangUpButtonClick(e)})},function(){hangUpButtonClick(e)})},20))},n.ontrack=function(e){QV("remoteClickToView",!1);var t=Q("remoteVideoCanvas");t.srcObject=remoteStream=e.streams[0],t.onloadedmetadata=function(e){var n=t.play();void 0!==n&&n.then(function(){}).catch(function(e){QV("remoteClickToView",!0)})},displayRemoteVideo(!0)},1==t&&((webchannel=n.createDataChannel("DataChannel",{})).onmessage=function(e){processMessage(e.data,2)},webchannel.onopen=function(){webchannel.ok=!0,updateControls(),0==serverRecording&&sendws({action:"rtcSwitch",v:0})},webchannel.onclose=function(e){webchannel&&webchannel.ok?disconnect():hangUpButtonClick(0)}),webrtcSessions[e]=n,n)}function remotePlay(){QV("remoteClickToView",!1),Q("remoteVideoCanvas").play()}function webRtcHandleOffer(e,t){var n=webrtcSessions[e];n&&n.setRemoteDescription(new RTCSessionDescription(t),function(){"offer"==t.type&&n.createAnswer(function(t){n.setLocalDescription(t,function(n,i){try{sendws({action:"webRtcSdp",sdp:t,id:e})}catch(e){}},function(){hangUpButtonClick(e)})},function(){hangUpButtonClick(e)})},function(){hangUpButtonClick(e)})}function performWebRtcSwitch(){!serverRecording&&webchannel&&webchannel.ok&&(sendws({action:"rtcSwitch",v:1}),webchannel.xoutBuffer=[])}function disconnect(){serverRecording=!1,QV("recordIcon",!1),state>0&&displayControl("Connection closed."),state>1&&setTimeout(start,500),cancelAllFileTransfers(),hangUpButtonClick(0,!0),hangUpButtonClick(1,!0),hangUpButtonClick(2,!0),null!=socket&&(socket.close(),socket=null),updateControls(),state=0,remoteImage=!1,QV("remoteImage",!1),updateLocalOutText(),updateRemoteOutText()}function send(e){if(2==state||0!=pushMessaging)if("object"==typeof e&&(e=JSON.stringify(e)),!serverRecording&&webchannel&&webchannel.ok)null!=webchannel.xoutBuffer?webchannel.xoutBuffer.push(e):webchannel.send(e);else if(null!=socket)try{socket.send(e)}catch(e){}}function sendws(e){2==state&&("object"==typeof e&&(e=JSON.stringify(e)),null!=socket&&socket.send(e))}function webRtcIdSwitch(e){return 0==e?0:3-e}function drawRemoteImage(e){var t=Q("remoteImage"),n=t.getContext("2d"),i=new Image;i.onload=function(){n.drawImage(this,0,0,t.width,t.height),remoteImage=!0,adjustVideoWindows()},i.src=e}function processMessage(e,t){if("string"==typeof e){try{e=JSON.parse(e)}catch(t){return void console.log("Unable to parse",e)}if("102938"==e.ctrlChannel){switch(e.type){case"image":drawRemoteImage(e.image);break;case"ping":send({ctrlChannel:"102938",type:"pong"})}return}switch(e.action){case"chat":displayRemote(e.msg),updateRemoteOutText(!1);break;case"outtext":updateRemoteOutText(e.value);break;case"ctrl":1==e.value?displayControl("Sent as push notification."):2==e.value&&displayControl("Push notification failed."),null!=e.msg&&displayControl(msg);break;case"random":random>e.random&&startWebRTC(0,!0);break;case"webRtcSdp":webrtcSessions[webRtcIdSwitch(e.id)]||startWebRTC(webRtcIdSwitch(e.id),!1),webRtcHandleOffer(webRtcIdSwitch(e.id),e.sdp);break;case"webRtcIce":var n=webrtcSessions[webRtcIdSwitch(e.id)];if(n)try{n.addIceCandidate(new RTCIceCandidate(e.ice))}catch(e){}break;case"videoStop":hangUpButtonClick(webRtcIdSwitch(e.id),!0);break;case"rtcSwitch":switch(e.v){case 0:performWebRtcSwitch();break;case 1:sendws({action:"rtcSwitch",v:2});break;case 2:for(var i in webchannel.xoutBuffer)webchannel.send(webchannel.xoutBuffer[i]);delete webchannel.xoutBuffer;break;default:console.log("Unknown rtcSwitch value: "+e.action)}break;case"file":startFileDownload(e);break;case"fileUploadCancel":cancelFileTransfer(e.id);break;case"fileUploadStart":fileDownloads[e.id]&&((currentFileDownload=fileDownloads[e.id]).data="",changeFileInfo(e.id,2,0),continueFileDownload(e),send({action:"fileUploadAck",id:e.id}));break;case"fileUploadEnd":currentFileDownload&&currentFileDownload.id==e.id&&(changeFileInfo(e.id,3,200),currentFileDownload.done=1,currentFileDownload=null,send({action:"fileUploadAck",id:e.id})),currentFileDownload=null;break;case"fileUploadAck":continueFileUpload();break;case"fileData":currentFileDownload&&currentFileDownload.id==e.id&&(currentFileDownload.data+=e.data,changeFileInfo(e.id,2,200*currentFileDownload.data.length/currentFileDownload.size),send({action:"fileUploadAck",id:e.id}));break;default:console.log("Unhandled object data",e)}}else console.log("Unhandled data",typeof e,e)}function fileButtonClick(){var e=Q("uploadFileInput");1!=e.getAttribute("eventset")&&(e.setAttribute("eventset","1"),e.addEventListener("change",fileSelect,!1)),e.value=null,e.click()}function fileSelect(){if(2==state){var e=Q("uploadFileInput");if(e.files.length>10)displayControl("Limit of 10 file uploads at the same time.");else for(var t=0;t<e.files.length;t++)if(e.files[t].size>0){var n=new FileReader;n.onload=function(e){this.xfile.data=e.target.result,startFileUpload(this.xfile)},n.xfile=e.files[t],n.readAsBinaryString(e.files[t])}}}function fileDrop(e){if(haltEvent(e),2==state&&null!=e.dataTransfer)if(e.dataTransfer.files.length>10)displayControl("Limit of 10 file uploads at the same time.");else for(var t=0;t<e.dataTransfer.files.length;t++)if(e.dataTransfer.files[t].size>0){var n=new FileReader;n.onload=function(e){this.xfile.data=e.target.result,startFileUpload(this.xfile)},n.xfile=e.dataTransfer.files[t],n.readAsBinaryString(e.dataTransfer.files[t])}}function startFileUpload(e){2==state&&(e.id=Math.random(),fileUploads.push(e),chatTextSession+=(new Date).toLocaleTimeString()+" - Upload> "+e.name+" ("+e.size+" bytes)\r\n",QA("xmsg",'<div style="clear:both"></div><div id="FILEUP-'+e.id+'" class="localBubble" style="font-size:14px;width:240px;cursor:pointer" onclick="cancelFileTransfer(\''+e.id+'\')"><div id="FILEUP-ICON-'+e.id+'" class="fileicon" style="float:left;width:32px;height:32px"></div><div><div id="FILEUP-NAME-'+e.id+'" style="height:20px;overflow:hidden;white-space:nowrap;" title="'+e.name+'">'+e.name+'</div><div style="width:200px;background-color:lightgray;margin-left:32px;border-radius:3px;margin-top:3px;height:11px"><div id="FILEUP-PROGRESS-'+e.id+'" style="width:0px;background-color:green;border-radius:3px;height:11px">&nbsp;</div></div></div></div>'),Q("xmsgparent").scrollTop=Q("xmsgparent").scrollHeight,send({action:"file",size:e.size,id:e.id,type:e.type,name:e.name}),null==currentFileUpload&&continueFileUpload())}function startFileDownload(e){2==state&&(fileDownloads[e.id]=e,chatTextSession+=(new Date).toLocaleTimeString()+" - Download> "+e.name+" ("+e.size+" bytes)\r\n",QA("xmsg",'<div style="clear:both"></div><div id="FILEUP-'+e.id+'" class="remoteBubble" style="font-size:14px;width:240px;cursor:pointer" onclick="saveFileTransfer(\''+e.id+'\')"><div id="FILEUP-ICON-'+e.id+'" class="fileicon" style="float:left;width:32px;height:32px"></div><div><div id="FILEUP-NAME-'+e.id+'" style="height:20px;overflow:hidden;white-space:nowrap;" title="'+e.name+'">'+e.name+'</div><div style="width:200px;background-color:lightgray;margin-left:32px;border-radius:3px;margin-top:3px;height:11px"><div id="FILEUP-PROGRESS-'+e.id+'" style="width:0px;background-color:green;border-radius:3px;height:11px">&nbsp;</div></div></div></div>'),Q("xmsgparent").scrollTop=Q("xmsgparent").scrollHeight)}function changeFileInfo(e,t,n,i){t&&(Q("FILEUP-ICON-"+e).classList.remove("fileicon"),Q("FILEUP-ICON-"+e).classList.remove("fileiconx"),Q("FILEUP-ICON-"+e).classList.remove("fileicontransfer"),Q("FILEUP-ICON-"+e).classList.remove("fileicondone"),Q("FILEUP-ICON-"+e).classList.add(["fileicon","fileiconx","fileicontransfer","fileicondone"][t])),n&&(QS("FILEUP-PROGRESS-"+e).width=n+"px"),i&&(QS("FILEUP-PROGRESS-"+e)["background-color"]=i)}function data2blob(e){for(var t=new Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return new Blob([new Uint8Array(t)])}function saveFileTransfer(e){var t=fileDownloads[e];t&&1==t.done&&saveAs(data2blob(t.data),t.name)}function cancelFileTransfer(e){null!=currentFileUpload&&currentFileUpload.id==e&&(currentFileUpload=null),null!=currentFileDownload&&currentFileDownload.id==e&&(currentFileDownload=null);var t=!1;if(fileDownloads[e]&&1!=fileDownloads[e].done)delete fileDownloads[e],t=!0;else for(var n in fileUploads)if(fileUploads[n].id==e){send({action:"fileUploadCancel",id:e}),fileUploads.splice(n,1),t=!0;break}t&&changeFileInfo(e,1,200,"gray")}function cancelAllFileTransfers(){for(var e in fileDownloads)cancelFileTransfer(fileDownloads[e].id);for(var e in fileUploads)cancelFileTransfer(fileUploads[e].id)}function continueFileUpload(){if(null==currentFileUpload){if(0==fileUploads.length)return;(currentFileUpload=fileUploads[0]).ptr=0,send({action:"fileUploadStart",size:currentFileUpload.size,id:currentFileUpload.id,type:currentFileUpload.type,name:currentFileUpload.name})}else if(currentFileUpload.size<=currentFileUpload.ptr)send({action:"fileUploadEnd",size:currentFileUpload.size,id:currentFileUpload.id,type:currentFileUpload.type,name:currentFileUpload.name}),changeFileInfo(currentFileUpload.id,3,200),fileUploads.splice(0,1),currentFileUpload=null,continueFileUpload();else{var e=Math.min(4e3,currentFileUpload.data.length-currentFileUpload.ptr),t=currentFileUpload.data.substring(currentFileUpload.ptr,currentFileUpload.ptr+e);send({action:"fileData",id:currentFileUpload.id,data:t}),currentFileUpload.ptr+=e,changeFileInfo(currentFileUpload.id,0,200*currentFileUpload.ptr/currentFileUpload.size)}}function continueFileDownload(e){send({action:"fileUploadAck",id:e.id})}function enableNotificationsButtonClick(){return notificationSupport&&Notification&&Notification.requestPermission().then(function(e){QV("notifyButton","granted"!=e)}),!1}function camButtonClick(){null==localStream&&startLocalStream({video:!0,audio:!0})}function micButtonClick(){null==localStream&&startLocalStream({video:!1,audio:!0})}function hangUpButtonClick(e,t){var n=Q("localVideoCanvas"),i=Q("remoteVideoCanvas"),o=webrtcSessions[1==multiWebRtc?e:0];if(0==e&&null!=webchannel){try{webchannel.close()}catch(e){}webchannel=null}if(o){if(1!=multiWebRtc&&0!=e||(o.ontrack=null,o.onremovetrack=null,o.onremovestream=null,o.onnicecandidate=null,o.oniceconnectionstatechange=null,o.onsignalingstatechange=null,o.onicegatheringstatechange=null,o.onnotificationneeded=null),1==e&&localStream){var a=localStream.getTracks();for(var l in a)a[l].stop();localStream=null}if(2==e&&remoteStream){a=remoteStream.getTracks();for(var l in a)a[l].stop();remoteStream=null}1!=multiWebRtc&&0!=e||(o.close(),delete webrtcSessions[e])}1==e?(n.removeAttribute("src"),n.removeAttribute("srcObject"),null!=localStream&&(localStream=null),displayLocalVideo(!1)):2==e&&(i.removeAttribute("src"),i.removeAttribute("srcObject"),displayRemoteVideo(!1)),1!=t&&send({action:"videoStop",id:e}),updateControls()}function startLocalStream(e){var t=1==multiWebRtc?1:0;null==localStream&&(1==multiWebRtc&&null!=webrtcSessions[1]||navigator.mediaDevices.getUserMedia&&(localStream=1,updateControls(),navigator.mediaDevices.getUserMedia(e).then(function(n){var i=(localStream=n).getTracks(),o=startWebRTC(t);if(1==e.video){var a=Q("localVideoCanvas");a.srcObject=n,a.onloadedmetadata=function(e){a.play()},displayLocalVideo(!0)}for(var l in i)o.addTrack(i[l],localStream)},function(e){displayControl(e.message+"."),hangUpButtonClick(1)})))}function start(){if(updateControls(),"string"==typeof args.id&&args.id.length>0){var e=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/meshrelay.ashx?id="+args.id;null!=args.auth&&""!=args.auth&&(e+="&auth="+args.auth),(socket=new WebSocket(e)).onopen=function(){state=1,displayControl("Waiting for other user...")},socket.onerror=function(e){},socket.onclose=function(){disconnect()},socket.onmessage=function(e){if(state<2&&"string"==typeof e.data&&("c"==e.data||"cr"==e.data))return serverRecording="cr"==e.data,QV("recordIcon",serverRecording),hangUpButtonClick(0,!0),hangUpButtonClick(1,!0),hangUpButtonClick(2,!0),displayControl("Connected."),state=2,updateControls(),sendws({action:"random",random:random}),updateLocalOutText(),void updateRemoteOutText();"{"==e.data[0]&&processMessage(e.data,1)}}else displayControl("Error: No connection key specified.")}function saveChatSession(){saveAs(data2blob(chatTextSession),"ChatSession")}function onUnLoad(){for(var e=0;e<3;e++)if(webrtcSessions[e])try{webrtcSessions[e].close(),delete webrtcSessions[e]}catch(e){}if(null!=webchannel){try{webchannel.close()}catch(e){}webchannel=null}if(null!=socket){try{socket.close()}catch(e){}socket=null}}function isSafeString3(e){return"string"==typeof e&&-1==e.indexOf("<")&&-1==e.indexOf(">")&&-1==e.indexOf("&")&&-1==e.indexOf('"')&&-1==e.indexOf("'")&&-1==e.indexOf("+")&&-1==e.indexOf("(")&&-1==e.indexOf(")")&&-1==e.indexOf("#")&&-1==e.indexOf(":")}function XparseUriArgs(){var e=window.document.location.href;e.endsWith("#")&&(e=e.substring(0,e.length-1));var t,n={},i=e.split(/[\?&|]/);for(var o in i.splice(0,1),i){var a=i[o],l=a.indexOf("=");if(n[t=a.substring(0,l)]=a.substring(l+1),isSafeString3(n[t])){var r=parseInt(n[t]);r==n[t]&&(n[t]=r)}else delete n[t]}return n}function updateLocalOutText(){var e=Q("xouttext").value;2==state&&""!=e||1!=localOutText?2==state&&""!=e&&0==localOutText&&(localOutText=!0,send({action:"outtext",value:!0})):(localOutText=!1,send({action:"outtext",value:!1}))}function updateRemoteOutText(e){2!=state&&(e=!1),remoteOutText!=e&&(remoteOutText=e,QV("typingIndicator",remoteOutText))}document.addEventListener("dragover",haltEvent,!1),document.addEventListener("dragleave",haltEvent,!1),document.addEventListener("drop",fileDrop,!1),document.onclick=function(e){notificationSupport&&(Notification&&QV("notifyButton","granted"!=Notification.permission),null!=notification&&(notification.close(),notification=null))},document.onkeyup=function(e){if(notificationSupport&&(Notification&&QV("notifyButton","granted"!=Notification.permission),null!=notification&&(notification.close(),notification=null)),2==state&&8==e.keyCode&&0==userInputFocus){var t=Q("xouttext").value;t.length>0&&(Q("xouttext").value=t.substring(0,t.length-1)),updateLocalOutText()}if(0==userInputFocus)return haltEvent(e),!1},document.onkeypress=function(e){if(notificationSupport&&(Notification&&QV("notifyButton","granted"!=Notification.permission),null!=notification&&(notification.close(),notification=null)),(2==state||pushMessaging)&&(13==e.keyCode?xsend(e):0==userInputFocus&&1==e.key.length&&(Q("xouttext").value=Q("xouttext").value+e.key,updateLocalOutText())),0==userInputFocus)return haltEvent(e),!1},FileReader.prototype.readAsBinaryString||(FileReader.prototype.readAsBinaryString=function(e){var t="",n=this,i=new FileReader;i.onload=function(e){for(var o=new Uint8Array(i.result),a=0;a<o.byteLength;a++)t+=String.fromCharCode(o[a]);n.onload({target:{result:t}})},i.readAsArrayBuffer(e)}),start()</script></canvas>