'use strict';var oZ={TAB:0,Tf:1,Ji:2},pZ=function(a){Cg("MediaRouter.WebRtc.Start.Success",a,oZ)};var tZ=function(a,b){wh.call(this,b);this.u=a;this.a=new Qc;this.h=xp(b.id);this.g=new Qc;this.v=!1;this.l=null;this.w=!1;this.m=this.f=null;qZ(this);rZ(this);sZ(this,new Ch("GET_TURN_CREDENTIALS"))};ka(tZ,wh);tZ.prototype.start=function(a){var b=this;return this.a.a.then(function(c){if(c.b)return Promise.reject(new Fg("Mirroring already started"));if(b.l)return Promise.reject(new Fg("Session permanently stopped"));b.f=new sg("MediaRouter.WebRtc.Session.Launch");c.a.addStream(a);c.start();return b.g.a})};
tZ.prototype.stop=function(){var a=this;Rc(this.g,new Fg("Session stop requested."));this.m&&(this.m.a(),this.m=null);if(this.l)return this.l;this.w=this.v=!1;this.f=null;return this.l=this.a.a.then(function(a){a.stop()}).then(function(){return a.h.Ba()}).catch(function(b){a.h.Ba();throw b;})};
var qZ=function(a){a.h.onMessage=function(b){if(!b.type)throw Error("Message has no type.");switch(b.type){case "TURN_CREDENTIALS":a.a.resolve(new Hh(a.b.id,b.data.credentials));break;case "ANSWER":a.a.a.then(function(a){Ph(a,b.data)});break;case "KNOCK_ANSWER":a.w=!0;a.a.a.then(function(a){Ph(a,b.data)});break;case "STOP":Rc(a.g,new Fg("Stop signal received"));a.stop();break;default:throw new Fg("Unknown message type: "+b.type);}}},rZ=function(a){a.a.a.then(function(b){Lh(b,function(b){sZ(a,new Ch("OFFER",
new Eh(b,a.u,Fh)))});Mh(b,function(b){sZ(a,Dh(b))});Ih(b,function(){a.v=!0;sZ(a,new Ch("SESSION_START_SUCCESS"));!a.w&&a.f&&a.f.a();a.f=null;a.m=new yg("MediaRouter.WebRtc.Session.Length");a.g.resolve(a)});Kh(b,function(){sZ(a,new Ch("SESSION_END"))});Jh(b,function(b){a.v||a.g.b(b);sZ(a,new Ch("SESSION_FAILURE"))})})},sZ=function(a,b){a.h.sendMessage(b,uZ)},uZ={channelType:"cloud"};var vZ=function(){gh.call(this,"webrtc")};ka(vZ,gh);h=vZ.prototype;h.be=function(a,b){return new tZ(a,b)};h.Ae=function(){pZ(0)};h.xe=function(){pZ(1)};h.zf=function(){pZ(2)};h.ye=function(){Bg("MediaRouter.WebRtc.Session.End")};h.ze=function(a){Cg("MediaRouter.WebRtc.Start.Failure",a,Eg)};h.Ed=function(){Bg("MediaRouter.WebRtc.Stream.End")};var wZ=new vZ;eh("mr.mirror.webrtc.WebRtcService",wZ);
