text: 'use strict';var tda={TAB:0,Ek:1,Bo:2},yw=function(){return new rb("MediaRouter.CastStreaming.Session.Launch")},zw=function(){return new xb("MediaRouter.CastStreaming.Session.Length")},Aw=function(a){Bb("MediaRouter.CastStreaming.Start.Success",a,tda)};var Bw=gb("mr.mirror.cast.LogUploader"),Dw=function(a,c,b){Cw("raw_events.log.gz",a,c,b);return c?"https://crash.corp.google.com/samples?reportid=&q="+encodeURIComponent("UserComments='"+c+"'"):""},Cw=function(a,c,b,d){if(0==c.size)Bw.info("Trying to upload an empty file to Crash"),d&&d(null);else{var e=new FormData;e.append("prod","Cast");e.append("ver",chrome.runtime.getManifest().version);e.append(a,c);b&&e.append("comments",b);ev("https://clients2.google.com/cr/report",function(f){f=f.target;
  var g=null;mv(f)?(g=nv(f),Bw.info("Upload to Crash succeeded: "+g)):Bw.info("Upload to Crash failed. HTTP status: "+f.Ua());d&&d(g)},"POST",e,void 0,3E4)}};var Ew=function(){this.b=0;gm(this)},Gw=function(){Fw||(Fw=new Ew);return Fw},uda=function(){var a=Gw(),c={fraction:.01,autoSubmitTimeLimitMillis:6048E5},b=c.autoSubmitTimeLimitMillis,d=Date.now();return a.b&&b&&d-a.b<b?!1:Math.random()<c.fraction};Ew.prototype.Ca=function(){return"mirror.cast.LogUtils"};Ew.prototype.qb=function(){return[void 0,{lastAutoSubmitMillis:this.b}]};Ew.prototype.ob=function(){var a=em(this);this.b=a&&a.lastAutoSubmitMillis||0};var Fw=null;gb("mr.mirror.cast.LogUtils");var Hw={Ux:"OFFER",St:"ANSWER",xy:"PRESENTATION",Hv:"GET_STATUS",Jz:"STATUS_RESPONSE",Gv:"GET_CAPABILITIES",qu:"CAPABILITIES_RESPONSE",jz:"RPC"};var vda=function(){this.capabilities=this.status=this.b=this.error=this.rpc=this.result=this.type=this.f=this.sessionId=null},xda=function(a){try{if("string"!==typeof a)throw SyntaxError("Cannot parse non-string as JSON");var c;Iw(JSON.parse(a),function(d){c=wda(d)},function(){throw Error("non-Object result from JSON parse");});return c}catch(d){var b=d instanceof SyntaxError?"JSON parse error: "+d.message:"Type coercion error: "+d.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);},wda=function(a){var c=new vda;null!=a.sessionId&&(c.sessionId=String(a.sessionId));Jw(a.seqNum,function(f){c.f=f},function(){throw Error('"seqNum" must be a number');});if("type"in a){for(var b=String(a.type).toUpperCase(),d=l(Object.keys(Hw)),e=d.next();!e.done;e=d.next())if(Hw[e.value]==b){c.type=b;break}if(!c.type)throw Error('not a known message "type"');
  }"result"in a&&(c.result=String(a.result));if("rpc"in a){if("string"!==typeof a.rpc)throw Error('"rpc" must be a String containing a base64 payload');c.rpc=new Uint8Array([].concat(n(atob(a.rpc))).map(function(f){return f.charCodeAt(0)}))}Iw(a.error,function(f){c.error=yda(f)},function(){throw Error('"error" must be an Object');});Iw(a.answer,function(f){c.b=zda(f)},function(){throw Error('"answer" must be an Object');});Iw(a.status,function(f){c.status=Ada(f)},function(){throw Error('"status" must be an Object');
  });Iw(a.capabilities,function(f){c.capabilities=Bda(f)},function(){throw Error('"capabilities" must be an Object');});return c},Iw=function(a,c,b){void 0!==a&&(a instanceof Object?c(a):b())},Jw=function(a,c,b){void 0!==a&&("number"!==typeof a?b():c(a))},Kw=function(a,c,b){void 0!==a&&(a instanceof Array&&a.every(function(d){return"number"===typeof d})?c(a):b())},Lw=function(a,c,b){void 0!==a&&(a instanceof Array?c(a.map(function(d){return String(d)})):b())},Cda=function(){this.j=null;this.b=[];this.f=
  [];this.g=this.h=this.w=null},zda=function(a){var c=new Cda;Jw(a.udpPort,function(b){c.j=b},function(){throw Error('"answer.udpPort" must be a number');});Kw(a.sendIndexes,function(b){c.b=b},function(){throw Error('"answer.sendIndexes" must be an array of numbers');});Kw(a.ssrcs,function(b){c.f=b},function(){throw Error('"answer.ssrcs" must be an array of numbers');});"IV"in a&&(c.w=String(a.IV));"receiverGetStatus"in a&&(c.h="true"==String(a.receiverGetStatus).toLowerCase());"castMode"in a&&(c.g=
  String(a.castMode));return c},Dda=function(){this.details=this.description=this.code=null},yda=function(a){var c=new Dda;Jw(a.code,function(b){c.code=b},function(){throw Error('"error.code" must be a number');});"description"in a&&(c.description=String(a.description));Iw(a.details,function(b){c.details=b},function(){throw Error('"error.details" must be an Object');});return c},Eda=function(){this.f=this.b=null},Ada=function(a){var c=new Eda;Jw(a.wifiSnr,function(b){c.b=b},function(){throw Error('"status.wifiSnr" must be a number');
  });Kw(a.wifiSpeed,function(b){c.f=b},function(){throw Error('"status.wifiSpeed" must be an array of numbers');});return c},Fda=function(){this.f=this.b=null},Bda=function(a){var c=new Fda;Lw(a.mediaCaps,function(b){c.b=b},function(){throw Error('"capabilities.mediaCaps" must be an array');});if("keySystems"in a){a=a.keySystems;if(!(a instanceof Array))throw Error('"capabilities.keySystems" must be an array');c.f=a.map(function(b){var d;Iw(b,function(e){d=Gda(e)},function(){throw Error('"capabilities.keySystems" entries must be *Objects');
  });return d})}return c},Hda=function(){this.g=this.m=this.w=this.j=this.s=this.b=this.o=this.f=this.initDataTypes=this.h=null},Gda=function(a){var c=new Hda;"keySystemName"in a&&(c.h=String(a.keySystemName));Lw(a.initDataTypes,function(b){c.initDataTypes=b},function(){throw Error('"capabilities.initDataTypes" must be an array');});Lw(a.codecs,function(b){c.f=b},function(){throw Error('"capabilities.codecs" must be an array');});Lw(a.secureCodecs,function(b){c.o=b},function(){throw Error('"capabilities.secureCodecs" must be an array');
  });Lw(a.audioRobustness,function(b){c.b=b},function(){throw Error('"capabilities.audioRobustness" must be an array');});Lw(a.videoRobustness,function(b){c.s=b},function(){throw Error('"capabilities.videoRobustness" must be an array');});"persistentLicenseSessionSupport"in a&&(c.j=String(a.persistentLicenseSessionSupport));"persistentReleaseMessageSessionSupport"in a&&(c.w=String(a.persistentReleaseMessageSessionSupport));"persistentStateSupport"in a&&(c.m=String(a.persistentStateSupport));"distinctiveIdentifierSupport"in
  a&&(c.g=String(a.distinctiveIdentifierSupport));return c};var Mw=function(a){this.l=gb("mr.mirror.cast.MessageDispatcher");this.h=a;this.b=null;this.f=new Map;this.g=0};Mw.prototype.subscribe=function(a,c){if(this.f.has(a))throw Error("Attempt to multiple-subscribe to the same response type: "+a);this.f.set(a,c);this.g=0;nb(this.l,"Added subscriber for "+a+"-type messages.");this.b||(this.b=Rv(this.h),this.b.onMessage=this.j.bind(this))};
  var Nw=function(a,c){a.f.delete(c)&&nb(a.l,function(){return"Removed subscriber of "+c+"-type messages."});0==a.f.size&&a.b&&(a.b.lb(),a.b=null)};Mw.prototype.sendMessage=function(a){return this.b?"RPC"==a.type?this.b.sendMessage(a,{namespace:"urn:x-cast:com.google.cast.remoting"}):this.b.sendMessage(a,{namespace:"urn:x-cast:com.google.cast.webrtc"}):Promise.reject(Error("Require at least one subscriber before sending messages."))};
  var Ow=function(a,c,b,d,e){var f=null,g=function(){Nw(a,b);null!=f&&(clearTimeout(f),f=null)};try{a.subscribe(b,function(k){e(k)&&g()})}catch(k){e(null,k);return}f=setTimeout(function(){g();e(null,Error("timeout"))},d);a.sendMessage(c).catch(function(k){g();e(null,k)})};
  Mw.prototype.j=function(a){if(a&&"string"===typeof a.namespace_&&a.namespace_.startsWith("urn:x-cast:com.google.cast.")){do{var c=void 0;try{c=xda(a.data)}catch(d){c=d.message;break}if(c.type){var b=this.f.get(c.type);if(b)try{b(c);return}catch(d){c="Error thrown during delivery. Response was: "+(JSON.stringify(c)+". Error from subscriber callback was: ")+(d.message+".")}else c="Message was ignored: "+JSON.stringify(c)}else c="Message did not include response type: "+JSON.stringify(c)}while(0);10>
  this.g?this.l.H(c):nb(this.l,c);++this.g}};var Pw=function(){this.b=Promise.resolve(1)},Rw=function(a,c,b){return Qw(a,function(d){return d==c},b)},Ida=function(a,c){var b=[3,4];return Qw(a,function(d){return-1!=b.indexOf(d)},c)},Sw=function(a,c){a.b=a.b.catch(function(){return 1});return Qw(a,function(){return!0},c)},Qw=function(a,c,b){var d,e,f=new Promise(function(g,k){d=g;e=k});a.b=a.b.then(function(g){if(!c(g))return e(Error("Operation requires a different starting checkpoint than "+g)),Promise.resolve(g);var k=new Jda(g);try{var m=b(k)}catch(p){m=
  Promise.reject(p)}return m.then(function(p){return d(p)},function(p){return e(p)}).then(function(){if(null===k.b)throw Error("A prior operation that started at "+(g+" did not complete."));return k.b})},function(g){e(g);throw g;});return f},Jda=function(a){this.f=a;this.b=null},Tw=function(a,c){a.b="number"===typeof c?c:a.f};var Uw=chrome.cast.streaming,Ww=function(a,c,b,d,e){this.J=a.sessionId;this.s=a.dg;this.M=a.ne;this.g=c;this.G=b;this.K=d;this.T=Vw(e,"onAnswer",this.s);this.V=Vw(e,"onSessionStop",this.s);this.l=gb("mr.mirror.cast.StreamingLaunchWorkflow");this.D=new Pw;this.m=this.C=this.o=this.f=this.b=this.w=this.j=this.h=null};
  Ww.prototype.start=function(a,c,b){var d=this;if(!a&&!c)return Promise.reject(Error("No tracks to stream"));var e=a instanceof Xw,f=c instanceof Xw;(e&&c&&!f||f&&a&&!e)&&Gb("Mixing remoting and non-remoting tracks");return Rw(this.D,1,function(g){d.h=a;d.j=c;d.w=b;d.l.info(function(){return"Launching streaming for "+Yw(d)+" to a "+(d.M+".")});return Kda(d).then(d.F.bind(d)).then(function(k){return Lda(d,k).then(function(m){d.T();var p=Mda(d,m,k);d.b=Zw(d,d.b,p);d.f=Zw(d,d.f,p);if(!d.b&&!d.f)throw Error("Receiver did not select any offers from: "+
  JSON.stringify(k));d.C=!!m.h;d.m=function(u,A){u==d.b?d.w.hf("Audio stream (id="+u+") error: "+A):u==d.f&&d.w.hf("Video stream (id="+u+") error: "+A)};Uw.rtpStream.onError.addListener(d.m);return Nda(d,m,p)})}).then(function(){d.l.info(function(){return"Launched streaming for "+Yw(d)});d.w.wg(d);Tw(g,2);return{Qp:d.b,At:d.f}})})};
  Ww.prototype.stop=function(){var a=this;return Sw(this.D,function(c){if(!a.h&&!a.j)return Tw(c,1),Promise.resolve();a.l.info(function(){return"Stopping streaming for "+Yw(a)+"."});a.m&&(Uw.rtpStream.onError.removeListener(a.m),a.m=null);if(a.w){var b=a.w.jh();a.w=null}else b=Promise.resolve();return b.then(function(){a.b&&(Uw.rtpStream.stop(a.b),Uw.rtpStream.destroy(a.b),a.b=null);a.f&&(Uw.rtpStream.stop(a.f),Uw.rtpStream.destroy(a.f),a.f=null);a.o&&(Uw.udpTransport.destroy(a.o),a.o=null);a.V();a.l.info(function(){return"Stopped streaming for "+
  Yw(a)+"."});a.h=null;a.j=null;Tw(c,1)})})};
  var Oda=function(a,c){var b=JSON.stringify(c);return Promise.all([a.b&&new Promise(function(d){return Uw.rtpStream.getRawEvents(a.b,b,d)}),a.f&&new Promise(function(d){return Uw.rtpStream.getRawEvents(a.f,b,d)})]).catch(function(d){a.l.error("Unexpected error when calling getRawEvents()",d);return[]}).then(function(d){return new Blob(d.filter(function(e){return!!e}),{type:"application/gzip"})})},Pda=function(a){return Promise.all([a.b&&new Promise(function(c){return Uw.rtpStream.getStats(a.b,c)}),
  a.f&&new Promise(function(c){return Uw.rtpStream.getStats(a.f,c)})]).catch(function(c){a.l.error("Unexpected error when calling getStats()",c);return[]}).then(function(c){return Object.assign.apply(Object,[{}].concat(n(c.filter(function(b){return!!b}))))})},Yw=function(a){if(a.h&&a.j)var c="audio+video ";else if(a.h)c="audio-only ";else if(a.j)c="video-only ";else return"stopped";return a.h instanceof Xw||a.j instanceof Xw?c+"remoting":c+"streaming"},Kda=function(a){return new Promise(function(c){var b=
  function(d,e,f){d&&!a.h&&(Uw.rtpStream.destroy(d),d=null);e&&!a.j&&(Uw.rtpStream.destroy(e),e=null);a.l.info(function(){return"Created Cast Streaming session: audioStreamId="+d+", videoStreamId="+e+"."});a.b=d;a.f=e;a.o=f;c()};a.h instanceof Xw||a.j instanceof Xw?Uw.session.create(null,null,b):Uw.session.create(a.h,a.j,b)})};
  Ww.prototype.F=function(){for(var a=Sj(),c=Sj(),b=[],d=l([this.b,this.f]),e=d.next();!e.done;e=d.next())if(e=e.value)for(var f=e==this.b,g=f?127:96,k=f?Math.floor(499999*Math.random())+1:Math.floor(499999*Math.random())+500001,m=f?48E3:9E4,p=l(Uw.rtpStream.getSupportedParams(e)),u=p.next();!u.done;u=p.next())u=u.value,u.payload.payloadType=g,u.payload.maxLatency=this.g.maxLatencyMillis,u.payload.minLatency=this.g.minLatencyMillis,u.payload.animatedLatency=this.g.animatedLatencyMillis,u.payload.ssrc=
  k,u.payload.clockRate=m,u.payload.aesKey=a,u.payload.aesIvMask=c,f?(u.payload.channels=2,u.payload.maxBitrate=this.g.audioBitrate,u.payload.maxFrameRate=100):(u.payload.minBitrate=this.g.minVideoBitrate,u.payload.maxBitrate=this.g.maxVideoBitrate,u.payload.maxFrameRate=this.g.maxFrameRate),b.push(new Qda(e,u));return b};
  var Zw=function(a,c,b){c&&!b.some(function(d){return d.gg==c})&&(a.l.H("Destroying RTP stream not selected by the receiver: id="+c),Uw.rtpStream.destroy(c),c=null);return c},Lda=function(a,c){return new Promise(function(b,d){for(var e=[],f=0;f<c.length;++f){var g=c[f].params,k={index:f,codecName:g.payload.codecName.toLowerCase(),rtpProfile:"cast",rtpPayloadType:g.payload.payloadType,ssrc:g.payload.ssrc,targetDelay:g.payload.animatedLatency,aesKey:g.payload.aesKey,aesIvMask:g.payload.aesIvMask,timeBase:"1/"+
  g.payload.clockRate,receiverRtcpEventLog:a.g.enableLogging,rtpExtensions:["adaptive_playout_delay"]};a.g.dscpEnabled&&(k.receiverRtcpDscp=46);127==g.payload.payloadType?Object.assign(k,{type:"audio_source",bitRate:0<g.payload.maxBitrate?1E3*g.payload.maxBitrate:60*g.payload.maxFrameRate+g.payload.clockRate*g.payload.channels,sampleRate:g.payload.clockRate,channels:g.payload.channels}):Object.assign(k,{type:"video_source",renderMode:"video",maxFrameRate:Math.round(1E3*g.payload.maxFrameRate)+"/1000",
  maxBitRate:1E3*g.payload.maxBitrate,resolutions:[{width:a.g.maxWidth,height:a.g.maxHeight}]});e.push(k)}var m=a.h instanceof Xw||a.j instanceof Xw?"remoting":"mirroring",p={type:"OFFER",sessionId:a.J,seqNum:vn(a.G),offer:{castMode:m,receiverGetStatus:!0,supportedStreams:e}};a.l.info(function(){return"Sending OFFER message: "+JSON.stringify(p)});Ow(a.K,p,"ANSWER",1E4,function(u,A){if(null==u)d(A);else if("ok"==u.result&&u.b){if(u.f!=p.seqNum)return a.l.H("Ignoring ANSWER for OFFER with different seqNum: "+
  JSON.stringify(u)),!1;((A=u.b.g)&&A!=m||!A&&"mirroring"!=m)&&a.l.error("Expected receiver to ANSWER with castMode="+m+", but got: "+A);nb(a.l,function(){return"Received ANSWER: "+JSON.stringify(u)});b(u.b)}else d(Error("Non-OK ANSWER received: "+JSON.stringify(u)));return!0})})},Mda=function(a,c,b){if(c.b.length!=c.f.length)return a.l.error("sendIndexes.length != ssrcs.length in ANSWER: "+JSON.stringify(c)),[];for(var d=[],e={},f=0;f<c.b.length;e={qf:e.qf},++f){var g=c.b[f];if(0>g||g>=b.length)return a.l.error("Receiver selected invalid index ("+
  g+" < "+b.length+") in ANSWER: "+JSON.stringify(c)),[];e.qf=b[g];if(d.some(function(k){return function(m){return m.gg==k.qf.gg}}(e)))return a.l.error("Receiver selected same RTP stream twice in ANSWER: "+JSON.stringify(c)),[];e.qf.params.payload.feedbackSsrc=c.f[g];if(d.some(function(k){return function(m){return m.params.payload.feedbackSsrc==k.qf.params.payload.feedbackSsrc}}(e)))return a.l.error("Receiver provided same SSRC for two different RTP streams in ANSWER: "+JSON.stringify(c)),[];d.push(e.qf)}return d},
  Nda=function(a,c,b){var d=null,e=function(){d&&(Uw.rtpStream.onStarted.removeListener(d),d=null)};return(new Promise(function(f,g){var k=c.j||2344;a.l.info(function(){return"Starting RTP streams to receiver at "+(a.s+":"+k)+(" for selected offers: "+JSON.stringify(b))});var m=a.o||-1;a.g.dscpEnabled&&(a.l.info("Enabled DSCP in sender."),Uw.udpTransport.setOptions(m,{DSCP:!0}));Uw.udpTransport.setDestination(m,{address:a.s,port:k});var p=new Set(b.map(function(A){return A.gg}));d=function(A){p.delete(A);
  0==p.size&&f()};Uw.rtpStream.onStarted.addListener(d);m=l(b);for(var u=m.next();!u.done;u=m.next())u=u.value,Uw.rtpStream.toggleLogging(u.gg,a.g.enableLogging),Uw.rtpStream.start(u.gg,u.params);setTimeout(function(){g(Error("Timeout: RTP streams failed to start."))},1E4)})).then(e).catch(function(f){e();throw f;})},Vw=function(a,c,b){var d=this;return a&&c in a?function(){try{a[c](b)}catch(e){d.l.error("Error from testHooks."+c,e)}}:function(){}},Qda=function(a,c){this.gg=a;this.params=c},Xw=function(){};var $w=function(a,c,b,d,e,f){this.m=a;this.K=Rda(c,this.m.wb);this.G=new Ww(this.m.wb,b,d,e,f);this.C=e;this.j=new Pw;this.g=new Sda;this.D=new mojo.Binding(mojo.MirrorServiceRemoter,this,null);this.l=gb("mr.mirror.cast.MediaRemoter");this.s=this.b=this.w=this.h=this.F=null;this.f=!0;this.o=this.J.bind(this)};
  $w.prototype.initialize=function(a,c){var b=this;return Rw(this.j,1,function(d){b.F=a;b.h=c;var e=b.D.createInterfacePtrAndBind();b.D.setConnectionErrorHandler(function(){b.l.info("Remoter mojo pipe connection error.");ax(b)});b.b=new mojo.MirrorServiceRemotingSourcePtr;var f=kj(b.m.mediaSource||"");if(!f)throw Error("Failed to parse tab ID from source:\n          "+b.m.mediaSource);b.l.info("Connecting remoter to browser: tabId="+f);(Ti.get("mr.ProviderManager")||null).onMediaRemoterCreated(f,e,
  mojo.makeRequest(b.b));b.b.ptr.setConnectionErrorHandler(function(){b.l.info("RemotingSource mojo pipe connection error.");ax(b)});return Tda(b).then(function(){if(b.f)b.b.onSinkAvailable(b.K);Tw(d,2)})})};
  var ax=function(a){return Sw(a.j,function(c){a.b&&(a.b.ptr.reset(),a.b=null);var b=a.w;a.w=null;a.h=null;a.F=null;a.D.close();chrome.settingsPrivate.onPrefsChanged.hasListener(a.o)&&chrome.settingsPrivate.onPrefsChanged.removeListener(a.o);return new Promise(function(d){window.setTimeout(function(){bx(a).then(function(){Tw(c,1);d();b&&b()})},250)})})};h=$w.prototype;h.Ts=function(a){cx(this.g,a)};h.wg=function(a){this.h&&this.h.wg(a)};h.jh=function(){return this.h?this.h.jh():Promise.resolve()};
  h.hf=function(a,c){this.l.error("Error during streaming: "+a,c);if(this.b)this.b.onError();ax(this)};
  h.start=function(){var a=this,c=!1;this.l.info(function(){c=!0;return"Starting next media remoting session."});c&&Uda(this.g,function(b){return a.l.info(b)});Vda(this.g);Rw(this.j,2,function(b){return(0,a.F)().then(function(d){a.w=d;a.C.subscribe("RPC",function(e){if(e.rpc){var f=a.g;e=e.rpc;f.w&&(++f.m,f.f+=e.length,f.w(e))}});Tw(b,3)}).catch(function(d){return bx(a).then(function(){Tw(b);throw d;})})}).then(function(){a.l.info("Remoting started successfully.")}).catch(function(b){a.l.error("Failed to start remoting",
  b);a.b.onError()})};h.rt=function(a,c){var b=this;return Rw(this.j,3,function(d){return b.G.start(a?new Xw:null,c?new Xw:null,b).then(function(e){Wda(b.g,function(f){return b.C.sendMessage(f)},function(f){b.b.onMessageFromSink(f)});Tw(d,4);return{audio_stream_id:e.Qp||-1,video_stream_id:e.At||-1}}).catch(function(e){return bx(b).then(function(){Tw(d);throw e;})})}).catch(function(d){b.l.error("Failed to start remoting streams",d);ax(b);return{audio_stream_id:-1,video_stream_id:-1}})};
  h.stop=function(a){var c=this;Ida(this.j,function(b){c.b.onStopped(a);return bx(c).then(function(){c.l.info("Remoting stopped.");Tw(b,5);(0,c.w)().then(function(){return Rw(c.j,5,function(d){if(c.b&&c.f)c.b.onSinkAvailable(c.K);Tw(d,2);return Promise.resolve()})}).catch(function(d){throw d;});c.w=null})}).catch(function(b){c.l.error("Failed to stop remoting: ",b);ax(c)})};
  h.pq=function(){null===this.s&&(this.s=pf(this.m.wb.dg).then(function(a){return a.f||!1}));return this.s.then(function(a){return{rate:(a?1E7:5E6)/8}})};
  var bx=function(a){return a.G.stop().then(function(){Nw(a.C,"RPC");Xda(a.g);dx(a.g)})},Tda=function(a){return new Promise(function(c){chrome.settingsPrivate.getPref("media_router.media_remoting.enabled",function(b){chrome.runtime.lastError?a.l.error("Encountered error getting media remoting pref: "+JSON.stringify(chrome.runtime.lastError)):b.type!=chrome.settingsPrivate.PrefType.BOOLEAN?a.l.error("Pref value not a boolean: "+JSON.stringify(b)):(a.f=!!b.value,a.l.info("Initializing mediaRemotingEnabled_ with value read from pref: "+
  a.f));chrome.settingsPrivate.onPrefsChanged.hasListener(a.o)||chrome.settingsPrivate.onPrefsChanged.addListener(a.o);c()})})};
  $w.prototype.J=function(a){if(this.b){a=l(a);for(var c=a.next();!c.done;c=a.next())if(c=c.value,"media_router.media_remoting.enabled"==c.key){if(c.type!=chrome.settingsPrivate.PrefType.BOOLEAN){this.l.error("Pref value not a boolean: "+JSON.stringify(c));break}a=!!c.value;if(this.f==a)break;this.f=a;this.l.info("mediaRemotingEnabled_ changed to: "+this.f);if(this.f)this.b.onSinkAvailable(this.K);else this.b.onStopped(mojo.RemotingStopReason.USER_DISABLED);break}}};
  var Rda=function(a,c){var b=this,d=new mojo.RemotingSinkMetadata;d.features=[];d.friendly_name=c.nt||"";d.audio_capabilities=[];d.video_capabilities=[];var e=mojo.RemotingSinkAudioCapability,f=mojo.RemotingSinkVideoCapability,g=d.audio_capabilities,k=d.video_capabilities,m=c.ne||"";(a.b||[]).forEach(function(p){switch(p){case "audio":g.push(e.CODEC_BASELINE_SET);break;case "aac":g.push(e.CODEC_AAC);break;case "opus":g.push(e.CODEC_OPUS);break;case "video":k.push(f.CODEC_BASELINE_SET);break;case "4k":k.push(f.SUPPORT_4K);
  break;case "h264":k.push(f.CODEC_H264);break;case "vp8":k.push(f.CODEC_VP8);break;case "vp9":m.startsWith("Chromecast Ultra")&&k.push(f.CODEC_VP9);break;case "hevc":m.startsWith("Chromecast Ultra")&&k.push(f.CODEC_HEVC);break;default:b.l.info("Unknown mediaCap name: "+p)}});c.ne&&"Chromecast Ultra"==c.ne&&k.push(f.SUPPORT_4K);return d};$w.prototype.estimateTransmissionCapacity=$w.prototype.pq;$w.prototype.stop=$w.prototype.stop;$w.prototype.startDataStreams=$w.prototype.rt;$w.prototype.start=$w.prototype.start;
  $w.prototype.sendMessageToSink=$w.prototype.Ts;
  var Sda=function(){this.w=this.j=this.b=null;this.s=this.f=this.m=this.g=this.o=0;this.h=null},Vda=function(a){a.b=[];ex(a,performance.now())},Wda=function(a,c,b){a.j=c;a.w=b;a.b?(c=a.b,a.b=null,c.forEach(function(d){return cx(a,d.data).then(d.Vs,d.qn)})):ex(a,performance.now())},Xda=function(a){if(a.b){var c=Error("Stop before delivering pending message");a.b.forEach(function(b){return b.qn(c)});a.b=null}a.j=null;a.w=null},cx=function(a,c){if(a.j){var b=btoa(String.fromCharCode.apply(null,c));++a.o;
  a.g+=c.length;return a.j({type:"RPC",rpc:b})}return a.b?new Promise(function(d,e){a.b.push({data:c,Vs:d,qn:e})}):Promise.reject(Error("RPC pipe not started"))},Uda=function(a,c){dx(a);a.h=setInterval(function(){if(a.b)var b=a.b.length+" messages are waiting to send.";else{b=performance.now();var d=(b-a.s)/1E3;d="Over the past "+d.toFixed(1)+" seconds, sent "+(a.o+" messages ("+Math.round(a.g/d)+" bytes/sec) and received ")+(a.m+" messages ("+Math.round(a.f/d)+" bytes/sec).");ex(a,b);b=d}c(b)},3E4)},
  dx=function(a){null!=a.h&&(clearInterval(a.h),a.h=null)},ex=function(a,c){a.o=0;a.g=0;a.m=0;a.f=0;a.s=c};var Yda=function(a){return a&&a.getAudioTracks()&&0<a.getAudioTracks().length?a.getAudioTracks()[0]:null},Zda=function(a){return a&&a.getVideoTracks()&&0<a.getVideoTracks().length?a.getVideoTracks()[0]:null};var fx=function(a,c,b,d,e){this.g=new Ww(a,c,b,d,void 0===e?null:e);this.l=gb("mr.mirror.cast.MediaStreamer");this.j=new Pw;this.h=this.f=this.b=this.w=null};fx.prototype.start=function(a,c){var b=this;return Rw(this.j,1,function(d){b.w=a;b.b=Yda(a);b.b&&"ended"==b.b.readyState&&(b.b=null);b.f=Zda(a);b.f&&"ended"==b.f.readyState&&(b.f=null);if(!b.b&&!b.f)return Tw(d),Promise.reject(Error("No MediaStream tracks to stream."));b.h=c;return b.g.start(b.b,b.f,b.h).then(function(){return Tw(d,2)})})};
  fx.prototype.stop=function(){var a=this;return Sw(this.j,function(c){return a.g.stop().then(function(){a.b=null;a.f=null;a.w=null;a.h=null;Tw(c,1)})})};var $da=function(a){return Rw(a.j,2,function(c){a.l.info("Suspending media streaming...");return a.g.stop().then(function(){a.l.info("Suspended media streaming.");Tw(c,3)})})};
  fx.prototype.resume=function(){var a=this;return Rw(this.j,3,function(c){a.b&&"ended"==a.b.readyState&&(a.b=null);a.f&&"ended"==a.f.readyState&&(a.f=null);if(!a.b&&!a.f)return Promise.reject(Error("Cannot resume: All tracks have ended."));a.l.info("Resuming media streaming...");return a.g.start(a.b,a.f,a.h).then(function(){a.l.info("Resumed media streaming.");Tw(c,2)})})};var gx=function(a,c,b){this.j=a;this.h=c;this.g=b;this.l=gb("mr.mirror.cast.WifiStatusMonitor");this.b=null;this.f=[]};gx.prototype.start=function(){var a=this;null==this.b&&(nb(this.l,"Starting Wifi Status Monitoring."),this.f=[],this.g.subscribe("STATUS_RESPONSE",function(c){return aea(a,c)}),this.b=setInterval(function(){return hx(a)},12E4),hx(this))};gx.prototype.stop=function(){null!=this.b&&(nb(this.l,"Stopping Wifi Status Monitoring."),clearInterval(this.b),this.b=null,Nw(this.g,"STATUS_RESPONSE"))};
  var aea=function(a,c){if(null!=a.b)if(c.status){var b={};null!=c.status.b&&(b.wifiSnr=c.status.b);null!=c.status.f&&(b.wifiSpeed=c.status.f[3]);0==Object.keys(b).length?a.l.H(function(){return"No status fields populated in response: "+JSON.stringify(c)}):(b.timestamp=Date.now(),30==a.f.length&&a.f.shift(),a.f.push(b),a.l.info(function(){return"Current Wifi status: "+JSON.stringify(b)}))}else a.l.H(function(){return"Ignoring response without status: "+JSON.stringify(c)})},hx=function(a){a.g.sendMessage({type:"GET_STATUS",
  sessionId:a.j,seqNum:vn(a.h),get_status:["wifiSnr","wifiSpeed"]})};var ix=function(a,c,b,d){this.K=c.dg;this.m={extVersion:chrome.runtime.getManifest().version,extChannel:"public",mirrorSettings:zj(a),sender:navigator.userAgent||"UNKNOWN",receiverProductName:c.ne};this.F=b;this.C=d;this.h=this.f=this.o=this.w=this.j=this.s=this.g=null;this.b=[]};ix.prototype.wg=function(a){null!=this.f&&clearInterval(this.f);this.g=a;this.s=Date.now();this.f=setInterval(this.D.bind(this,a),9E5)};
  ix.prototype.jh=function(){null!=this.f&&(clearInterval(this.f),this.f=null);if(null!=this.g){var a=this.D(this.g);this.g=null;return a}return Promise.resolve()};ix.prototype.hf=function(a,c){null==this.j&&(this.j=Date.now(),"function"===typeof a?this.w=a():"string"===typeof a&&(this.w=a),c&&"string"===typeof c.stack&&(this.o=c.stack))};
  var bea=function(a,c){return(null==a.g?Promise.resolve():a.D(a.g)).then(function(){var b=c.map(function(d){d=jx(a,d);var e=d.map(function(g){return g.events}).filter(function(g){return null!=g}),f=["["];d.map(function(g){return g.fg}).forEach(function(g,k){0<k&&f.push(",");f.push(g)});f.push("]");return{events:new Blob(e,{type:"application/gzip"}),fg:new Blob(f,{type:"application/json"})}});a.b=[];return b})};
  ix.prototype.D=function(a){var c=this;if(null!=this.h)return this.h;var b=pf(this.K).then(function(d){d={receiverVersion:d.b,receiverConnected:d.h,receiverOnEthernet:d.f,receiverHasUpdatePending:d.g,receiverUptimeSeconds:d.j};Object.assign(d,c.m);var e=Date.now();Object.assign(d,{startTime:c.s,endTime:e,activity:Yw(a),receiverWifiStatus:Array.from(c.C.f)});c.s=e;null!=c.j&&(Object.assign(d,{streamingErrorTime:c.j,streamingErrorMessage:c.w,streamingErrorCause:c.o}),c.j=null,c.w=null,c.o=null);return d});
  return(this.h=Promise.all([b.then(function(d){return Oda(a,d)}),b,Pda(a)]).then(function(d){var e=l(d);d=e.next().value;var f=e.next().value;e=e.next().value;c.b.push({events:d,fg:new Blob([JSON.stringify(Object.assign({tags:f},e))],{type:"application/json"})});c.b=jx(c,c.F);c.h=null}))||Promise.resolve()};
  var jx=function(a,c){c-=2;for(var b=[],d=a.b.length-1;0<=d;--d){c-=a.b[d].fg.size+1;if(0>c)break;b.push({events:null,fg:a.b[d].fg});if(null!=a.b[d].events){var e=a.b[d].events.size;c>=e&&(b[b.length-1].events=a.b[d].events,c-=e)}}return b.reverse()};var kx=gb("mr.NetworkUtils"),lx=function(a,c){if(!Di)return Promise.reject("TDLS feature not enabled.");kx.info("setTDLSState_: ip="+a+", state="+c);return new Promise(function(b,d){chrome.networkingPrivate.setWifiTDLSEnabledState(a,c,function(e){chrome.runtime.lastError?(kx.H("Unable to set TDLS state: state = "+c+", error = "+chrome.runtime.lastError.message),d("Unable to set TDLS state to "+c+".")):(kx.info("TDLS state changed: state = "+c+", status = "+e),b(e))})})};var mx=function(a,c,b,d){d=void 0===d?null:d;wj.call(this,c);var e=c.wb;this.C=e.sessionId;this.J=e.dg;this.D=a;this.M=d;this.l=gb("mr.mirror.cast.Session");this.s=new Pw;this.o=new un("mirror.cast.SeqNumGenerator");this.m=new Mw(c.id);this.w=new fx(e,this.D,this.o,this.m,this.M);this.j=null;this.b=new ix(a,e,b,new gx(this.C,this.o,this.m));this.h=!1;this.F=null};q(mx,wj);h=mx.prototype;
  h.start=function(a){var c=this;return Rw(this.s,1,function(b){var d=yw();return cea(c).then(function(e){c.h=e;return c.w.start(a,c)}).then(function(){if(c.w.g.C){var e=c.b;e.m.tdlsIsOn=c.h;e.C.start();dea(c)}else c.b.m.tdlsIsOn=c.h;d.end();c.F=zw();Tw(b,2);return c})})};
  h.stop=function(){var a=this;return Sw(this.s,function(c){a.F&&(a.F.end(),a.F=null);a.b.C.stop();return a.w.stop().then(function(){return a.j?ax(a.j):Promise.resolve()}).then(function(){a.j=null;return a.h?eea(a):Promise.resolve()}).then(function(){a.h=!1;Tw(c,4)})})};
  h.nn=function(){var a=this,c={sessionId:this.C,seqNum:vn(this.o),type:"PRESENTATION",icons:[],title:uj(this.vc)};this.l.info("Sending session metadata update to receiver: "+this.C);this.m.sendMessage(c).catch(function(b){a.l.H("Failed to send activity to sink: "+b.message)})};h.wg=function(a){this.b.wg(a)};h.jh=function(){return this.b.jh()};h.hf=function(a,c){this.b.hf(a,c);this.l.error(a,c);this.stop()};
  var nx=function(a,c){return bea(a.b,c)},cea=function(a){a.l.info("maybeEnableTdls_: useTdls = "+a.D.useTdls);return a.D.useTdls?lx(a.J,!0).then(function(c){if("Connected"==c)return a.l.info("Successfully enabled TDLS."),!0;a.l.H("Did not enable TDLS: result="+c);return!1}).catch(function(c){a.l.H("Error while calling enableTDLS()",c);return!1}):Promise.resolve(!1)},eea=function(a){return lx(a.J,!1).catch(function(c){return a.l.error("Error while turning TDLS back off",c)})},dea=function(a){fea(a).then(function(c){(c.b||
  []).includes("video")?gea(a,c):a.l.H(function(){return"Receiver incapable of Media Remoting: "+JSON.stringify(c)})}).catch(function(c){a.l.H("None/Invalid capabilites response. Media Remoting disabled.",c)})},fea=function(a){return new Promise(function(c,b){var d={type:"GET_CAPABILITIES",sessionId:a.C,seqNum:vn(a.o)};a.l.info(function(){return"Sending GET_CAPABILITIES message: "+JSON.stringify(d)});Ow(a.m,d,"CAPABILITIES_RESPONSE",3E4,function(e,f){if(null==e)return b(f),!0;if("ok"!=e.result||!e.capabilities)return b(Error("Bad response: "+
  JSON.stringify(e))),!0;if(e.f!=d.seqNum)return a.l.info(function(){return"Ignoring CAPABILITIES_RESPONSE with different seqNum: "+JSON.stringify(e)}),!1;nb(a.l,function(){return"Received CAPABILITIES_RESPONSE: "+JSON.stringify(e)});c(e.capabilities);return!0})})},gea=function(a,c){Rw(a.s,2,function(b){var d=a.f.wb.ne||"<UNKNOWN>";if(!d.startsWith("Chromecast")&&!d.startsWith("Eureka Dongle"))return a.l.H('HACK: Media Remoting disabled because the receiver model--"'+(d+'" according to discovery--is not a Chromecast.')),
  Tw(b),Promise.resolve();a.j=new $w(a.f,c,a.D,a.o,a.m,a.M);return a.j.initialize(a.T.bind(a),a).catch(function(e){a.l.error("Media Remoting start failed: "+e.message,e)}).then(function(){return Tw(b)})})};mx.prototype.T=function(){var a=this;return Rw(this.s,2,function(c){return new Promise(function(b,d){$da(a.w).then(function(){Tw(c,3);a.K=!0;nj(a);b(a.V.bind(a))}).catch(function(e){a.hf("Failed to suspend MediaStreamer before starting remoting",e);d(e)})})})};
  mx.prototype.V=function(){var a=this;return Rw(this.s,3,function(c){return new Promise(function(b,d){a.w.resume().then(function(){Tw(c,2);a.K=!1;nj(a);b()}).catch(function(e){a.hf("Failed resume MediaStreamer after ending remoting mode",e);d(e)})})})};var ox=function(){lj.call(this,"cast_streaming");this.w=this.s=this.K=this.F=this.h=null;this.jb=this.G="";this.da=this.o=!1;this.ha=this.ra.bind(this);this.J=this.M=this.T=this.V=this.j=null};q(ox,lj);h=ox.prototype;h.yg=function(a){this.o=a||!1;this.da=!0};h.getName=function(){return"cast_streaming"};
  h.Ej=function(a,c,b,d,e){var f=this;if(!this.o)return lj.prototype.Ej.call(this,a,c,b,d,e);this.R.info("Start mirroring on route "+a.id);if(!this.da)return wi(Error("Not initialized"));var g=new Promise(function(k,m){f.m().then(function(){if(gj(c)&&b.shouldCaptureVideo)return Qi(!1).then(function(p){f.jb=p})}).then(function(){return e?e(a).b:a}).then(function(p){f.G=c;hea(f,p);var u=f.F.createInterfacePtrAndBind(),A=f.K.createInterfacePtrAndBind(),F=iea(p,b);jea(f,p,c,d);if(!f.h)throw new Ai("Error to get mirroring service host");
  f.s=new mojo.MirroringCastMessageChannelPtr;f.V=yw();f.h.start(F,u,A,mojo.makeRequest(f.s));f.j=new wj(a,f.g.Si.bind(f.g));nj(f.j);kea(f,p,c);f.M=function(){return k(p)};f.J=m}).catch(function(p){f.R.info("Mirroring launch error: "+p);f.Zf(p.reason);m(p)})});return xi(g)};h.xh=function(a,c){return new mx(a,c,20969472,null)};h.eh=function(){Aw(0)};h.ah=function(){Aw(1)};h.Yh=function(){Aw(2)};h.bh=function(){Ab("MediaRouter.CastStreaming.Session.End")};
  h.Zf=function(a){Bb("MediaRouter.CastStreaming.Start.Failure",a,zi)};h.dh=function(){Ab("MediaRouter.CastStreaming.Stream.End")};
  h.wi=function(a){var c=this;return this.o?Promise.resolve():(new Promise(function(b){return chrome.metricsPrivate.getIsCrashReportingEnabled(b)})).then(function(b){var d=b&&uda(),e=[9351424];d&&e.push(20969472);return nx(a,e).then(function(f){var g=f[f.length-1];f=pm(f[0].events).catch(function(k){c.R.error("Failed to persist events Blob.",k)});d&&0<g.events.size?Dw(g.events,void 0,c.Dr.bind(c)):b&&Cw("stats.json",g.fg,void 0,void 0);return f})})};h.Dr=function(a){a&&(Gw().b=Date.now())};
  h.Dj=function(a){if(this.o)return cb();this.R.info("Received message to upload logs for "+a);return this.b?nx(this.b,[20969472]).then(function(c){c=l(c).next().value;return 0==c.events.size?"":Dw(c.events,a)}):Promise.resolve(lea(this,a))};
  var lea=function(a,c){var b=window.localStorage.getItem("mr.temp.mirror.cast.Service.eventsBlob");if(null==b||1>b.length)b=null;else{for(var d=new Uint16Array(b.length),e=0;e<b.length;++e)d[e]=b.charCodeAt(e);b=d.buffer;d=(new Uint8Array(b,b.byteLength-1,1))[0];b=new Uint8Array(b,0,b.byteLength-(0==d?2:1));b=new Blob([b],{type:"application/gzip"})}if(null!=b&&0!=b.size)return pm(new Blob),a.R.info("Uploading saved logs for feedback."),Dw(b,c)};h=ox.prototype;
  h.onError=function(a){this.J&&(this.J(a),this.M=this.J=null,this.Zf(9));this.R.info("Mirroring service error: "+a);this.m()};h.didStart=function(){this.M&&(this.M(),this.M=this.J=null);this.V&&(this.V.end(),this.V=null);this.T=zw();fj(this.G)?this.eh():gj(this.G)?this.ah():ij(this.G)&&this.Yh()};h.didStop=function(){this.m()};h.send=function(a){if(this.w){var c=JSON.parse(a.jsonFormatData);nb(this.R,function(){return"Sending message: "+JSON.stringify(c)});this.w.sendMessage(a.jsonFormatData,{namespace:a.messageNamespace})}};
  h.Er=function(a){if(a&&(a.namespace_===mojo.MirroringWebRtcNamespace||a.namespace_===mojo.MirroringRemotingNamespace)&&this.s){var c=new mojo.MirroringCastMessage;c.messageNamespace=a.namespace_;"string"!==typeof a.data?this.R.info("Received non-string as JSON"):(c.jsonFormatData=a.data,this.s.send(c))}};
  var hea=function(a,c){a.F=new mojo.Binding(mojo.MirroringSessionObserver,a,null);a.K=new mojo.Binding(mojo.MirroringCastMessageChannel,a,null);a.w=Rv(c.id);a.w.onMessage=a.Er.bind(a)},iea=function(a,c){var b=new mojo.MirroringSessionParameters;b.receiverAddress=new mojo.IPAddress;b.receiverAddress.addressBytes=a.wb.dg.split(".").map(function(d){return parseInt(d,10)});b.receiverModelName=a.wb.ne;b.type=c.shouldCaptureVideo&&c.shouldCaptureAudio?mojo.MirroringSessionType.AUDIO_AND_VIDEO:c.shouldCaptureVideo?
  mojo.MirroringSessionType.VIDEO_ONLY:mojo.MirroringSessionType.AUDIO_ONLY;return b},jea=function(a,c,b,d){a.h=new mojo.MirroringServiceHostPtr;c=c.wb.tabId||-1;fj(b)?a.g.getMirroringServiceHostForTab(c,mojo.makeRequest(a.h)):gj(b)?a.g.getMirroringServiceHostForDesktop(-1,a.jb,mojo.makeRequest(a.h)):ij(b)?(c=new mojo.Url,c.url=b,a.g.getMirroringServiceHostForOffscreenTab(c,d||"",mojo.makeRequest(a.h))):a.h=null},kea=function(a,c,b){fj(b)&&!chrome.tabs.onUpdated.hasListener(a.ha)&&chrome.tabs.onUpdated.addListener(a.ha);
  (fj(b)||ij(b))&&qj(a.j,c.wb.tabId)};ox.prototype.ra=function(a,c,b){ej(14);this.j&&rj(this.j,a,c,b)};
  ox.prototype.m=function(){chrome.tabs.onUpdated.removeListener(this.ha);return this.o?this.da?this.h?(this.h.ptr.reset(),this.s=this.h=null,this.w&&this.w.lb(),this.w=null,this.F&&(this.F.close(),this.F=null),this.K&&(this.K.close(),this.K=null),this.g.Vh(this.j.f.id),this.j=null,this.jb=this.G="",this.T&&(this.T.end(),this.T=null),this.bh(),Promise.resolve(!0)):Promise.resolve(!1):Promise.reject("Not initialized"):lj.prototype.m.call(this)};
  ox.prototype.Fj=function(a,c,b,d,e,f){return this.o?wi(Error("Mirroring service does not support updating stream")):lj.prototype.Fj.call(this,a,c,b,d,e,f)};ox.prototype.send=ox.prototype.send;ox.prototype.didStop=ox.prototype.didStop;ox.prototype.didStart=ox.prototype.didStart;ox.prototype.onError=ox.prototype.onError;var mea=new ox;bj("mr.mirror.cast.Service",mea);
  