text: 'use strict';var ko={TAB:0,dD:1,DQ:2},lo=function(a){Jg("MediaRouter.CastStreaming.Start.Success",a,ko)};var mo=x("mr.mirror.cast.LogUploader"),oo=function(a,b,c){no("raw_events.log.gz",a,b,c);return b?"https://crash.corp.google.com/samples?stbtiq="+b:""},no=function(a,b,c,e){if(0==b.size)mo.info("Trying to upload an empty file to Crash"),e&&e(null);else{var f=new FormData;f.append("prod","Cast");f.append("ver",chrome.runtime.getManifest().version);f.append(a,b);c&&f.append("comments",c);xf("https://clients2.google.com/cr/report",function(a){a=a.target;var b=null;a.ie()?(b=a.hj(),mo.info("Upload to Crash succeeded: "+
  b)):mo.info("Upload to Crash failed. HTTP status: "+a.Sa());e&&e(b)},"POST",f,void 0,3E4)}};var po=function(){this.gp=0;yh(this)},ro=function(){qo||(qo=new po);return qo};po.prototype.G$=function(a){this.gp=a};po.prototype.fca=function(){var a={fraction:.01,autoSubmitTimeLimitMillis:6048E5},b=a.autoSubmitTimeLimitMillis,c=Date.now();return this.gp&&b&&c-this.gp<b?!1:Math.random()<a.fraction};
  var to=function(a,b,c,e){var f=new so;f.extVersion=chrome.runtime.getManifest().version;f.extChannel="public";f.minBitrate=c.minVideoBitrate;f.maxBitrate=c.maxVideoBitrate;f.resolution=c.zY();f.minResolution=c.PY();f.resolutionChangePolicy=c.LZ();f.maxFrameRate=c.maxFrameRate;f.minLatency=c.minLatencyMillis;f.maxLatency=c.maxLatencyMillis;f.animatedLatency=c.animatedLatencyMillis;f.useDscp=c.dscpEnabled;f.useTdls=c.useTdls;null!=b&&(f.receiverVersion=b);null!=a&&(f.receiverProductName=a);e.length&&
  (f.Tra=e);return f},vo=function(a,b,c,e,f){uo.info("getRawEvents");return new Promise(function(g,k){var n=function(b){uo.info("Got receiver version: "+b);b=JSON.stringify(to(c,b,e,f));chrome.cast.streaming.rtpStream.getRawEvents(a,b,g)};"Chromecast"==c?Gf(b).then(n,k):n(null)})},wo=function(a,b,c,e){uo.info("getStats");return new Promise(function(f,g){var k=function(b){uo.info("Got receiver version: "+b);var g=to(c,b,e,[]);chrome.cast.streaming.rtpStream.getStats(a,function(a){var b={tags:g};Qb(b,
  a);f(b)})};"Chromecast"==c?Gf(b).then(k,g):k(null)})};po.prototype.ma=function(){return"mirror.cast.LogUtils"};po.prototype.getData=function(){return[void 0,{lastAutoSubmitMillis:this.gp}]};po.prototype.$a=function(){var a=wh(this);this.gp=a&&a.lastAutoSubmitMillis||0};var qo=null,uo=x("mr.mirror.cast.LogUtils"),so=function(){this.ext="MR";this.senderProductName="Google Chrome";this.senderVersion=Rj;this.senderPlatform=fc;this.senderUserAgent=Rb||""};var xo=function(a,b,c){fk.call(this,a,b,c)};ja(xo,fk);var yo=function(a){return a&&a.getAudioTracks()&&0<a.getAudioTracks().length?a.getAudioTracks()[0]:null},zo=function(a){return a&&a.getVideoTracks()&&0<a.getVideoTracks().length?a.getVideoTracks()[0]:null};var Ao=x("mr.NetworkUtils"),Bo=function(a,b){return cj?new Promise(function(c,e){chrome.networkingPrivate.setWifiTDLSEnabledState(a,b,function(a){chrome.runtime.lastError?(Ao.l("Unable to set TDLS state: state = "+b+", error = "+chrome.runtime.lastError.message),e("Unable to set TDLS state to "+b+".")):(Ao.info("TDLS state changed: state = "+b+", status = "+a),c(a))})}):Promise.reject("TDLS feature not enabled.")};var Co={uha:"OFFER",Mea:"ANSWER",Mha:"PRESENTATION",Yfa:"GET_STATUS",via:"STATUS_RESPONSE"};var Do=function(a,b){this.sessionId=a;this.seqNum=b;this.type="PRESENTATION"};var Eo=function(){this.vC=null;this.AM=[];this.sq=[];this.GL=this.oQ=null},Fo=function(){this.details=this.description=this.code=null},Go=function(){this.status=this.Nc=this.error=this.result=this.type=this.seqNum=this.sessionId=null},Ho=function(a){var b;try{if("string"!==typeof a)throw SyntaxError("Cannot parse non-string as JSON");b=JSON.parse(a);if(!(b instanceof Object))throw Error("non-Object result from JSON parse");var c=new Go;null!=b.sessionId&&(c.sessionId=String(b.sessionId));if("seqNum"in
  b){if("number"!==typeof b.seqNum)throw Error('"seqNum" must be a number');c.seqNum=b.seqNum}if("type"in b){for(var e=String(b.type).toUpperCase(),f=ia(Object.keys(Co)),g=f.next();!g.done;g=f.next())if(Co[g.value]==e){c.type=e;break}if(!c.type)throw Error('not a known message "type"');}"result"in b&&(c.result=String(b.result));if("error"in b){var k=b.error;if(!(k instanceof Object))throw Error('"error" must be a struct');c.error=new Fo;if("code"in k){if("number"!==typeof k.code)throw Error('"error.code" must be a number');
  c.error.code=k.code}"description"in k&&(c.error.description=String(k.description));if("details"in k){if(!(k.details instanceof Object))throw Error('"error.details" must be a struct');c.error.details=k.details}}if("answer"in b){var n=b.answer;if(!(n instanceof Object))throw Error('"answer" must be a struct');c.Nc=new Eo;if("udpPort"in n){if("number"!==typeof n.udpPort)throw Error('"answer.udpPort" must be a number');c.Nc.vC=n.udpPort}e=function(a){return a instanceof Array?a.every(function(a){return"number"===
  typeof a}):!1};if("sendIndexes"in n){if(!e(n.sendIndexes))throw Error('"answer.sendIndexes" must be an array of numbers');c.Nc.AM=n.sendIndexes}if("ssrcs"in n){if(!e(n.ssrcs))throw Error('"answer.ssrcs" must be an array of numbers');c.Nc.sq=n.ssrcs}"IV"in n&&(c.Nc.oQ=String(n.IV));"receiverGetStatus"in n&&(c.Nc.GL="true"==String(n.receiverGetStatus).toLowerCase())}"status"in b&&(c.status=b.status);return c}catch(q){b=q instanceof SyntaxError?"JSON parse error: "+q.message:"Type coercion error: "+
  q.message}"string"==typeof a?a="a string: "+a:a instanceof ArrayBuffer?(a=new Uint8Array(a),a="an ArrayBuffer whose base64 is "+btoa(String.fromCharCode.apply(null,a))):a="of invalid data type "+typeof a;throw Error(b+". Input was "+a);},Io=function(a,b,c){this.type="GET_STATUS";this.sessionId=a;this.seqNum=b;this.get_status=c};var Jo=function(a,b){this.address=a;this.port=b},Ko=function(a,b,c){mh.call(this,b);this.a=x("mr.mirror.cast.Session");this.tm=a;this.Pa=a.wg().clone();this.jd=tg.vs(b.id);this.A=b.Le.sessionId;this.oe=new Jo(b.Le.yO,2344);this.cu=b.Le.zO;this.cd=null;this.Gi=!1;this.oc=null;this.Hk=!1;this.ri=0;this.ya=this.ar=this.br=null;this.h6=["H264","VP8"];this.Py=new I;this.WD=null;this.pM=u(this.H4,this);this.oM=u(this.G4,this);this.Oo=null;this.Np=new vi(30);this.HL=!1;this.Ck=c||null;this.lB=new Qh("mirror.cast.SeqNumGenerator");
  this.ld=this.Ef=null;this.Lz=0};ja(Ko,mh);d=Ko.prototype;d.start=function(a){var b=this,c=yo(a);a=zo(a);this.Ef=new Ag("MediaRouter.CastStreaming.Session.Launch");this.ya=new xc;this.g1();this.Pa.useTdls&&Bo(this.oe.address,!0).then(function(a){"Connected"!=a&&(b.Pa.useTdls=!1)},function(){b.Pa.useTdls=!1});chrome.cast.streaming.session.create(c,a,function(a,c,g){b.cd=a;b.oc=c;b.ri=g;b.jd.onMessage=u(b.Nt,b);b.Lz=0;b.kB({type:"OFFER",sessionId:b.getId(),seqNum:b.lB.zs(),offer:b.$n()})});return this.ya.promise};
  d.stop=function(){this.ld&&(this.ld.end(),this.ld=null);this.a.info("Stopping "+this.getId());null!==this.cd&&(chrome.cast.streaming.rtpStream.stop(this.cd),chrome.cast.streaming.rtpStream.destroy(this.cd),this.cd=null,this.Gi=!1);null!==this.oc&&(chrome.cast.streaming.rtpStream.stop(this.oc),chrome.cast.streaming.rtpStream.destroy(this.oc),this.oc=null,this.Hk=!1);this.ri&&(chrome.cast.streaming.udpTransport.destroy(this.ri),this.ri=0);this.Pa.useTdls&&Bo(this.oe.address,!1);this.ya&&(this.ya.resolve(this),
  this.ya=null);chrome.cast.streaming.rtpStream.onStarted.removeListener(this.pM);chrome.cast.streaming.rtpStream.onError.removeListener(this.oM);null!==this.Oo&&(window.clearTimeout(this.Oo),this.Oo=null);this.br=this.ar=null;if(this.Ck&&this.Ck.onSessionStop)this.Ck.onSessionStop(this.oe);this.jd.Ya();return!0};d.O$=function(a){this.Gi&&chrome.cast.streaming.rtpStream.toggleLogging(this.cd,a);this.Hk&&chrome.cast.streaming.rtpStream.toggleLogging(this.oc,a)};
  d.getLogs=function(){var a=this;if(!this.Gi&&!this.Hk)return Promise.reject(Error("No streams has been started yet."));var b=[];if(this.Gi){var c=vo(this.cd,this.oe.address,this.cu,this.Pa,this.Np.G());b.push(c)}this.Hk&&(c=vo(this.oc,this.oe.address,this.cu,this.Pa,this.Np.G()),b.push(c));return Promise.all(b).then(function(b){b=new Blob(b,{type:"application/gzip"});a.a.info("Events blob size: "+b.size);return b})};
  d.getStats=function(){var a=[];if(this.Gi){var b=wo(this.cd,this.oe.address,this.cu,this.Pa);a.push(b)}this.Hk&&(b=wo(this.oc,this.oe.address,this.cu,this.Pa),a.push(b));this.Np.W()&&a.push(Promise.resolve({receiverStatusData:this.Np.G()}));return Promise.all(a).then(function(a){var b={};a.forEach(function(a){Qb(b,a)});return b})};
  d.YT=function(){var a=chrome.cast.streaming.rtpStream.getSupportedParams(this.cd)[0];a.payload.channels=2;a.payload.maxBitrate=this.Pa.audioBitrate;a.payload.maxFrameRate=100;a.payload.maxLatency=this.Pa.maxLatencyMillis;a.payload.minLatency=this.Pa.minLatencyMillis;a.payload.animatedLatency=this.Pa.animatedLatencyMillis;a.payload.ssrc=Math.floor(499999*Math.random())+1;a.payload.clockRate=48E3;a.payload.feedbackSsrc=2;a.payload.payloadType=127;a.payload.aesKey=this.br;a.payload.aesIvMask=this.ar;
  return a};
  d.oU=function(){var a=this,b=[];if(null===this.oc)return b;var c=chrome.cast.streaming.rtpStream.getSupportedParams(this.oc);this.h6.forEach(function(e){var f=c.find(function(a){return a.payload.codecName.toLowerCase()==e.toLowerCase()});f&&(f.payload.maxFrameRate=a.Pa.maxFrameRate,f.payload.minBitrate=a.Pa.minVideoBitrate,f.payload.maxBitrate=a.Pa.maxVideoBitrate,f.payload.maxLatency=a.Pa.maxLatencyMillis,f.payload.minLatency=a.Pa.minLatencyMillis,f.payload.animatedLatency=a.Pa.animatedLatencyMillis,f.payload.aesKey=
  a.br,f.payload.aesIvMask=a.ar,f.payload.ssrc=Math.floor(499999*Math.random())+500001,f.payload.feedbackSsrc=12,f.payload.payloadType=96,b.push(f))});return b};
  d.$n=function(){var a=this,b=0,c=[];if(this.cd){var e=this.YT();this.WD=e;e={index:b,type:"audio_source",codecName:e.payload.codecName.toLowerCase(),rtpProfile:"cast",rtpPayloadType:e.payload.payloadType,ssrc:e.payload.ssrc,targetDelay:this.Pa.animatedLatencyMillis,aesKey:e.payload.aesKey,aesIvMask:e.payload.aesIvMask,bitRate:0<e.payload.maxBitrate?1E3*e.payload.maxBitrate:60*e.payload.maxFrameRate+e.payload.clockRate*e.payload.channels,sampleRate:e.payload.clockRate,timeBase:"1/"+e.payload.clockRate,
  channels:e.payload.channels,rtpExtensions:["adaptive_playout_delay"]};this.Pa.enableLogging&&Qb(e,{receiverRtcpEventLog:!0});this.Pa.dscpEnabled&&Qb(e,{receiverRtcpDscp:46});c.push(e);b++}this.oU().forEach(function(e){var f={index:b,type:"video_source",codecName:e.payload.codecName.toLowerCase(),rtpProfile:"cast",rtpPayloadType:e.payload.payloadType,ssrc:e.payload.ssrc,targetDelay:a.Pa.animatedLatencyMillis,aesKey:e.payload.aesKey,aesIvMask:e.payload.aesIvMask,maxFrameRate:Math.round(1E3*e.payload.maxFrameRate)+
  "/1000",timeBase:"1/90000",maxBitRate:e.payload.maxBitrate,resolutions:[{width:a.Pa.maxWidth,height:a.Pa.maxHeight}],rtpExtensions:["adaptive_playout_delay"]};a.Pa.enableLogging&&Qb(f,{receiverRtcpEventLog:!0});a.Pa.dscpEnabled&&Qb(f,{receiverRtcpDscp:46});c.push(f);a.Py.set(b,e);b++});return{supportedStreams:c}};
  d.H4=function(a){a==this.cd?this.Gi=!0:a==this.oc&&(this.Hk=!0);this.Gi&&(null===this.oc||this.Hk)&&(this.O$(this.Pa.enableLogging),this.ya&&(this.ya.resolve(this),this.ya=null));this.ld=new Fg("MediaRouter.CastStreaming.Session.Length")};d.G4=function(a,b){if(a==this.cd)this.a.l("Audio stream error "+b);else if(a==this.oc)this.a.l("Video stream error "+b);else{this.a.l("Error for stream "+a+": "+b);return}this.ya&&(this.ya.reject(Error("Error for stream "+a+": "+b)),this.ya=null);this.stop()};
  d.Hca=function(a,b){var c=this;this.a.o(function(){return"Starting streaming ... "+JSON.stringify({udpTransportId:c.ri,receiverIpEndPoint:c.oe,"audio ID":c.cd,"video ID":c.oc,"audio params":a,"video params":b})});if(sa(chrome.cast.streaming.udpTransport.setOptions)){var e={};this.Pa.dscpEnabled&&(this.a.info("Enable DSCP in sender."),e.DSCP=!0);chrome.cast.streaming.udpTransport.setOptions(this.ri,e)}chrome.cast.streaming.udpTransport.setDestination(this.ri,{address:this.oe.address,port:this.oe.port});
  chrome.cast.streaming.rtpStream.onStarted.addListener(this.pM);chrome.cast.streaming.rtpStream.onError.addListener(this.oM);a&&chrome.cast.streaming.rtpStream.start(this.cd,a);b&&chrome.cast.streaming.rtpStream.start(this.oc,b)};
  d.Nt=function(a){var b=this;if("urn:x-cast:com.google.cast.webrtc"==a.namespace_){var c,e=null;try{c=Ho(a.data)}catch(q){c=new Go,e=q.message}if("ANSWER"==c.type)if("ok"==c.result&&c.Nc){c.Nc.vC&&(this.oe.port=c.Nc.vC);this.HL=!!c.Nc.GL;if(this.Ck)this.Ck.onAnswer(this.oe);this.Ef&&(this.Ef.end(),this.Ef=null);this.a.info("Starting streaming");var f=this.WD,g=null;c.Nc.AM.forEach(function(a){f&&0==a?c.Nc.sq[a]&&(f.payload.feedbackSsrc=c.Nc.sq[a]):b.Py.Aa(a)&&(g?b.a.l("Receiver selected multiple video stream"):
  (g=b.Py.get(a),c.Nc.sq[a]&&(g.payload.feedbackSsrc=c.Nc.sq[a])))});null!==this.oc&&null===g&&(this.a.l("Receiver is capable of video, but did not specify a video stream index in the ANSWER message."),chrome.cast.streaming.rtpStream.destroy(this.oc),this.oc=null);if(f||g)this.HH(),this.Hca(f,g),this.ya&&(this.ya.resolve(this),this.ya=null)}else this.ya&&(this.ya.reject(Error("Non-OK answer received: "+JSON.stringify(c))),this.ya=null),this.stop();else if("STATUS_RESPONSE"==c.type&&c.status instanceof
  Object){a={};for(var e=ia(Object.keys(c.status)),k=e.next();!k.done;k=e.next()){var k=k.value,n=c.status[k];qa(n)&&n.length?a[k]=n.pop():a[k]=n}e={};e[(new Date).toISOString()]=a;this.Np.add(e)}else e||(e="Ignoring message: "+JSON.stringify(c)),10>this.Lz?this.a.l(e):this.a.o(e),++this.Lz}};d.g1=function(){this.ar=Rh(window.crypto.getRandomValues(new Uint8Array(16)));this.br=Rh(window.crypto.getRandomValues(new Uint8Array(16)))};d.CM=function(){this.kB(this.sZ())};
  d.kB=function(a){this.jd.sendMessage(a,{namespace:"urn:x-cast:com.google.cast.webrtc"})};d.HH=function(){this.Oo=null;if(this.ri&&this.HL){var a=new Io(this.getId(),this.lB.zs(),["wifiSnr","wifiSpeed","wifiFcsError"]);this.kB(a);this.Oo=window.setTimeout(u(this.HH,this),12E4)}};d.sZ=function(){var a=new Do(this.A,this.lB.zs());a.title=this.QA||void 0;a.icons=this.iconUrl&&!this.Ws?[new chrome.cast.Image(this.iconUrl)]:[];return a};d.getId=function(){return this.A};d.vg=function(){return this.tm};var Lo=function(){lh.call(this,"cast_streaming");this.Ck=null};ja(Lo,lh);d=Lo.prototype;d.getName=function(){return"cast_streaming"};d.vg=function(a,b,c){return new xo(a,b,c)};d.Ir=function(a,b){return new Ko(a,b,this.Ck)};d.hu=function(){lo(0)};d.du=function(){lo(1)};d.LA=function(){lo(2)};d.eu=function(){Ig("MediaRouter.CastStreaming.Session.End")};d.fu=function(a){Jg("MediaRouter.CastStreaming.Start.Failure",a,Lg)};d.gu=function(){Ig("MediaRouter.CastStreaming.Stream.End")};
  d.lw=function(){var a=this,b=this.Ka,c=b.getLogs().then(function(a){return a},function(b){a.m.l("Get cast streaming logs failed.",b)}),b=b.getStats().then(function(a){return a},function(b){a.m.l("Get cast streaming stats failed.",b)}),e=new Promise(function(a){chrome.metricsPrivate.getIsCrashReportingEnabled(a)});return Promise.all([c,b,e]).then(function(b){var c=ia(b);b=c.next().value;var e=c.next().value,c=c.next().value;if(b){var f=new FileReader;f.onloadend=function(){Fh("mr.temp.mirror.cast.Service.mirrorLogs",
  f.result)};f.readAsBinaryString(b)}c&&(b&&ro().fca()?oo(b,void 0,a.q3.bind(a)):e&&no("stats.json",new Blob([JSON.stringify(e)],{type:"application/json"}),void 0,void 0))})};d.q3=function(a){a&&ro().G$(Date.now())};d.Qg=function(a){var b=this;this.m.info("Received message to upload logs for "+a);return this.Ka?this.Ka.getLogs().then(function(b){return oo(b,a)},function(c){b.m.l("Get cast streaming logs failed.",c);return b.bK(a)}):Promise.resolve(this.bK(a))};
  d.bK=function(a){var b=window.localStorage["mr.temp.mirror.cast.Service.mirrorLogs"];if(!b)return"";window.localStorage.removeItem("mr.temp.mirror.cast.Service.mirrorLogs");this.m.info("Uploading saved logs for feedback.");for(var c=new Uint8Array(b.length),e=0;e<c.length;e++)c[e]=b.charCodeAt(e);return oo(new Blob([c],{type:"application/gzip"}),a)};var Mo=new Lo;jh("mr.mirror.cast.Service",Mo);
  