'use strict';var BBa={TAB:0,Ym:1,Ks:2},Y$=function(a){Ab("MediaRouter.WebRtc.Start.Success",a,BBa)};var Z$=function(a,b){Tj.call(this,b);this.H=a;this.l=new Fb;this.g=nx(b.id);this.m=new Fb;this.D=!1;this.s=null;this.F=!1;this.u=this.C=null;CBa(this);DBa(this);this.g.sendMessage(new Zj("GET_TURN_CREDENTIALS"))};t(Z$,Tj);
Z$.prototype.start=function(a){var b=this;return this.l.promise.then(function(c){if(c.g)return Promise.reject(new Zi("Mirroring already started"));if(b.s)return Promise.reject(new Zi("Session permanently stopped"));b.C=new qb("MediaRouter.WebRtc.Session.Launch");c.ca.addStream(a);c.start();return b.m.promise})};
Z$.prototype.stop=function(){var a=this;this.m.reject(new Zi("Session stop requested."));this.u&&(this.u.end(),this.u=null);if(this.s)return this.s;this.F=this.D=!1;this.C=null;return this.s=this.l.promise.then(function(b){b.stop()}).then(function(){return a.g.dispose()}).catch(function(b){a.g.dispose();throw b;})};
var CBa=function(a){a.g.onMessage=function(b){if(!b.type)throw Error("Message has no type.");switch(b.type){case "TURN_CREDENTIALS":a.l.resolve(new ek(a.h.id,b.data.credentials));break;case "ANSWER":a.l.promise.then(function(c){mk(c,b.data)});break;case "KNOCK_ANSWER":a.F=!0;a.l.promise.then(function(c){mk(c,b.data)});break;case "STOP":a.m.reject(new Zi("Stop signal received"));a.stop();break;default:throw new Zi("Unknown message type: "+b.type);}}},DBa=function(a){a.l.promise.then(function(b){ik(b,
function(c){a.g.sendMessage(new Zj("OFFER",new bk(c,a.H,ck)))});jk(b,function(c){c=ak(c);a.g.sendMessage(c)});fk(b,function(){a.D=!0;a.g.sendMessage(new Zj("SESSION_START_SUCCESS"));!a.F&&a.C&&a.C.end();a.C=null;a.u=new wb("MediaRouter.WebRtc.Session.Length");a.m.resolve(a)});hk(b,function(){a.g.sendMessage(new Zj("SESSION_END"))});gk(b,function(c){a.D||a.m.reject(c);a.g.sendMessage(new Zj("SESSION_FAILURE"))})})};var $$=function(){Hj.call(this,"webrtc")};t($$,Hj);k=$$.prototype;k.Bi=function(a,b){return new Z$(a,b)};k.ai=function(){Y$(0)};k.Xh=function(){Y$(1)};k.wj=function(){Y$(2)};k.Yh=function(){zb("MediaRouter.WebRtc.Session.End")};k.Kg=function(a){Ab("MediaRouter.WebRtc.Start.Failure",a,Yi)};k.Zh=function(){zb("MediaRouter.WebRtc.Stream.End")};var EBa=new $$;yj("mr.mirror.webrtc.WebRtcService",EBa);
