"use strict";(function(root,factory){if(typeof define==="function"&&define.amd){define([],factory)}else{var lib=factory.call(root);Object.keys(lib).forEach(function(key){root[key]=lib[key]})}})(this,function(){var topWindow=this;function error(msg){if(topWindow.console){if(topWindow.console.error){topWindow.console.error(msg)}else if(topWindow.console.log){topWindow.console.log(msg)}}}function isInIFrame(w){w=w||topWindow;return w!==w.top}function makeFailHTML(msg){return""+'
"}var GET_A_WEBGL_BROWSER=""+"This page requires a browser that supports WebGL.
"+'Click here to upgrade your browser.';var OTHER_PROBLEM=""+"It doesn't appear your computer can support WebGL.
"+'Click here for more information.';function create3DContext(canvas,opt_attribs){var names=["webgl","experimental-webgl"];var context=null;for(var ii=0;ii1&&uniformInfo.name.substr(-3)==="[0]";if(type===gl.FLOAT&&isArray){return function(v){gl.uniform1fv(location,v)}}if(type===gl.FLOAT){return function(v){gl.uniform1f(location,v)}}if(type===gl.FLOAT_VEC2){return function(v){gl.uniform2fv(location,v)}}if(type===gl.FLOAT_VEC3){return function(v){gl.uniform3fv(location,v)}}if(type===gl.FLOAT_VEC4){return function(v){gl.uniform4fv(location,v)}}if(type===gl.INT&&isArray){return function(v){gl.uniform1iv(location,v)}}if(type===gl.INT){return function(v){gl.uniform1i(location,v)}}if(type===gl.INT_VEC2){return function(v){gl.uniform2iv(location,v)}}if(type===gl.INT_VEC3){return function(v){gl.uniform3iv(location,v)}}if(type===gl.INT_VEC4){return function(v){gl.uniform4iv(location,v)}}if(type===gl.BOOL){return function(v){gl.uniform1iv(location,v)}}if(type===gl.BOOL_VEC2){return function(v){gl.uniform2iv(location,v)}}if(type===gl.BOOL_VEC3){return function(v){gl.uniform3iv(location,v)}}if(type===gl.BOOL_VEC4){return function(v){gl.uniform4iv(location,v)}}if(type===gl.FLOAT_MAT2){return function(v){gl.uniformMatrix2fv(location,false,v)}}if(type===gl.FLOAT_MAT3){return function(v){gl.uniformMatrix3fv(location,false,v)}}if(type===gl.FLOAT_MAT4){return function(v){gl.uniformMatrix4fv(location,false,v)}}if((type===gl.SAMPLER_2D||type===gl.SAMPLER_CUBE)&&isArray){var units=[];for(var ii=0;ii=0&&bounds.left=0;return isVisible&&isFrameVisible(window.parent)}catch(e){return true}}function isOnScreen(element){var isVisible=true;if(element){var bounds=element.getBoundingClientRect();isVisible=bounds.top=0}return isVisible&&isFrameVisible(topWindow)}function augmentTypedArray(typedArray,numComponents){var cursor=0;typedArray.push=function(){for(var ii=0;ii=0){numComponents=2}else if(name.indexOf("color")>=0){numComponents=4}else{numComponents=3}if(length%numComponents>0){throw"can not guess numComponents. You should specify it."}return numComponents}function makeTypedArray(array,name){if(isArrayBuffer(array)){return array}if(Array.isArray(array)){array={data:array}}if(!array.numComponents){array.numComponents=guessNumComponentsFromName(name,array.length)}var type=array.type;if(!type){if(name==="indices"){type=Uint16Array}}var typedArray=createAugmentedTypedArray(array.numComponents,array.data.length/array.numComponents|0,type);typedArray.push(array.data);return typedArray}function createAttribsFromArrays(gl,arrays,opt_mapping){var mapping=opt_mapping||createMapping(arrays);var attribs={};Object.keys(mapping).forEach(function(attribName){var bufferName=mapping[attribName];var array=makeTypedArray(arrays[bufferName],bufferName);attribs[attribName]={buffer:createBufferFromTypedArray(gl,array),numComponents:array.numComponents||guessNumComponentsFromName(bufferName),type:getGLTypeForTypedArray(gl,array),normalize:getNormalizationForTypedArray(array)}});return attribs}function getNumElementsFromNonIndexedArrays(arrays){var key=Object.keys(arrays)[0];var array=arrays[key];if(isArrayBuffer(array)){return array.numElements}else{return array.data.length/array.numComponents}}function createBufferInfoFromArrays(gl,arrays,opt_mapping){var bufferInfo={attribs:createAttribsFromArrays(gl,arrays,opt_mapping)};var indices=arrays.indices;if(indices){indices=makeTypedArray(indices,"indices");bufferInfo.indices=createBufferFromTypedArray(gl,indices,gl.ELEMENT_ARRAY_BUFFER);bufferInfo.numElements=indices.length}else{bufferInfo.numElements=getNumElementsFromNonIndexedArrays(arrays)}return bufferInfo}function createBuffersFromArrays(gl,arrays){var buffers={};Object.keys(arrays).forEach(function(key){var type=key==="indices"?gl.ELEMENT_ARRAY_BUFFER:gl.ARRAY_BUFFER;var array=makeTypedArray(arrays[key],name);buffers[key]=createBufferFromTypedArray(gl,array,type)});if(arrays.indices){buffers.numElements=arrays.indices.length}else if(arrays.position){buffers.numElements=arrays.position.length/3}return buffers}function drawBufferInfo(gl,type,bufferInfo,count,offset){var indices=bufferInfo.indices;var numElements=count===undefined?bufferInfo.numElements:count;offset=offset===undefined?offset:0;if(indices){gl.drawElements(type,numElements,gl.UNSIGNED_SHORT,offset)}else{gl.drawArrays(type,offset,numElements)}}function drawObjectList(gl,objectsToDraw){var lastUsedProgramInfo=null;var lastUsedBufferInfo=null;objectsToDraw.forEach(function(object){var programInfo=object.programInfo;var bufferInfo=object.bufferInfo;var bindBuffers=false;if(programInfo!==lastUsedProgramInfo){lastUsedProgramInfo=programInfo;gl.useProgram(programInfo.program);bindBuffers=true}if(bindBuffers||bufferInfo!==lastUsedBufferInfo){lastUsedBufferInfo=bufferInfo;setBuffersAndAttributes(gl,programInfo.attribSetters,bufferInfo)}setUniforms(programInfo.uniformSetters,object.uniforms);drawBufferInfo(gl,gl.TRIANGLES,bufferInfo)})}return{createAugmentedTypedArray:createAugmentedTypedArray,createAttribsFromArrays:createAttribsFromArrays,createBuffersFromArrays:createBuffersFromArrays,createBufferInfoFromArrays:createBufferInfoFromArrays,createAttributeSetters:createAttributeSetters,createProgram:createProgram,createProgramFromScripts:createProgramFromScripts,createProgramFromSources:createProgramFromSources,createProgramInfo:createProgramInfo,createUniformSetters:createUniformSetters,drawBufferInfo:drawBufferInfo,drawObjectList:drawObjectList,getWebGLContext:getWebGLContext,updateCSSIfInIFrame:updateCSSIfInIFrame,getExtensionWithKnownPrefixes:getExtensionWithKnownPrefixes,resizeCanvasToDisplaySize:resizeCanvasToDisplaySize,setAttributes:setAttributes,setBuffersAndAttributes:setBuffersAndAttributes,setUniforms:setUniforms,setupWebGL:setupWebGL}});function AgoraRender(){var gl=undefined;var program=undefined;var positionLocation=undefined;var texCoordLocation=undefined;var yTexture=undefined;var uTexture=undefined;var vTexture=undefined;var texCoordBuffer=undefined;var surfaceBuffer=undefined;var that={view:undefined,mirrorView:false,container:undefined,canvas:undefined,renderImageCount:0,initWidth:0,initHeight:0,initRotation:0,canvasUpdated:false,clientWidth:0,clientHeight:0};that.start=function(view,onFailure){initCanvas(view,that.mirrorView,view.clientWidth,view.clientHeight,that.initRotation,onFailure)};that.stop=function(){gl=undefined;program=undefined;positionLocation=undefined;texCoordLocation=undefined;deleteTexture(yTexture);deleteTexture(uTexture);deleteTexture(vTexture);yTexture=undefined;uTexture=undefined;vTexture=undefined;deleteBuffer(texCoordBuffer);deleteBuffer(surfaceBuffer);texCoordBuffer=undefined;surfaceBuffer=undefined;if(that.container){that.container.removeChild(that.canvas)}if(that.view){that.view.removeChild(that.container)}that.canvas=undefined;that.container=undefined;that.view=undefined;that.mirrorView=false};that.renderImage=function(image){if(!gl){return}if(image.width!=that.initWidth||image.height!=that.initHeight||image.rotation!=that.initRotation||image.mirror!=that.mirrorView){var view=that.view;that.stop();console.log("init canvas "+image.width+"*"+image.height+" rotation "+image.rotation);initCanvas(view,image.mirror,image.width,image.height,image.rotation,function(e){console.error("init canvas "+image.width+"*"+image.height+" rotation "+image.rotation+" failed. "+e)})}gl.bindBuffer(gl.ARRAY_BUFFER,texCoordBuffer);var xWidth=image.width+image.left+image.right;var xHeight=image.height+image.top+image.bottom;gl.bufferData(gl.ARRAY_BUFFER,new Float32Array([image.left/xWidth,image.bottom/xHeight,1-image.right/xWidth,image.bottom/xHeight,image.left/xWidth,1-image.top/xHeight,image.left/xWidth,1-image.top/xHeight,1-image.right/xWidth,image.bottom/xHeight,1-image.right/xWidth,1-image.top/xHeight]),gl.STATIC_DRAW);gl.enableVertexAttribArray(texCoordLocation);gl.vertexAttribPointer(texCoordLocation,2,gl.FLOAT,false,0,0);uploadYuv(xWidth,xHeight,image.yplane,image.uplane,image.vplane);updateCanvas(image.rotation,image.width,image.height);gl.drawArrays(gl.TRIANGLES,0,6);that.renderImageCount+=1};function uploadYuv(width,height,yplane,uplane,vplane){gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,yTexture);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,width,height,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,yplane);var e=gl.getError();if(e!=gl.NO_ERROR){console.log("upload y plane ",width,height,yplane.byteLength," error",e)}gl.activeTexture(gl.TEXTURE1);gl.bindTexture(gl.TEXTURE_2D,uTexture);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,width/2,height/2,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,uplane);var e=gl.getError();if(e!=gl.NO_ERROR){console.log("upload u plane ",width,height,uplane.byteLength," error",e)}gl.activeTexture(gl.TEXTURE2);gl.bindTexture(gl.TEXTURE_2D,vTexture);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,width/2,height/2,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,vplane);var e=gl.getError();if(e!=gl.NO_ERROR){console.log("upload v plane ",width,height,vplane.byteLength," error",e)}}function deleteBuffer(buffer){if(buffer&&that.gl){that.gl.deleteBuffer(buffer)}}function deleteTexture(texture){if(texture&&that.gl){that.gl.deleteTexture(texture)}}function initCanvas(view,mirror,width,height,rotation,onFailure){that.clientWidth=view.clientWidth;that.clientHeight=view.clientHeight;that.view=view;that.mirrorView=mirror;that.canvasUpdated=false;that.container=document.createElement("div");that.container.style.width="100%";that.container.style.height="100%";that.container.style.display="flex";that.container.style.justifyContent="center";that.container.style.alignItems="center";that.view.appendChild(that.container);that.canvas=document.createElement("canvas");if(rotation==0||rotation==180){that.canvas.width=width;that.canvas.height=height}else{that.canvas.width=height;that.canvas.height=width}that.initWidth=width;that.initHeight=height;that.initRotation=rotation;if(that.mirrorView){that.canvas.style.transform="rotateY(180deg)"}that.container.appendChild(that.canvas);try{gl=that.canvas.getContext("webgl")||that.canvas.getContext("experimental-webgl")}catch(e){console.log(e)}if(!gl){gl=undefined;onFailure({error:"Browser not support! No WebGL detected."});return}gl.clearColor(0,0,0,1);gl.enable(gl.DEPTH_TEST);gl.depthFunc(gl.LEQUAL);gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);program=createProgramFromSources(gl,[AgoraRTC.vertexShaderSource,AgoraRTC.yuvShaderSource]);gl.useProgram(program);initTextures()}function initTextures(){positionLocation=gl.getAttribLocation(program,"a_position");texCoordLocation=gl.getAttribLocation(program,"a_texCoord");surfaceBuffer=gl.createBuffer();texCoordBuffer=gl.createBuffer();gl.activeTexture(gl.TEXTURE0);yTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,yTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.activeTexture(gl.TEXTURE1);uTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,uTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.activeTexture(gl.TEXTURE2);vTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,vTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);var y=gl.getUniformLocation(program,"Ytex");gl.uniform1i(y,0);var u=gl.getUniformLocation(program,"Utex");gl.uniform1i(u,1);var v=gl.getUniformLocation(program,"Vtex");gl.uniform1i(v,2)}function updateCanvas(rotation,width,height){if(that.canvasUpdated){return}that.canvas.style.width="100%";that.canvas.style.height="100%";try{if(rotation===0||rotation===180){if(that.clientWidth/that.clientHeight>width/height){that.canvas.style.width=that.clientHeight*width/height+"px"}else if(that.clientWidth/that.clientHeightwidth/height){that.canvas.style.height=that.clientWidth*width/height+"px"}else if(that.clientHeight/that.clientWidth>>0;var latency=now32-ts;if(latency>that.latency){that.latency=latency}resetImageData()}};that.setVideoProfile=function(profile){that.profile={};if(typeof profile!=="string"&&typeof profile!=="object"){return false}if(profile.hasOwnProperty("profile")){that.profile.profile=profile.profile}if(profile.hasOwnProperty("swapWidthAndHeight")){that.profile.swapWidthAndHeight=profile.swapWidthAndHeight!==false}else{that.profile.swapWidthAndHeight=false}if(typeof profile=="string"){that.profile.profile=profile}if(that.stream){that.stream.postMessage({type:"send",message:{command:"setVideoProfile",profile:that.profile.profile,swapWidthAndHeight:that.profile.swapWidthAndHeight}})}return true};function resetImageData(){header=undefined;yplane=undefined;uplane=undefined;vplane=undefined}function getReso(w,h){return{width:w,height:h}}var supportedVideoList={true:true,unspecified:true,"120p":getReso(160,120),"240p":getReso(320,240),"360p":getReso(640,360),"480p":getReso(640,480),"720p":getReso(1280,720),"1080p":getReso(1920,1080),"4k":getReso(3840,2160)};function onWorkerMessage(e){var data=e.data;switch(data.type){case"init":that.oninit(data);break;case"close":that.onclose(data);break;case"error":that.onerror(data);break;case"message":that.onmessage(data.data);break}}return that};AgoraRTC.createStream=function(spec){return AgoraRTC.Stream(spec)};AgoraRTC.Client=function(spec){"use strict";var that=AgoraRTC.EventDispatcher(spec);that.signal=undefined;that.localStream=undefined;that.remoteStreams={};that.signalOpen=false;that.agentUrl=AgoraRTC.getAgentUrl();function onSignalError(e){if(that.signalOpen){console.log("signal connection lost.");var message={reason:"LOST_CONNECTION_TO_AGENT",type:"error",eventType:e.type,code:e.code};AgoraCall(that.onFailure,message);that.dispatchEvent(message);return}if(e.type==="error"){return}var message={reason:"CLOSE_BEFORE_OPEN",type:"error",eventType:e.type,code:e.code,agentInstallUrl:getInstallUrl(),agentInstallGuideUrl:getInstallGuideUrl()};AgoraCall(that.onFailure,message);that.dispatchEvent(message)}that.init=function(appId,onSuccess,onFailure){spec.appId=appId;that.onFailure=onFailure;if(!that.signal){try{that.signal=AgoraRTC.Signal({url:that.agentUrl,onFailure:onSignalError})}catch(e){console.log("create signal connection failed"+e);AgoraCall(onFailure,e);return}that.signal.on("onopen",function(event){that.signalOpen=true;that.signal.onEvent=function(e){if(e.event==="error"){var name=getErrorCodeName(e.code);if(name){e.reason=name}}else if(e.event==="onUserMuteAudio"){e.event="peer-mute-audio"}else if(e.event==="onUserMuteVideo"){e.event="peer-mute-video"}that.dispatchEvent(AgoraRTC.MediaEvent({type:e.event,msg:e}))};that.getVersion(function(ev){if(ev.version=="1.6.0"||ev.version=="1.6.1"||ev.version=="1.7.0"||ev.version=="1.7.1"||ev.version=="1.7.2"||ev.version=="1.7.3"||ev.version=="1.7.4"||ev.version=="1.8.0"){initialize(onSuccess,onFailure);return}var message={reason:"INCOMPATIBLE_WEBAGENT",type:"error",version:AgoraRTC.version,agentVersion:ev.version,agentInstallUrl:getInstallUrl(),agentInstallGuideUrl:getInstallGuideUrl()};that.dispatchEvent(message)},function(ev){var message={reason:"INCOMPATIBLE_WEBAGENT",type:"error",version:AgoraRTC.version,agentVersion:ev.version,agentInstallUrl:getInstallUrl(),agentInstallGuideUrl:getInstallGuideUrl()};that.dispatchEvent(message)})})}if(that.signalOpen){initialize(onSuccess,onFailure)}function initialize(onSuccess,onFailure){sendSignalCommand({command:"initialize",appId:spec.appId},function(ev){var m=ev.msg;if(m.code!=true){that.signal.close();that.signal=undefined;onError(m.code,"initialize");return}AgoraCall(onSuccess,m)},onFailure)}function onError(code,type){var name=getErrorCodeName(code);if(!name){name="UNKNOWN_ERROR"}notifyError({reason:name,type:"error",eventType:type,code:code});return}function notifyError(e){AgoraCall(onFailure,e);that.dispatchEvent(e)}function getErrorCodeName(code){for(var k in L.ErrorCode){if(L.ErrorCode.hasOwnProperty(k)){if(L.ErrorCode[k]===code){return String(k)}}}return null}that.signal.on("onError",function(ev){var m=ev.msg;onError(m.code,"error")});console.log(that.signal)};that.renewChannelKey=function(channelKey,onSuccess,onFailure){sendSignalCommand({command:"renewChannelKey",channelKey:channelKey},function(ev){var m=ev.msg;if(m.code===true){AgoraCall(onSuccess,m);return}AgoraCall(onFailure,m)},onFailure)};that.join=function(channelKey,channelName,uid,onSuccess,onFailure){if(channelName.length>64){onFailure(L.ErrorCode.INVALID_CHANNEL_NAME);return}sendSignalCommand({command:"joinChannel",channelKey:channelKey,channelName:channelName,uid:uid},function(ev){that.signal.on("onAddVideoStream",onAddVideoStream);that.signal.on("onPeerLeave",onPeerLeave);var m=ev.msg;if(m.code==true){if(!m.uid){m.uid=0}AgoraCall(onSuccess,m.uid);return}if(m.code==L.ErrorCode.JOIN_CHANNEL_REJECTED){console.error("Command joinChannel has been rejected by agent. Is this user joined a channel already?");AgoraCall(onFailure,m.code);return}AgoraCall(onFailure,m.code)},onFailure)};that.leave=function(onSuccess,onFailure){closeLocalRemoteStreams();sendSignalCommand({command:"leaveChannel"},function(ev){var m=ev.msg;if(m.code===true){AgoraCall(onSuccess,m);return}if(m.code==L.ErrorCode.LEAVE_CHANNEL_REJECTED){console.error("Command leaveChannel has been rejected by agent. Is this user not in a channel?");AgoraCall(onSuccess,m);return}AgoraCall(onFailure,{code:m.code})},function(e){console.log("leave channel failed",e)})};that.publish=function(stream,onSuccess,onFailure){that.localStream=stream;sendSignalCommand({command:"unmuteLocal"},function(ev){var m=ev.msg;if(m.code!=true){AgoraCall(onFailure,{code:m.code});return}AgoraCall(onSuccess,m)},onFailure);stream.bindClient(that)};that.unpublish=function(stream,onSuccess,onFailure){sendSignalCommand({command:"muteLocal"},function(ev){var m=ev.msg;if(m.code!=true){AgoraCall(onFailure,{code:m.code});return}AgoraCall(onSuccess,m)},function(e){AgoraCall(onFailure,{error:e})})};that.subscribe=function(stream,onFailure){stream.init(function(){that.dispatchEvent(AgoraRTC.StreamEvent({type:"stream-subscribed",stream:stream}))},function(error){AgoraCall(onFailure,error)})};that.unsubscribe=function(streamID,onFailure){console.log("remote streams",that.remoteStreams);if(that.remoteStreams[streamID]==undefined){AgoraCall(onFailure,{error:"no such stream"});return}that.remoteStreams[streamID].close();delete that.remoteStreams[streamID]};that.enableAudio=function(stream,callback){sendSignalCommand({command:"enableAudio",streamID:stream.getId()},function(ev){var m=ev.msg;if(callback){AgoraCall(callback,m.code===true)}},callback);return true};that.disableAudio=function(stream,callback){sendSignalCommand({command:"disableAudio",streamID:stream.getId()},function(ev){var m=ev.msg;if(callback){AgoraCall(callback,m.code===true)}},callback);return true};that.enableVideo=function(stream,callback){sendSignalCommand({command:"enableVideo",streamID:stream.getId()},function(ev){var m=ev.msg;if(callback){AgoraCall(callback,m.code===true)}},callback);return true};that.disableVideo=function(stream,callback){sendSignalCommand({command:"disableVideo",streamID:stream.getId()},function(ev){var m=ev.msg;if(callback){AgoraCall(callback,m.code===true)}},callback);return true};that.getDevices=function(callback){sendSignalCommand({command:"getDevices"},function(ev){var devices=ev.msg.devices;AgoraCall(callback,devices)},callback);that.signal.on("getDevices")};that.selectDevice=function(device,onFailure){sendSignalCommand({command:"selectDevice",device:device},function(ev){console.log(ev)},onFailure)};that.startRecording=function(recordingKey,onSuccess,onFailure){sendSignalCommand({command:"startRecording",recordingKey:recordingKey},function(ev){var start=ev.msg;if(start.code===true){AgoraCall(onSuccess,start)}else{AgoraCall(onFailure,start)}},onFailure)};that.stopRecording=function(recordingKey,onSuccess,onFailure){sendSignalCommand({command:"stopRecording",recordingKey:recordingKey},function(ev){var stop=ev.msg;if(stop.code===true){AgoraCall(onSuccess,stop)}else{AgoraCall(onFailure,stop)}},onFailure)};that.queryRecordingStatus=function(onStatus){sendSignalCommand({command:"queryRecordingStatus"},function(ev){onStatus(ev.msg)},onStatus)};that.close=function(){closeLocalRemoteStreams();if(that.signal){that.signal.close();that.signal=undefined}};that.getVersion=function(onSuccess,onFailure){sendSignalCommand({command:"getVersion"},function(ev){var m=ev.msg;if(m.code===true){AgoraCall(onSuccess,m)}else{AgoraCall(onFailure,m)}},onFailure)};that.setParameters=function(parameters){sendSignalCommand({command:"setParameters",parameters:JSON.stringify(parameters)})};that.setEncryptionMode=function(encryptionMode){sendSignalCommand({command:"setEncryptionMode",mode:encryptionMode})};that.setEncryptionSecret=function(secret){sendSignalCommand({command:"setEncryptionSecret",secret:secret})};that.getWindows=function(callback){sendSignalCommand({command:"getWindows"},function(ev){var windows=ev.msg.windows;AgoraCall(callback,windows)},callback)};that.startScreenSharing=function(window,onSuccess,onFailure){sendSignalCommand({command:"startScreenSharing",window:window},onSuccess,onFailure)};that.setScreenSharingWindow=function(window,onSuccess,onFailure){sendSignalCommand({command:"setScreenSharingWindow",window:window},onSuccess,onFailure)};that.stopScreenSharing=function(onSuccess,onFailure){sendSignalCommand({command:"stopScreenSharing"},onSuccess,onFailure)};that.setChannelProfile=function(profile,onSuccess,onFailure){sendSignalCommand({command:"setChannelProfile",profile:profile},onSuccess,onFailure)};that.setClientRole=function(role,permissionKey,onSuccess,onFailure){if(!permissionKey){permissionKey=""}sendSignalCommand({command:"setClientRole",role:role,key:permissionKey},onSuccess,onFailure)};that.enableDualStreamMode=function(enabled,onSuccess,onFailure){sendSignalCommand({command:"enableDualStreamMode",enabled:enabled},onSuccess,onFailure)};function sendSignalCommand(message,onSuccess,onFailure){that.signal.on(message.command,function(e){AgoraCall(onSuccess,e);console.log(e)});that.signal.sendMessage(message,function(e){console.log(e);e.reason="CONNECTION_TO_AGENT_ERROR";AgoraCall(onFailure,e)})}function onPeerLeave(ev){var m=ev.msg;if(that.remoteStreams.hasOwnProperty(m.uid)){that.remoteStreams[m.uid].close();delete that.remoteStreams[m.uid];console.log("remote streams after peer leave ",that.remoteStreams)}that.dispatchEvent(AgoraRTC.ClientEvent({type:"peer-leave",uid:m.uid}))}function onAddVideoStream(ev){var m=ev.msg;if(!that.remoteStreams.hasOwnProperty(m.uid)){var stream=AgoraRTC.Stream({streamID:m.uid,local:false,audio:m.audio,video:m.video,screen:m.screen});stream.bindClient(that);that.remoteStreams[m.uid]=stream}that.dispatchEvent(AgoraRTC.StreamEvent({type:"stream-added",stream:that.remoteStreams[m.uid]}));console.log("remote streams",that.remoteStreams)}function getInstallUrl(){if(navigator.appVersion.indexOf("Mac")!=-1){return AgoraRTC.macAgentInstallUrl}return AgoraRTC.winAgentInstallUrl}function getInstallGuideUrl(){var userLang=navigator.language||navigator.userLanguage;if(userLang.indexOf("zh")!=-1){return AgoraRTC.cnAgentInstallGuideUrl}return AgoraRTC.enAgentInstallGuideUrl}function closeLocalRemoteStreams(){if(that.localStream){that.localStream.close()}that.localStream=undefined;for(var streamId in that.remoteStreams){if(that.remoteStreams.hasOwnProperty(streamId)){that.remoteStreams[streamId].close();delete that.remoteStreams[streamId]}}}return that};AgoraRTC.createRtcClient=function(){return AgoraRTC.Client({})};AgoraRTC.createLiveClient=function(){return AgoraRTC.Client({})};
//# sourceMappingURL=dist/AgoraRtcAgentSDK.min.js.map