'use strict';var vba={TAB:0,Ri:1,gm:2},Y$=function(a){Rb("MediaRouter.WebRtc.Start.Success",a,vba)};var Z$=function(a,b){Tg.call(this,b);this.B=a;this.f=new Tb;this.b=rx(b.id);this.j=new Tb;this.A=!1;this.s=null;this.o=!1;this.m=this.g=null;wba(this);xba(this);this.b.sendMessage(new Zg("GET_TURN_CREDENTIALS"))};l(Z$,Tg);
Z$.prototype.start=function(a){var b=this;return this.f.b.then(function(c){if(c.f)return Promise.reject(new Wf("Mirroring already started"));if(b.s)return Promise.reject(new Wf("Session permanently stopped"));b.g=new Fb("MediaRouter.WebRtc.Session.Launch");c.b.addStream(a);c.start();return b.j.b})};
Z$.prototype.stop=function(){var a=this;this.j.reject(new Wf("Session stop requested."));this.m&&(this.m.b(),this.m=null);if(this.s)return this.s;this.o=this.A=!1;this.g=null;return this.s=this.f.b.then(function(a){a.stop()}).then(function(){return a.b.Ra()}).catch(function(b){a.b.Ra();throw b;})};
var wba=function(a){a.b.onMessage=function(b){if(!b.type)throw Error("Message has no type.");switch(b.type){case "TURN_CREDENTIALS":a.f.resolve(new dh(a.h.id,b.data.credentials));break;case "ANSWER":a.f.b.then(function(a){lh(a,b.data)});break;case "KNOCK_ANSWER":a.o=!0;a.f.b.then(function(a){lh(a,b.data)});break;case "STOP":a.j.reject(new Wf("Stop signal received"));a.stop();break;default:throw new Wf("Unknown message type: "+b.type);}}},xba=function(a){a.f.b.then(function(b){hh(b,function(b){a.b.sendMessage(new Zg("OFFER",
new ah(b,a.B,bh)))});ih(b,function(b){b=$g(b);a.b.sendMessage(b)});eh(b,function(){a.A=!0;a.b.sendMessage(new Zg("SESSION_START_SUCCESS"));!a.o&&a.g&&a.g.b();a.g=null;a.m=new Lb("MediaRouter.WebRtc.Session.Length");a.j.resolve(a)});gh(b,function(){a.b.sendMessage(new Zg("SESSION_END"))});fh(b,function(b){a.A||a.j.reject(b);a.b.sendMessage(new Zg("SESSION_FAILURE"))})})};var $$=function(){Hg.call(this,"webrtc")};l($$,Hg);g=$$.prototype;g.tg=function(a,b){return new Z$(a,b)};g.eh=function(){Y$(0)};g.ah=function(){Y$(1)};g.ui=function(){Y$(2)};g.bh=function(){Qb("MediaRouter.WebRtc.Session.End")};g.dh=function(a){Rb("MediaRouter.WebRtc.Start.Failure",a,Vf)};g.Qf=function(){Qb("MediaRouter.WebRtc.Stream.End")};var yba=new $$;xg("mr.mirror.webrtc.WebRtcService",yba);
