'use strict';var ima={TAB:0,ll:1,aq:2},Y$=function(a){ub("MediaRouter.WebRtc.Start.Success",a,ima)};var Z$=function(a,b){Hj.call(this,b);this.H=a;this.l=new zb;this.g=$w(b.id);this.m=new zb;this.D=!1;this.o=null;this.F=!1;this.u=this.C=null;jma(this);kma(this);this.g.sendMessage(new Oj("GET_TURN_CREDENTIALS"))};t(Z$,Hj);
Z$.prototype.start=function(a){var b=this;return this.l.g.then(function(c){if(c.g)return Promise.reject(new Ni("Mirroring already started"));if(b.o)return Promise.reject(new Ni("Session permanently stopped"));b.C=new kb("MediaRouter.WebRtc.Session.Launch");c.ia.addStream(a);c.start();return b.m.g})};
Z$.prototype.stop=function(){var a=this;this.m.reject(new Ni("Session stop requested."));this.u&&(this.u.end(),this.u=null);if(this.o)return this.o;this.F=this.D=!1;this.C=null;return this.o=this.l.g.then(function(b){b.stop()}).then(function(){return a.g.dispose()}).catch(function(b){a.g.dispose();throw b;})};
var jma=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 Tj(a.h.id,b.data.credentials));break;case "ANSWER":a.l.g.then(function(c){bk(c,b.data)});break;case "KNOCK_ANSWER":a.F=!0;a.l.g.then(function(c){bk(c,b.data)});break;case "STOP":a.m.reject(new Ni("Stop signal received"));a.stop();break;default:throw new Ni("Unknown message type: "+b.type);}}},kma=function(a){a.l.g.then(function(b){Xj(b,function(c){a.g.sendMessage(new Oj("OFFER",
new Qj(c,a.H,Rj)))});Yj(b,function(c){c=Pj(c);a.g.sendMessage(c)});Uj(b,function(){a.D=!0;a.g.sendMessage(new Oj("SESSION_START_SUCCESS"));!a.F&&a.C&&a.C.end();a.C=null;a.u=new qb("MediaRouter.WebRtc.Session.Length");a.m.resolve(a)});Wj(b,function(){a.g.sendMessage(new Oj("SESSION_END"))});Vj(b,function(c){a.D||a.m.reject(c);a.g.sendMessage(new Oj("SESSION_FAILURE"))})})};var $$=function(){vj.call(this,"webrtc")};t($$,vj);k=$$.prototype;k.wh=function(a,b){return new Z$(a,b)};k.Ug=function(){Y$(0)};k.Rg=function(){Y$(1)};k.Yh=function(){Y$(2)};k.Sg=function(){tb("MediaRouter.WebRtc.Session.End")};k.Ef=function(a){ub("MediaRouter.WebRtc.Start.Failure",a,Mi)};k.Tg=function(){tb("MediaRouter.WebRtc.Stream.End")};var lma=new $$;mj("mr.mirror.webrtc.WebRtcService",lma);
