'use strict';var wE=/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/,xE=[4278190080,4293918720,4294901760],yE=[167772160,2886729728,3232235520],zE=function(a){var b=document.createElement("a");b.href=a;return b};var BE=function(a,b,c,d){b="["+b+"]: "+c+" "+d.responseURL+" => "+d.status+" ("+d.statusText+")";AE(d)?x(a,b):z(a,b)},AE=function(a){return 200<=a.status&&299>=a.status},CE=function(a){a=(new DOMParser).parseFromString(a,"text/xml");return a.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","parsererror").length?null:a};var DE=function(){this.name="unknown";this.state="error";this.a=null;this.allowStop=!0;this.resource=null;this.extraData={}},EE=function(){var a;a=Error.call(this);this.message=a.message;"stack"in a&&(this.stack=a.stack)};ka(EE,Error);var GE=function(a,b){void 0===b&&(FE||(FE=new ze(10,2E3,1)),b=FE);this.b=a;this.a=b;this.j=v("mr.dial.Client")};
GE.prototype.launchApp=function(a,b){var c=this;return this.a.send(HE(this,a),"POST",b,{timeoutMillis:15E3}).then(function(a){return IE(c,"launchApp","POST",a)})};
var JE=function(a,b){return a.a.send(HE(a,b),"DELETE").then(function(b){return IE(a,"stopApp","DELETE",b)})},KE=function(a,b){return a.a.send(HE(a,b),"GET",void 0,{bh:3}).then(function(c){BE(a.j,"GetAppInfo","GET",c);if(!AE(c)){if(404==c.status)throw new EE;throw Error("Response error: "+c.status);}c=CE(c.responseText);if(!c)throw x(a.j,"Invalid or empty response"),Error("Invalid or empty response");var d=c.getElementsByTagName("service");if(!d||1!=d.length)throw x(a.j,"Invalid GET response (invalid service)"),
Error("Invalid GET response (invalid service)");c=new DE;for(var e=0,f=d[0].childNodes.length;e<f;e++){var g=d[0].childNodes[e];if("state"==g.nodeName){a:switch(g.textContent){case "running":g="running";break a;case "stopped":g="stopped";break a;default:g="error"}c.state=g}else"name"==g.nodeName?c.name=g.textContent:"link"==g.nodeName?c.resource=g.getAttribute("href"):"options"==g.nodeName?c.allowStop="false"!=g.getAttribute("allowStop"):c.extraData[g.nodeName]=g.innerHTML}if("unknown"==c.name)throw x(a.j,
"GET response missing name value"),Error("GET response missing name value");if(c.name!=b)throw x(a.j,"GET app name mismatch"),Error("GET app name mismatch");if("error"==c.state)throw x(a.j,"GET response missing state value"),Error("GET response missing state value");if((d=/installable=(.+)/.exec(c.state))&&d[1])c.state="installable",c.a=d[1];else if("running"!=c.state&&"stopped"!=c.state)throw x(a.j,"GET response has invalid state value"),Error("GET response has invalid state value");return c})},
HE=function(a,b){a=a.b.Pb;"/"!=a.charAt(a.length-1)&&(a+="/");return a+b},IE=function(a,b,c,d){return new Promise(function(e,f){BE(a.j,b,c,d);AE(d)?e():f(Error(d.statusText))})},FE=null;var LE=function(a,b){this.appName=a;this.launchParameter=void 0===b?"":b},NE=function(a){if(a.startsWith("urn:dial-multiscreen-org:dial:application:")){var b=a.indexOf("?"),c=a.substring(42,0<b?b:void 0);a=c&&0<c.length?new LE(c,0<b?a.substring(b+1):void 0):null}else a=ME(a);return a},ME=function(a){var b=(new mm(a)).f;if(!b)return null;a=(a=OE.exec(b))?a[1]:null;if(!a)return null;a=decodeURIComponent(a);if(b=(b=PE.exec(b))?b[1]:void 0)try{b=ik(b)}catch(c){return w(QE,"Invalid base64 encoded postData:"+
b),null}return new LE(a,b)},QE=v("mr.dial.MediaSource"),OE=/__dialAppName__=([A-Za-z0-9-._~!$&'()*+,;=%]+)/,PE=/__dialPostData__=([A-Za-z0-9]+={0,2})/;var RE=function(a,b){this.qb=a;this.appName=b};var SE=function(a){this.a=new Map;this.b=a};SE.prototype.init=function(){Xh(this)};SE.prototype.clear=function(){this.a.clear()};SE.prototype.add=function(a){if(!this.a.get(a.qb.id)){this.a.set(a.qb.id,a);var b=this.b;TE(b);b.g.ic(b,a.qb)}};var UE=function(a,b){a=ja(a.a);for(var c=a.next();!c.done;c=a.next())if(c=ja(c.value),c.next(),c=c.next().value,c.qb.sinkId==b)return c;return null},WE=function(a,b){var c=a.a.get(b);c&&(a.a.delete(b),VE(a.b,c))},XE=function(a){return Array.from(a.a.values(),function(a){return a.qb})};
SE.prototype.ea=function(){return"dial.ActivityRecords"};SE.prototype.pa=function(){return[Array.from(this.a)]};SE.prototype.ua=function(){var a=Uh(this);a&&(this.a=new Map(a))};var YE={en:0,Xp:1,Uo:2,dn:3},ZE={ERROR:0,op:1,EMPTY:2},$E=function(a){Cg("MediaRouter.Dial.Create.Route",a,YE)};var aF=function(){this.a=this.modelName=this.deviceType=this.expireTimeMillis=this.fetchTimeMillis=this.appUrl=this.ipAddress=this.friendlyName=this.deviceLabel=this.uniqueId=null},bF=function(a){var b;a.deviceLabel?a.uniqueId?a.friendlyName?a.ipAddress?a.appUrl?a.fetchTimeMillis?a.expireTimeMillis?(b=a.ipAddress,a=zE(a.appUrl),b="http:"==a.protocol&&a.hostname==b?null:"Invalid appUrl"):b="Missing expireTimeMillis":b="Missing fetchTimeMillis":b="Missing appUrl":b="Missing ipAddress":b="Missing friendlyName":
b="Missing uniqueId":b="Missing deviceLabel";return b};aF.prototype.toString=function(){return JSON.stringify(this,function(a,b){return va(b)&&0==b.indexOf("uuid:")?"***":b})};
var cF=function(a){var b=new aF;b.uniqueId=a.uniqueId;b.deviceLabel=a.deviceLabel;b.friendlyName=a.friendlyName;b.ipAddress=a.ipAddress;b.appUrl=a.appUrl;b.fetchTimeMillis=a.fetchTimeMillis;b.expireTimeMillis=a.expireTimeMillis;b.deviceType=a.deviceType;b.modelName=a.modelName;b.a=a.configId;return b},eF=function(a){void 0===a&&(dF||(dF=new ze(10,3E3,2)),a=dF);this.a=new Map;this.b=new Map;this.f=new Map;this.g=a;this.j=v("mr.dial.DeviceDescriptionService");Xh(this)};eF.prototype.ea=function(){return"mr.dial.DeviceDescriptionService"};
eF.prototype.pa=function(){return[Array.from(this.a)]};eF.prototype.ua=function(){var a=Uh(this);if(a)for(var a=ja(a),b=a.next();!b.done;b=a.next()){var c=ja(b.value),b=c.next().value,c=c.next().value;null!=bF(cF(c))?this.j.error("Dropping invalid description "+b+" loaded from storage."):this.a.set(b,cF(c))}};
var gF=function(a,b){var c;if(c=a.a.get(b.deviceLabel)){if(c.a!=b.configId||Date.now()>=c.expireTimeMillis)z(a.j,"Removing invalid entry "+c.toString()),a.a.delete(b.deviceLabel),c=null}else c=null;return c?(Bg("MediaRouter.Dial.Device.Description.Cached"),Promise.resolve(c)):fF(a,b)},fF=function(a,b){if(!hF(b.deviceDescriptionUrl))return Promise.reject(Error("Invalid device description URL: "+b.deviceDescriptionUrl));var c=a.b.get(b.deviceLabel);if(c&&c.deviceDescriptionUrl==b.deviceDescriptionUrl)return c.wa.a;
var d=new Qc,c={deviceDescriptionUrl:b.deviceDescriptionUrl,wa:d};a.b.set(b.deviceLabel,c);chrome.dial.fetchDeviceDescription(b.deviceLabel,function(c){a.b.delete(b.deviceLabel);c?((c=iF(a,b,c.deviceDescription,c.appUrl))?(x(a.j,"Got device description for "+c.deviceLabel),z(a.j,"... device description was: "+c.toString()),null!=c.a&&(z(a.j,"Caching device description for "+c.deviceLabel),a.a.set(b.deviceLabel,c))):(Cg("MediaRouter.Dial.Device.Description.Failure",1,ZE),x(a.j,"Invalid device description"),
c=null),c?d.resolve(c):d.b(Error("Failed to process device description"))):(c=An("chrome.dial.fetchDeviceDescription"),d.b(c))});return d.a},iF=function(a,b,c,d){var e=CE(c);if(!e)return null;var f=new aF;f.fetchTimeMillis=Date.now();f.expireTimeMillis=f.fetchTimeMillis+18E5;f.deviceLabel=b.deviceLabel;f.a=b.configId;b=zE(b.deviceDescriptionUrl);f.ipAddress=b.hostname;f.deviceType=jF(e,"deviceType");f.modelName=jF(e,"modelName");f.friendlyName=jF(e,"friendlyName");f.uniqueId=jF(e,"UDN");!f.friendlyName&&
f.modelName&&(f.friendlyName=f.modelName,f.uniqueId&&(f.friendlyName+="["+f.uniqueId.slice(-4)+"]"),w(a.j,"Fixed device description: created friendlyName from modelName."));f.appUrl=d;d=bF(f);z(a.j,function(){return"Device description: "+kF(e)});return d?(w(a.j,function(){return"Device description failed to validate: "+f},d),null):f},jF=function(a,b){return(a=a.getElementsByTagName(b))&&0!=a.length?a[0].textContent:null},kF=function(a){var b=function(a){for(var b=0,c=a.length;b<c;b++)a[b].textContent=
"***"};b(a.getElementsByTagName("UDN"));b(a.getElementsByTagName("serialNumber"));return(new XMLSerializer).serializeToString(a)},lF=function(a,b){var c=a.f.get(b);if(c)return c.a;c=new Qc;a.f.set(b,c);a.g.send(b,"GET").then(function(d){a.f.delete(b);BE(a.j,"checkAccess","GET",d);c.resolve(AE(d))},function(){a.j.error("Timed out checking access to device description URL.");c.resolve(!1)});return c.a},hF=function(a){a=zE(a);var b;if(b="http:"==a.protocol)a:{b:if((a=a.hostname.match(wE))&&5==a.length){b=
[];for(var c=0;4>c;c++)if(b[c]=Number.parseInt(a[c+1],10),0>b[c]||255<b[c]){a=null;break b}a=b}else a=null;if(a)for(a=(a[0]<<24|a[1]<<16|a[2]<<8|a[0])>>>0,b=0;3>b;b++)if((a&xE[b])>>>0==yE[b]){b=!0;break a}b=!1}return b},dF=null;var mF=null,nF=null,oF=function(){mF||(mF=new Jk(3,"dial.DialOnDeviceListEventListener","mr.dial.SinkDiscoveryService",chrome.dial.onDeviceList));nF||(nF=new Jk(4,"dial.DialOnErrorEventListener","mr.dial.SinkDiscoveryService",chrome.dial.onError));return[mF,nF]};var pF=function(a,b){b=void 0===b?new eF:b;this.f=a;this.m=b;this.j=v("mr.dial.SinkDiscoveryService");this.a=new Map;this.l=this.h=!1;this.b={xc:0,Mc:0};this.g=0};ka(pF,Vg);pF.prototype.init=function(){Xh(this);eh("mr.dial.SinkDiscoveryService",this)};pF.prototype.start=function(){this.h||(x(this.j,"Starting..."),this.h=!0,oF().forEach(function(a){return a.addListener()}),qF(this))};var qF=function(a){a.h?chrome.dial.discoverNow(function(b){x(a.j,"chrome.dial.discoverNow = "+b)}):x(a.j,"Not started. Ignoring discover().")};
pF.prototype.w=function(a){var b=this;x(this.j,"onDeviceList returned "+a.length+" devices");z(this.j,function(){return"....the list is: "+JSON.stringify(a)});this.l=!1;var c=0,d=[],e=new Set;a.forEach(function(a){d.push(rF(b,a).then(function(a){e.add(a.getId());sF(b,a)},function(){c++}))});Sk(d).then(function(){b.l||tF(b,e).then(function(){var a=b.a.size;uF(b,a,a+c)})})};
var uF=function(a,b,c){a.b={xc:b,Mc:c};36E5>Date.now()-a.g||(b=a.b,Dg("MediaRouter.Dial.AvailableDevicesCount",b.xc),Dg("MediaRouter.Dial.KnownDevicesCount",b.Mc),a.g=Date.now())},sF=function(a,b){if(!a.l){z(a.j,"mayAddSink, id = "+b.getId());var c=a.a.get(b.getId());c?c.update(b)&&(z(a.j,"Updated sink "+c.getId()),a.f.Oc(c)):(z(a.j,function(){return"Adding new sink "+b.getId()+": "+("name = "+b.Za.friendlyName+(b.fb?", ip = "+b.fb:"")+(b.gb?", model = "+b.gb:"")+", apps = "+JSON.stringify(b.eb))}),
a.a.set(b.getId(),b),a.f.xd(b))}},tF=function(a,b){var c=[],d=[];a.a.forEach(function(e){b.has(e.getId())||d.push((e.Fb?lF(a.m,e.Fb):Promise.resolve(!1)).then(function(b){b||(a.a.delete(e.getId()),c.push(e))}))});return Sk(d).then(function(){0<c.length&&a.f.Pc(c)})},rF=function(a,b){return gF(a.m,b).then(function(a){var c;a.uniqueId?(c=a.uniqueId,0==c.indexOf("uuid:")&&(c=c.substr(5)),c=c.replace(/-/g,"").toLowerCase()):c="";var e=c;c=a.uniqueId?pk(ok.S(),e):b.deviceLabel;var f=vF.test(a.modelName),
e=new rk(a.friendlyName,e);e.Za.id=c;e.fb=a.ipAddress;e.Pb=a.appUrl;e.Fb=b.deviceDescriptionUrl;e.gb=a.modelName;e.Xb=!f;return e})};
pF.prototype.v=function(a){switch(a.code){case "no_valid_network_interfaces":case "network_disconnected":w(this.j,"DIAL error: "+a.code+". Clear device list now.");a=Array.from(this.a.values());this.a.clear();this.f.Pc(a);uF(this,0,0);this.l=!0;break;case "no_listeners":case "socket_error":case "cellular_network":case "unknown":w(this.j,"DIAL error: "+a.code+". Keep device list.");break;default:w(this.j,"Unhandled DIAL error: "+a.code)}};
var wF=function(a,b){return a.a.get(b)||null},yF=function(a,b){var c=[];a.a.forEach(function(a){"available"==sk(a,b)&&c.push(a.Za)});a=xF[b];return new ko(c,a?[a]:void 0)};h=pF.prototype;h.Fg=function(){return this.b};h.handleEvent=function(a,b){for(var c=[],d=1;d<arguments.length;++d)c[d-1]=arguments[d];if(a==chrome.dial.onDeviceList)this.w.apply(this,[].concat(la(c)));else if(a==chrome.dial.onError)this.v.apply(this,[].concat(la(c)));else throw Error("Unhandled event");};h.ea=function(){return"dial.DialSinkDiscoveryService"};
h.pa=function(){return[new zF(Array.from(this.a),this.b),{deviceCountMetricsRecordTime:this.g}]};h.ua=function(){var a=Uh(this);if(a){for(var b=ja(a.sinks),c=b.next();!c.done;c=b.next())c=c.value,this.a.set(c[0],tk(c[1]));this.b=a.deviceCounts}if(a=Vh(this))this.g=a.deviceCountMetricsRecordTime};
var xF={YouTube:"https://www.youtube.com",Netflix:"https://www.netflix.com",Pandora:"https://www.pandora.com",Radio:"https://www.pandora.com",Hulu:"https://www.hulu.com",Vimeo:"https://www.vimeo.com",Dailymotion:"https://www.dailymotion.com","com.dailymotion":"https://www.dailymotion.com"},vF=/Eureka Dongle|Chromecast Audio/i,zF=function(a,b){this.sinks=a;this.deviceCounts=b};var AF=function(a,b){this.j=v("mr.dial.AppDiscoveryService");this.a=new Set;this.b=a;this.h=b;this.l=new Map;this.m=new Map;this.f=null;this.g=!1};AF.prototype.init=function(){Xh(this)};AF.prototype.start=function(){x(this.j,"Starting periodic scanning.");this.g||(this.g=!0,BF(this))};AF.prototype.stop=function(){x(this.j,"Stopping periodic scanning.");this.g&&(this.g=!1,this.f&&(clearTimeout(this.f),this.f=null),this.l.clear())};
var BF=function(a){x(a.j,"Start app status scan.");var b=[];Array.from(a.b.a.values()).forEach(function(c){b.push.apply(b,CF(a,c))});Array.from(a.h.a.values()).forEach(function(c){b.push(DF(a,c))});Sk(b).then(function(){a.g&&!a.f&&(z(a.j,"Scan complete; scheduling for next scan."),a.f=setTimeout(function(){z(a.j,"Start app status scan (timer-based)");a.f=null;BF(a)},6E4))})},CF=function(a,b){if(!b.Xb)return[];for(var c=[],d=ja(a.a),e=d.next();!e.done;e=d.next())c.push(a.w(e.value,b));return c};
AF.prototype.w=function(a,b){var c=this;if("unknown"!=sk(b,a)&&36E5>Date.now()-(b.Vd[a]||0)||!b.Xb)return Promise.resolve();z(this.j,"Querying "+b.getId()+" for "+a+" to update app status");return EF(this,b,a).then(function(d){a:if("Netflix"==d.name)d=!d.extraData||"websocket"!=d.extraData.capabilities||"running"!=d.state&&"stopped"!=d.state?"unavailable":"available";else switch(d.state){case "running":case "stopped":d="available";break a;default:d="unavailable"}FF(c,b,a,d)},function(d){d instanceof
EE?FF(c,b,a,"unavailable"):(w(c.j,"Failed to process app availability; "+b.getId()+" does not support app availability"),b.Xb=!1)})};
var DF=function(a,b){var c=wF(a.b,b.qb.sinkId);if(!c)return w(a.j,"Activity refers to nonexistent sink: "+b.qb.id),Promise.resolve();if(!c.Xb)return Promise.resolve();var d=b.appName;z(a.j,"Querying "+c.getId()+" for "+d+" to update activity");return EF(a,c,d).then(function(b){"running"!=b.state&&GF(a,c,d)},function(){return GF(a,c,d)})},HF=function(a,b){var c=a.m.get(b.getId());c||(c=new GE(b),z(a.j,"Created DIAL client for "+b.getId()),a.m.set(b.getId(),c));return c},EF=function(a,b,c){var d=IF(b,
c),e=a.l.get(d);if(e)return e;e=KE(HF(a,b),c);a.l.set(d,e);b=function(){a.l.delete(d)};e.then(b,b);return e},IF=function(a,b){return a.getId()+":"+b},FF=function(a,b,c,d){z(a.j,"Got app status "+d+" from "+b.getId()+" for "+c);var e=sk(b,c);b.eb[c]=d;b.Vd[c]=Date.now();d!=e&&a.b.f.Oc(b)},GF=function(a,b,c){(b=UE(a.h,b.getId()))&&b.appName==c&&WE(a.h,b.qb.id)},JF=function(a,b){return Array.from(a.b.a.values()).some(function(a){return"unknown"==sk(a,b)})};AF.prototype.ea=function(){return"dial.AppDiscoveryService"};
AF.prototype.pa=function(){return[Array.from(this.a)]};AF.prototype.ua=function(){var a=Uh(this);this.a=new Set(a||[])};var KF=function(a,b,c){this.g=a;this.a=b||new pF(this);this.b=new SE(this);this.f=c||new AF(this.a,this.b);this.j=v("mr.DialProvider")};h=KF.prototype;h.getName=function(){return"dial"};h.Ga=function(){this.b.init();this.a.init();this.a.start();this.f.init();TE(this)};h.pd=function(a){z(this.j,"GetAvailableSinks for "+a);return(a=NE(a))?yF(this.a,a.appName):lo};
h.startObservingMediaSinks=function(a){var b=NE(a);if(b){a=this.f;b=b.appName;if(!a.a.has(b)||JF(a,b))a.a.add(b),0!=a.b.a.size&&(a.g?Array.from(a.b.a.values()).forEach(a.w.bind(a,b)):a.start());TE(this)}};h.stopObservingMediaSinks=function(a){if(a=NE(a))this.f.a.delete(a.appName),LF(this)};h.startObservingMediaRoutes=function(){TE(this)};h.stopObservingMediaRoutes=function(){LF(this)};
var LF=function(a){(0==a.a.a.size||0==a.f.a.size&&0==a.b.a.size)&&a.f.stop()},TE=function(a){0<a.a.a.size&&(0<a.f.a.size||0<a.b.a.size)&&a.f.start()};h=KF.prototype;h.wd=function(a){return(a=wF(this.a,a))?a.Za:null};h.fc=function(){return XE(this.b)};
h.createRoute=function(a,b,c,d){var e=this,f=wF(this.a,b);if(!f)return $E(0),eg(Error("Unkown sink: "+b));ok.S().b=new nk(f.gb,f.Ea());var g=NE(a);if(!g)return eg(Error("No app name set."));var m=g.appName,q=new GE(f);return fg(KE(q,m).then(function(a){if("running"==a.state)return JE(q,m)}).then(function(){return q.launchApp(m,g.launchParameter)}).then(function(){return MF(e,b,a,m,c,d)}).catch(function(a){$E(3);throw a;}))};h.joinRoute=function(){return eg(Error("Not supported"))};
h.connectRouteByRouteId=function(){return eg(Error("Not supported"))};h.detachRoute=function(){};var MF=function(a,b,c,d,e,f){$E(1);b=Ej(e,a.getName(),b,c,!0,d,null);b.offTheRecord=f;a.b.add(new RE(b,d));return b};KF.prototype.xd=function(a){this.g.onSinkAvailabilityUpdated(this,1);TE(this);CF(this.f,a);this.g.Bb();ok.S().a=new nk(a.gb,a.Ea())};
KF.prototype.Pc=function(a){var b=this;if(0==this.a.a.size)this.g.onSinkAvailabilityUpdated(this,0);LF(this);a.forEach(function(a){var c=b.b;a=a.getId();if(a=UE(c,a))c.a.delete(a.qb.id),VE(c.b,a)});this.g.Bb()};KF.prototype.Oc=function(){this.g.Bb()};var VE=function(a,b){b=b.qb;if(b.isLocal)a.g.onPresentationConnectionStateChanged(b.id,"terminated");LF(a);a.g.Rc(a,b)};h=KF.prototype;
h.terminateRoute=function(a){var b=this.b.a.get(a)||null;if(!b)return Promise.reject(new jo(3,"Route in DIAL provider not found for routeId "+a));WE(this.b,a);return(a=wF(this.a,b.qb.sinkId))?JE(new GE(a),b.appName):Promise.reject(new jo(3,"Sink in DIAL provider not found for sinkId "+b.qb.sinkId))};h.Gc=function(){return null};h.Fc=function(){return null};h.sendRouteMessage=function(){return Promise.reject(Error("DIAL sending messages is not supported"))};h.sendRouteBinaryMessage=function(){return Promise.reject(Error("DIAL sending messages is not supported"))};
h.hd=function(a,b){b=wF(this.a,b);return!b||Rg(a)?!1:(a=NE(a))?"available"==sk(b,a.appName):!1};h.yc=function(){return!1};h.searchSinks=function(){return Fc()};h.createMediaRouteController=function(){return Fc()};h.setMediaRouteStatusObserver=function(){};h.provideSinks=function(){};var NF=function(a,b){this.f=a;this.b=b;this.a=this.f.a;this.j=v("mr.cast.CastDialSinkDiscoveryCallbacks")},OF=function(a,b){var c=a.a.b(b.getId());if(c)return c;(b=b.Ea())?(a=a.a,c=ok.S().f||8009,a=a.m.get(b+":"+c)):a=null;return a};NF.prototype.xd=function(a){OF(this,a)?Hk(2):PF(this,a);this.b.xd(a)};var PF=function(a,b){var c=wk(b);c&&al(a.a,c).then(function(d){d?OF(a,b)?Hk(2):(bl(a.a,c),Hk(0)):Bg("MediaRouter.Dial.Sink.Discovered.NonCast")},pa)};
NF.prototype.Pc=function(a){var b=this;t(a,function(a){var c=b.a.b(a.getId());c&&c.Rb&&cl(b.a,a.getId())});this.b.Pc(a)};NF.prototype.Oc=function(a){var b=this.a.b(a.getId());b?b.Rb&&(b.update(a.Za.friendlyName,a.Ea(),b.ta(),b.a)&&x(this.j,"Updated Cast sink with DIAL sink: "+a.getId()),el(this.a.g,b)):PF(this,a);this.b.Oc(a)};var QF=function(a,b){this.m=new pF(new NF(b,this));this.f=new C;this.b=a;this.h=this.l=0;this.g=new zi;this.a=new KF(this,this.m)};h=QF.prototype;h.ea=function(){return"cast.DialProviderWrapper"};h.pa=function(){return[new RF(qi(this.f),this.l,this.h,this.g.P())]};h.ua=function(){var a=Uh(this);a&&(mi(this.f,a.b),this.l=a.sequenceNumber,this.h=a.f,yi(this.g,a.a))};h.getName=function(){return this.a.getName()};h.Ga=function(){this.a.Ga();Xh(this)};h.fc=function(){return this.a.fc()};h.hh=function(){};
h.pd=function(a){return this.a.pd(a)};h.startObservingMediaSinks=function(a){this.a.startObservingMediaSinks(a)};h.stopObservingMediaSinks=function(a){this.a.stopObservingMediaSinks(a)};h.startObservingMediaRoutes=function(a){this.a.startObservingMediaRoutes(a)};h.stopObservingMediaRoutes=function(a){this.a.stopObservingMediaRoutes(a)};h.wd=function(a){return this.a.wd(a)};
var TF=function(a,b,c,d,e){var f=NE(b),g=wF(a.m,c);if(!g)return Promise.reject(Error("Attempting custom launch with closed route"));var m=f.appName;if(!m)return Promise.reject(Error("No app name given"));var q=Lm(b);return q?KE(new GE(g),m).then(function(y){var D=MF(a.a,c,b,m,e,d);y={routeId:D.id,sinkId:g.getId(),appName:m,ng:y,launchParameter:f.launchParameter,session:null,clientId:null};a.f.set(D.id,y);var T=SF(a,y.sinkId),ea=new em("receiver_action",{receiver:T,action:chrome.cast.gd.CAST});ea.clientId=
q;a.b.Jb(a,y.routeId,ea);var ea=chrome.cast.L,wa=String(a.h);a.h=(a.h+1)%9007199254740992;T=new ea(wa,"",y.appName,[],T);y.session=T;y.clientId=q;T=new em("new_session",T);T.clientId=q;a.b.Jb(a,y.routeId,T);return D}):Promise.reject(Error("No client ID"))};QF.prototype.createRoute=function(a,b,c,d,e,f,g){return UF.test(a)?fg(TF(this,a,b,d,c)):this.a.createRoute(a,b,c,d,e,f,g)};
QF.prototype.terminateRoute=function(a){var b=this.f.get(a);if(b&&b.session&&b.clientId){var c={receiver:SF(this,b.sinkId),action:chrome.cast.gd.STOP},c=new em("receiver_action",c);c.clientId=b.clientId;this.b.Jb(this,b.routeId,c);this.b.onPresentationConnectionStateChanged(b.routeId,"terminated")}return this.a.terminateRoute(a)};
QF.prototype.sendRouteMessage=function(a,b,c){var d=JSON.parse(b);switch(d.type){case "client_connect":return b=d.clientId,(a=this.f.get(a))?(c=SF(this,a.sinkId),c.receiverType=chrome.cast.Ud.DIAL,c=new em("custom_dial_launch",new chrome.cast.Vf(c,a.ng.state,a.ng.extraData)),c.clientId=b,b=this.l,this.l=(this.l+1)%9007199254740992,c.sequenceNumber=b,this.g.add(c.sequenceNumber),this.b.Jb(this,a.routeId,c),a=Promise.resolve()):a=Promise.reject(Error("Unknown route")),a;case "custom_dial_launch":if(this.g.contains(d.sequenceNumber))return this.g.remove(d.sequenceNumber),
b=d.message,(a=this.f.get(a))?b&&!b.doLaunch?a=Promise.resolve():(c=wF(this.m,a.sinkId))?(c=new GE(c),d=a.launchParameter,d=(b?b.launchParameter:null)||d,a=c.launchApp(a.appName,d)):a=Promise.reject(Error("Custom launch response for sink that no longer exists")):a=Promise.reject(Error("Unknown route")),a;break;case "v2_message":if("STOP"==d.message.type)return this.terminateRoute(a),Promise.resolve()}return this.a.sendRouteMessage(a,b,c)};
QF.prototype.sendRouteBinaryMessage=function(a){return Promise.reject(Error("Route "+a+" does not support sending binary data."))};var SF=function(a,b){a=wF(a.m,b);b=new chrome.cast.Ie(b,a.Za.friendlyName);b.ipAddress=a.Ea();b.receiverType=chrome.cast.Ud.DIAL;return b};h=QF.prototype;h.Gc=function(a){return this.a.Gc(a)};h.Fc=function(a){return this.a.Fc(a)};h.hd=function(a,b){return this.a.hd(a,b)};h.yc=function(a,b,c){return this.a.yc(a,b,c)};
h.connectRouteByRouteId=function(a,b,c,d,e){return this.a.connectRouteByRouteId(a,b,c,d,e)};h.joinRoute=function(a,b,c,d,e,f){return this.a.joinRoute(a,b,c,d,e,f)};h.detachRoute=function(a){this.f.remove(a);this.a.detachRoute(a)};h.Bb=function(){this.b.Bb()};h.onSinkAvailabilityUpdated=function(a,b){this.b.onSinkAvailabilityUpdated(a,b)};h.ic=function(a,b){this.b.ic(this,b)};h.Rc=function(a,b){this.b.Rc(this,b)};h.Tb=function(a,b){this.b.Tb(this,b)};h.Jb=function(a,b,c){this.b.Jb(this,b,c)};
h.onPresentationConnectionStateChanged=function(a,b){this.b.onPresentationConnectionStateChanged(a,b)};h.onPresentationConnectionClosed=function(a,b,c){this.b.onPresentationConnectionClosed(a,b,c)};h.Xe=function(a){return this.b.Xe(a)};h.Ze=function(){return this.b.Ze()};h.Qc=function(){return this.b.Qc()};h.oe=function(a,b,c){this.b.oe(this,b,c)};h.hf=function(a){this.b.hf(a)};h.xd=function(a){this.a.xd(a)};h.Pc=function(a){this.a.Pc(a)};h.Oc=function(a){this.a.Oc(a)};h.ff=function(){};h.Xg=function(){};
h.searchSinks=function(a,b){return this.a.searchSinks(a,b)};h.provideSinks=function(a){this.a.provideSinks(a)};h.createMediaRouteController=function(){return Fc()};h.setMediaRouteStatusObserver=function(){};h.Af=function(a){this.b.Af(a)};h.ef=function(){return this.b.ef()};h.Vc=function(a,b){return this.b.Vc(a,b)};var RF=function(a,b,c,d){this.b=a;this.sequenceNumber=b;this.f=c;this.a=d},UF=/__dialAppName__/;var YF=function(a,b){this.h=a;this.m=b;this.l=new Qc;this.a=this.l.a;this.g=xp(a.id);this.b=new Qc;this.f=!1;VF(this);WF(this);XF(this,new Ch("GET_TURN_CREDENTIALS"))};YF.prototype.start=function(){var a=this;return this.a.then(function(b){if(b.b)return Promise.reject(Error("Presentation already started"));b.start();return a.b.a})};YF.prototype.stop=function(){var a=this;this.f=!1;return this.a.then(function(b){b.stop();a.a=Promise.reject(Error("Peer connection has already been stopped"))})};
var VF=function(a){a.g.onMessage=function(b){if(b.type)switch(b.type){case "TURN_CREDENTIALS":a.l.resolve(new Hh(a.h.id,b.data.credentials));break;case "ANSWER":a.a.then(function(a){Ph(a,b.data)});break;case "STOP":a.b.b("Stop signal received");a.stop();break;default:throw Error("Unknown message type: "+b.type);}else a.a.then(function(a){var c={type:"PRESENTATION_CONNECTION_MESSAGE",data:b};"string"==typeof c?a.l.send(c):a.l.send(JSON.stringify(c))})}},WF=function(a){a.a.then(function(b){Lh(b,function(b){XF(a,
new Ch("OFFER",new Eh(b,null,null,a.m)))});Mh(b,function(b){b=Dh(b);"STOP"==b.type&&a.stop();XF(a,b)});Ih(b,function(){a.f=!0;XF(a,new Ch("SESSION_START_SUCCESS"));a.b.resolve(a.h)});Kh(b,function(){XF(a,new Ch("SESSION_END"))});Jh(b,function(b){a.f||a.b.b(b);XF(a,new Ch("SESSION_FAILURE"))})})},XF=function(a,b){a.g.sendMessage(b,ZF)},ZF={channelType:"cloud"};var $F=function(a){this.a=a;this.f=new Map;this.A=new Map;this.o=[];this.l=this.K=this.v=this.B=this.h=null;this.m=this.g=this.b=!1;this.u=new Map;this.w=new Map;Xh(this)};$F.prototype.getName=function(){return"cloud"};
$F.prototype.Ga=function(){var a=this;x(this.j,"Initializing Cloud MRP");var b=qE.S();null==b.l&&(null==b.g&&(b.g=new OB(uE(b))),b.l=new tC(b.g,this));this.o.push(b.l);if(null==b.h){var c;null==b.f&&(b.f=new wB(uE(b),sE(b)));c=b.f;null==b.m&&(b.m=new ED(uE(b)));b.h=new wC(c,b.m,this,tE(b))}this.h=b.h;this.o.push(this.h);this.B=vE(b);this.v=sE(b);if(null==b.B){if(null==b.w){c=vE(b);var d=sE(b);null==b.F&&(b.F=new mE(uE(b)));b.w=new RD(c,d,b.F,this)}c=b.w;null==b.A&&(b.A=new XD(sE(b),this));b.B=new ZD(c,
b.A,this)}this.K=b.B;null==b.K&&(b.K=new aE);this.l=b.K;hE(this.l).then(function(b){a.b=b;x(a.j,"Cloud enabled setting: "+a.b)});eE(this.l).then(function(b){a.g=b;x(a.j,"Cloud on setting: "+a.g)});bE(this.l,function(b){a.b=b;x(a.j,"Cloud enabled setting: "+a.b);a.b&&aG(a)});lE(this.l).then(function(b){a.m=b;x(a.j,"Privacy notified setting: "+a.m)})};$F.prototype.fc=function(){return Array.from(this.f.values())};
$F.prototype.pd=function(a){if(!bG(this,a))return lo;z(this.j,"GetAvailableSinks for "+a);var b=[];if(this.g||cG())b=aG(this);this.w.clear();for(var c={},d=ja(this.u.values()),e=d.next();!e.done;c={Wc:c.Wc,ee:c.ee},e=d.next())c.Wc=e.value,c.ee=!1,b.forEach(function(a){return function(b){b.va.id==a.Wc.va.id&&(a.ee=!0,b.va.friendlyName=a.Wc.va.friendlyName)}}(c)),c.ee||this.w.set(c.Wc.va.id,c.Wc);b=b.concat.apply(b,[].concat(la(this.w.values())));z(this.j,function(){return"Available sinks are..."+JSON.stringify(b)});
c=b.map(function(a){return a.va});this.h&&(c=c.concat(dG));return new ko(c,-1!=a.indexOf("0F5096E8")?Tg:null)};var aG=function(a){var b=[];x(a.j,"Checking cloud discovery services");ok.S().g=Fa();a.o.forEach(function(a){a=a.Sc();b=b.concat(a)});return b};h=$F.prototype;h.startObservingMediaSinks=function(){};h.stopObservingMediaSinks=function(){};h.startObservingMediaRoutes=function(){};h.stopObservingMediaRoutes=function(){};h.wd=function(a){return(a=eG(this,a))?a.va:null};
h.createRoute=function(a,b,c,d,e,f,g){var m=this;x(this.j,"createRoute called");z(this.j,"urn: "+a+" sinkId:"+b);if(e=this.A.get(b))return bg(this.a.Xg(this,e,a,c,g,function(b){b.mediaSource=a;b.kb.tabId=g;return dg(b)}),function(a){m.a.Tb(m,a);return a});e=eG(this,b);return fG(this,a,e,b,c,d,g)};
var gG=function(a,b,c,d,e){b instanceof jo&&2==b.errorCode?a.vc(c,6,null):(a.j.error("Error on start session",b instanceof Error?b:Error("Expected an Error value, got "+b)),a.vc(c,e,new $f(wD,"warning","dismiss")));if(b=a.h)b=a.h,b.b.delete(d.deviceId)?(b.a.a.delete(d.va.id),b=!0):b=!1;b&&a.ne([d.va])},fG=function(a,b,c,d,e,f,g){if(f)return eg(Error("not supported"));f=!1;switch(hG(c)){case "cloud":$B(1);break;case "mesi":f=!0;if(!a.m){a.m=!0;jE(a.l);var m=new $f(zD,"notification","learn_more");m.secondaryActions=
["dismiss"];m.helpPageId=6320939;a.a.Qc().send(m)}$B(0)}ok.S().b=new nk(c.model,null);var q=Ej(e,a.getName(),d,b,!0,"",null);f&&(q.customControllerPath="cloud_route_details/view.html?routeId="+q.id);a.f.set(q.id,q);a.A.set(d,q);a.u.set(q.id,c);a.a.ic(a,q);a.a.Vc(a.ea(),!0);if(Sg(b)&&!f)return x(a.j,"starting presentation on route: "+q.id),cg(iG(q,b),function(b){gG(a,b,q,c,7);throw b;});x(a.j,"starting mirroring on route: "+q.id);q.kb={tabId:g,sessionId:"",Be:"",Ce:c.model};Sg(b)&&(q.isOffscreenPresentation=
!0);return cg(a.a.ff(a,q,e),function(b){gG(a,b,q,c,5);throw b;})};h=$F.prototype;h.terminateRoute=function(a){var b=this.f.get(a);return b?this.vc(b,0,null):Promise.reject(new jo(3,"Route in cloud provider not found for routeId "+a))};
h.vc=function(a,b,c){x(this.j,"terminating route: "+a.id);this.f.delete(a.id);this.A.delete(a.sinkId);var d=this.u.get(a.id);this.u.delete(a.id);c&&this.Yg().send(c);Cg("MediaRouter.Cloud.Session.End",b,VB);switch(b){case 1:break;default:switch(hG(d)){case "cloud":ND(this.B,d.deviceId,NB,{})}}this.a.Rc(this,a);0==this.f.size&&this.a.Vc(this.ea(),!1);this.a.onPresentationConnectionStateChanged(a.id,"terminated");this.w.has(a.sinkId)&&(b=this.w.get(a.sinkId),this.ne([b.va]),this.w.delete(a.sinkId));
return Promise.resolve()};h.sendRouteMessage=function(a,b,c){if(c&&c.channelType){c=c.channelType;var d=(a=this.f.get(a)||void 0)?eG(this,a.sinkId):void 0;return $D(this.K,c,b,a,d)}return va(b)?(this.lb(b,a),Promise.resolve()):Promise.reject(Error("Channel type missing"))};h.sendRouteBinaryMessage=function(a){return Promise.reject(Error("Route "+a+" does not support sending binary data."))};
h.Gc=function(a){var b=new Ah;5>b.minFrameRate&&(b.minFrameRate=5);"hangouts"!=this.Fc(a)&&(b.senderSideLetterboxing=!0);Bh(b);Object.freeze(b);x(this.j,"Settings for "+a+": "+zh(b));return b.shouldCaptureAudio||b.shouldCaptureVideo?b:null};h.Fc=function(a){var b=null;a=eG(this,a);switch(hG(a)){case "cloud":b="webrtc";break;case "mesi":b=a.vb?"meetings":"hangouts"}return b};h.hd=function(a,b){z(this.j,"Checking canRoute: "+a+" for sinkId: "+b);return bG(this,a)&&!!this.wd(b)};
h.yc=function(a,b){return"https://hangouts.google.com/cloudmrp-mirroring"==a&&this.f.has(b)};h.joinRoute=function(a,b){return(a=this.f.get(b))?dg(a):eg(Error("not supported"))};h.connectRouteByRouteId=function(){return eg(Error("not supported"))};h.detachRoute=function(){};h.jf=function(a){x(this.j,a.length+" sinks added");0<a.length&&!this.g&&(cE(this.l),this.g=!0);a=eG(this,a[0].id);ok.S().a=new nk(a.model,null);this.a.Bb();this.a.onSinkAvailabilityUpdated(this,2);x(this.j,"sinkAvailability changed to AVAILABLE")};
h.ne=function(a){x(this.j,a.length+" sinks removed");this.o.some(function(a){return 0<a.Sc().length})||(this.a.onSinkAvailabilityUpdated(this,0),x(this.j,"sinkAvailability changed to UNAVAILABLE"));this.a.Bb()};h.Zg=function(a){x(this.j,a.length+" sinks updated");this.a.Bb()};h.Yg=function(){return this.a.Qc()};h.lb=function(a,b,c){c?this.a.Jb(this,b,a):this.a.oe(this,b,a)};
var eG=function(a,b){var c=jG(a,b);c||(c=null,(b=a.A.get(b))&&(c=a.u.get(b.id)));return c},jG=function(a,b){var c=null;a.o.some(function(a){c=a.gc(b);return!!c});return c},hG=function(a){return mb(a.a,"cloud")?"cloud":mb(a.a,"mesi")?"mesi":null},cG=function(){var a=ok.S().g;return 3E5<=Date.now()-a},bG=function(a,b){var c=Rg(b);b=Sg(b);if(a.v.f&&!a.v.b&&c)return a.a.onSinkAvailabilityUpdated(a,2),!0;var d=!1;a.b&&a.v.b&&(d=!0);var e;if(e=!chrome.declarativeWebRequest)a=a.v,e=!(a.f||a.b&&a.a&&(-1!=
LC.indexOf(a.a)||-1!=LC.indexOf(JC(a))))&&b;return e?!1:d&&(c||b)};h=$F.prototype;h.searchSinks=function(a,b){var c=this;if(!bG(this,a))return Promise.reject(Error("err"));a=zC(this.h,b);a.then(function(a){c.jf([a])});return a};h.createMediaRouteController=function(){return Fc()};h.setMediaRouteStatusObserver=function(){};h.provideSinks=function(){};h.ea=function(){return"CloudProvider"};h.pa=function(){return[void 0,{cloudEnabled:this.b,cloudOn:this.g,notifiedHangoutsPrivacy:this.m}]};
h.ua=function(){var a=Vh(this);a&&(a.cloudEnabled&&(this.b=a.cloudEnabled),a.cloudOn&&(this.g=a.cloudOn),a.notifiedHangoutsPrivacy&&(this.m=a.notifiedHangoutsPrivacy))};var iG=function(a,b){a=new YF(a,b);return fg(a.start())};$F.prototype.j=v("mr.CloudProvider");var dG=new Rj("pseudo:cloud","","meeting","","default");var kG=function(){Jk.call(this,12,"ExternalMessageListener","mr.ProviderManager",chrome.runtime.onMessageExternal)};ka(kG,Jk);kG.prototype.De=function(a,b){return b.id&&-1!=lG.indexOf(b.id)?"start"==a.type||"stop"==a.type:!1};kG.prototype.Te=function(){return!0};var nG=function(){mG||(mG=new kG);return mG},mG=null,lG=["idmofbkcelhplfjnmmdolenpigiiiecc","ggedfkijiiammpnbdadhllnehapomdge","njjegkblellcjnakomndbaloifhcoccg"];var oG=function(){Jk.call(this,11,"InternalMessageListener","mr.ProviderManager",chrome.runtime.onMessage)};ka(oG,Jk);oG.prototype.De=function(a,b){return"retrieve_log_data"==a.type&&b.id==chrome.runtime.id&&b.url=="chrome-extension://"+b.id+"/feedback.html"};oG.prototype.Te=function(){return!0};var qG=function(){pG||(pG=new oG);return pG},pG=null;var rG,sG,tG=v("mr.Init"),uG=function(){var a=sG,b=new Bo(a),c=new QF(a,b),b=[b,c];b.push(new $F(a));return b};kp.S().init();rG=new wg("MediaRouter.Provider.WakeDuration");sG=new yp;
var vG=(new Promise(function(a,b){switch(window.location.host){case "enhhojjnijigcajfphajepfemndkmdlo":a();break;case "pkedcjkdefgpdelpbcmbmeomcjbeemfm":chrome.management.get("enhhojjnijigcajfphajepfemndkmdlo",function(c){chrome.runtime.lastError||!c.enabled?a():b(Error("Dev extension is enabled"))});break;default:b(Error("Unknown extension id"))}})).then(function(){return chrome.mojoPrivate&&chrome.mojoPrivate.requireAsync?new Promise(function(a){chrome.mojoPrivate.requireAsync("media_router_bindings").then(function(b){b.Qj&&b.Qj();
b.start().then(function(c){a({mrService:b,mrInstanceId:c})})})}):Promise.reject(Error("No mojo service loaded"))}).then(function(a){if(!a.mrService)throw Error("Failed to get MR service");var b=a.mrInstanceId;if(!b)throw Error("Failed to get MR instance ID.");x(tG,"MR instance ID: "+b);a=a.mrService;if(!sG)throw Error("providerManager not initialized.");a.setHandlers(sG);Zh(b)&&(rG.b="MediaRouter.Provider.FirstWakeDuration");chrome.runtime.onSuspend.addListener(rG.a.bind(rG));ci(b);np();b=uG();window.addEventListener("unhandledrejection",
function(a){a=a.reason;a.stack||(a=Error(a));tG.error("Unhandled promise rejection.",a)});sG.Ga(a,b)}).then(void 0,function(a){w(tG,a.message);throw a;});[].concat([nG(),qG()],la(oF()),la([].concat([Mk(),Ok()],la(Rk()))),la([eC()])).forEach(function(a){Xh(a)});nG().addListener();qG().addListener();vG.then(void 0,function(){return window.close()});
