home *** CD-ROM | disk | FTP | other *** search
/ csi.uticak12.org / csi.uticak12.org.tar / csi.uticak12.org / flashVideo / Handshake.swf / scripts / __Packages / mx / video / NCManager.as < prev    next >
Text File  |  2010-12-15  |  27KB  |  883 lines

  1. class mx.video.NCManager implements mx.video.INCManager
  2. {
  3.    static var version = "1.0.2.7";
  4.    static var shortVersion = "1.0.2";
  5.    var DEFAULT_TIMEOUT = 60000;
  6.    function NCManager()
  7.    {
  8.       this.initNCInfo();
  9.       this.initOtherInfo();
  10.       this._timeoutIntervalId = 0;
  11.       this._tryNCIntervalId = 0;
  12.       this._timeout = this.DEFAULT_TIMEOUT;
  13.       this._nc = undefined;
  14.       this._ncConnected = false;
  15.    }
  16.    function initNCInfo()
  17.    {
  18.       this._isRTMP = undefined;
  19.       this._serverName = undefined;
  20.       this._wrappedURL = undefined;
  21.       this._portNumber = undefined;
  22.       this._appName = undefined;
  23.    }
  24.    function initOtherInfo()
  25.    {
  26.       this._contentPath = undefined;
  27.       this._streamName = undefined;
  28.       this._streamLength = undefined;
  29.       this._streamWidth = undefined;
  30.       this._streamHeight = undefined;
  31.       this._streams = undefined;
  32.       this._autoSenseBW = false;
  33.       this.fpadZone = undefined;
  34.       this._payload = 0;
  35.       this._connTypeCounter = 0;
  36.       this.cleanConns();
  37.    }
  38.    function getTimeout()
  39.    {
  40.       return this._timeout;
  41.    }
  42.    function setTimeout(t)
  43.    {
  44.       this._timeout = t;
  45.       if(this._timeoutIntervalId != 0)
  46.       {
  47.          clearInterval(this._timeoutIntervalId);
  48.          this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  49.       }
  50.    }
  51.    function getBitrate()
  52.    {
  53.       return this._bitrate;
  54.    }
  55.    function setBitrate(b)
  56.    {
  57.       if(this._isRTMP == undefined || !this._isRTMP)
  58.       {
  59.          this._bitrate = b;
  60.       }
  61.    }
  62.    function getVideoPlayer()
  63.    {
  64.       return this._owner;
  65.    }
  66.    function setVideoPlayer(v)
  67.    {
  68.       this._owner = v;
  69.    }
  70.    function getNetConnection()
  71.    {
  72.       return this._nc;
  73.    }
  74.    function getStreamName()
  75.    {
  76.       return this._streamName;
  77.    }
  78.    function isRTMP()
  79.    {
  80.       return this._isRTMP;
  81.    }
  82.    function getStreamLength()
  83.    {
  84.       return this._streamLength;
  85.    }
  86.    function getStreamWidth()
  87.    {
  88.       return this._streamWidth;
  89.    }
  90.    function getStreamHeight()
  91.    {
  92.       return this._streamHeight;
  93.    }
  94.    function connectToURL(url)
  95.    {
  96.       this.initOtherInfo();
  97.       this._contentPath = url;
  98.       if(this._contentPath == null || this._contentPath == "")
  99.       {
  100.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH);
  101.       }
  102.       else
  103.       {
  104.          var _loc2_ = this.parseURL(this._contentPath);
  105.          if(_loc2_.streamName == undefined || _loc2_.streamName == "")
  106.          {
  107.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  108.          }
  109.          else if(_loc2_.isRTMP)
  110.          {
  111.             var _loc4_ = this.canReuseOldConnection(_loc2_);
  112.             this._isRTMP = true;
  113.             this._protocol = _loc2_.protocol;
  114.             this._streamName = _loc2_.streamName;
  115.             this._serverName = _loc2_.serverName;
  116.             this._wrappedURL = _loc2_.wrappedURL;
  117.             this._portNumber = _loc2_.portNumber;
  118.             this._appName = _loc2_.appName;
  119.             if(!(this._appName == undefined || this._appName == "" || this._streamName == undefined || this._streamName == ""))
  120.             {
  121.                this._autoSenseBW = this._streamName.indexOf(",") >= 0;
  122.                return _loc4_ || this.connectRTMP();
  123.             }
  124.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  125.          }
  126.          else
  127.          {
  128.             var _loc3_ = _loc2_.streamName;
  129.             if(_loc3_.indexOf("?") < 0 && (_loc3_.length < 4 || _loc3_.slice(-4).toLowerCase() != ".txt") && (_loc3_.length < 4 || _loc3_.slice(-4).toLowerCase() != ".xml") && (_loc3_.length < 5 || _loc3_.slice(-5).toLowerCase() != ".smil"))
  130.             {
  131.                _loc4_ = this.canReuseOldConnection(_loc2_);
  132.                this._isRTMP = false;
  133.                this._streamName = _loc3_;
  134.                return _loc4_ || this.connectHTTP();
  135.             }
  136.             if(_loc3_.indexOf("/fms/fpad") >= 0)
  137.             {
  138.                try
  139.                {
  140.                   return this.connectFPAD(_loc3_);
  141.                }
  142.                catch(err:Error)
  143.                {
  144.                }
  145.             }
  146.             this._smilMgr = new mx.video.SMILManager(this);
  147.             return this._smilMgr.connectXML(_loc3_);
  148.          }
  149.       }
  150.    }
  151.    function connectAgain()
  152.    {
  153.       var _loc2_ = this._appName.indexOf("/");
  154.       if(_loc2_ < 0)
  155.       {
  156.          _loc2_ = this._streamName.indexOf("/");
  157.          if(_loc2_ >= 0)
  158.          {
  159.             this._appName += "/";
  160.             this._appName += this._streamName.slice(0,_loc2_);
  161.             this._streamName = this._streamName.slice(_loc2_ + 1);
  162.          }
  163.          return false;
  164.       }
  165.       var _loc3_ = this._appName.slice(_loc2_ + 1);
  166.       _loc3_ += "/";
  167.       _loc3_ += this._streamName;
  168.       this._streamName = _loc3_;
  169.       this._appName = this._appName.slice(0,_loc2_);
  170.       this.close();
  171.       this._payload = 0;
  172.       this._connTypeCounter = 0;
  173.       this.cleanConns();
  174.       this.connectRTMP();
  175.       return true;
  176.    }
  177.    function reconnect()
  178.    {
  179.       if(!this._isRTMP)
  180.       {
  181.          throw new Error("Cannot call reconnect on an http connection");
  182.       }
  183.       else
  184.       {
  185.          this._nc.onStatus = function(info)
  186.          {
  187.             this.mc.reconnectOnStatus(this,info);
  188.          };
  189.          this._nc.onBWDone = function()
  190.          {
  191.             this.mc.onReconnected();
  192.          };
  193.          this._nc.connect(this._ncUri,false);
  194.       }
  195.    }
  196.    function onReconnected()
  197.    {
  198.       delete this._nc.onStatus;
  199.       delete this._nc.onBWDone;
  200.       this._ncConnected = true;
  201.       this._owner.ncReconnected();
  202.    }
  203.    function close()
  204.    {
  205.       if(this._nc)
  206.       {
  207.          this._nc.close();
  208.          this._ncConnected = false;
  209.       }
  210.    }
  211.    function helperDone(helper, success)
  212.    {
  213.       if(!success)
  214.       {
  215.          this._nc = undefined;
  216.          this._ncConnected = false;
  217.          this._owner.ncConnected();
  218.          this._smilMgr = undefined;
  219.          this._fpadMgr = undefined;
  220.          return undefined;
  221.       }
  222.       var _loc2_ = undefined;
  223.       var _loc4_ = undefined;
  224.       if(helper == this._fpadMgr)
  225.       {
  226.          _loc4_ = this._fpadMgr.rtmpURL;
  227.          this._fpadMgr = undefined;
  228.          _loc2_ = this.parseURL(_loc4_);
  229.          this._isRTMP = _loc2_.isRTMP;
  230.          this._protocol = _loc2_.protocol;
  231.          this._serverName = _loc2_.serverName;
  232.          this._portNumber = _loc2_.portNumber;
  233.          this._wrappedURL = _loc2_.wrappedURL;
  234.          this._appName = _loc2_.appName;
  235.          this._streamName = _loc2_.streamName;
  236.          var _loc5_ = this.fpadZone;
  237.          this.fpadZone = -1;
  238.          this.connectRTMP();
  239.          this.fpadZone = _loc5_;
  240.          return undefined;
  241.       }
  242.       if(helper != this._smilMgr)
  243.       {
  244.          return undefined;
  245.       }
  246.       this._streamWidth = this._smilMgr.width;
  247.       this._streamHeight = this._smilMgr.height;
  248.       _loc4_ = this._smilMgr.baseURLAttr[0];
  249.       if(_loc4_ != undefined && _loc4_ != "")
  250.       {
  251.          if(_loc4_.charAt(_loc4_.length - 1) != "/")
  252.          {
  253.             _loc4_ += "/";
  254.          }
  255.          _loc2_ = this.parseURL(_loc4_);
  256.          this._isRTMP = _loc2_.isRTMP;
  257.          this._streamName = _loc2_.streamName;
  258.          if(this._isRTMP)
  259.          {
  260.             this._protocol = _loc2_.protocol;
  261.             this._serverName = _loc2_.serverName;
  262.             this._portNumber = _loc2_.portNumber;
  263.             this._wrappedURL = _loc2_.wrappedURL;
  264.             this._appName = _loc2_.appName;
  265.             if(this._appName == undefined || this._appName == "")
  266.             {
  267.                this._smilMgr = undefined;
  268.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  269.             }
  270.             else if(this._smilMgr.baseURLAttr.length > 1)
  271.             {
  272.                _loc2_ = this.parseURL(this._smilMgr.baseURLAttr[1]);
  273.                if(_loc2_.serverName != undefined)
  274.                {
  275.                   this.fallbackServerName = _loc2_.serverName;
  276.                }
  277.             }
  278.          }
  279.       }
  280.       this._streams = this._smilMgr.videoTags;
  281.       this._smilMgr = undefined;
  282.       var _loc3_ = 0;
  283.       for(; _loc3_ < this._streams.length; this._streams[_loc3_].parseResults = _loc2_,_loc3_ = _loc3_ + 1)
  284.       {
  285.          _loc4_ = this._streams[_loc3_].src;
  286.          _loc2_ = this.parseURL(_loc4_);
  287.          if(this._isRTMP == undefined)
  288.          {
  289.             this._isRTMP = _loc2_.isRTMP;
  290.             if(this._isRTMP)
  291.             {
  292.                this._protocol = _loc2_.protocol;
  293.                if(this._streams.length > 1)
  294.                {
  295.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute RTMP URLs, must use meta tag base attribute.");
  296.                }
  297.                else
  298.                {
  299.                   this._serverName = _loc2_.serverName;
  300.                   this._portNumber = _loc2_.portNumber;
  301.                   this._wrappedURL = _loc2_.wrappedURL;
  302.                   this._appName = _loc2_.appName;
  303.                   if(this._appName == undefined || this._appName == "")
  304.                   {
  305.                      throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  306.                   }
  307.                }
  308.             }
  309.             else if(_loc2_.streamName.indexOf("/fms/fpad") >= 0 && this._streams.length > 1)
  310.             {
  311.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute fpad URLs, must use meta tag base attribute.");
  312.             }
  313.             continue;
  314.          }
  315.          if(!(this._streamName != undefined && this._streamName != "" && !_loc2_.isRelative && this._streams.length > 1))
  316.          {
  317.             continue;
  318.          }
  319.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"When using meta tag base attribute, cannot use absolute URLs for video or ref tag src attributes.");
  320.       }
  321.       this._autoSenseBW = this._streams.length > 1;
  322.       if(!this._autoSenseBW)
  323.       {
  324.          if(this._streamName != undefined)
  325.          {
  326.             this._streamName += this._streams[0].parseResults.streamName;
  327.          }
  328.          else
  329.          {
  330.             this._streamName = this._streams[0].parseResults.streamName;
  331.          }
  332.          this._streamLength = this._streams[0].dur;
  333.       }
  334.       if(this._isRTMP)
  335.       {
  336.          this.connectRTMP();
  337.       }
  338.       else if(this._streamName != undefined && this._streamName.indexOf("/fms/fpad") >= 0)
  339.       {
  340.          this.connectFPAD(this._streamName);
  341.       }
  342.       else
  343.       {
  344.          if(this._autoSenseBW)
  345.          {
  346.             this.bitrateMatch();
  347.          }
  348.          this.connectHTTP();
  349.          this._owner.ncConnected();
  350.       }
  351.    }
  352.    function bitrateMatch()
  353.    {
  354.       var _loc3_ = undefined;
  355.       var _loc4_ = this._bitrate;
  356.       if(isNaN(_loc4_))
  357.       {
  358.          _loc4_ = 0;
  359.       }
  360.       var _loc2_ = 0;
  361.       while(_loc2_ < this._streams.length)
  362.       {
  363.          if(isNaN(this._streams[_loc2_].bitrate) || _loc4_ >= this._streams[_loc2_].bitrate)
  364.          {
  365.             _loc3_ = _loc2_;
  366.             break;
  367.          }
  368.          _loc2_ = _loc2_ + 1;
  369.       }
  370.       if(isNaN(_loc3_))
  371.       {
  372.          throw new mx.video.VideoError(mx.video.VideoError.NO_BITRATE_MATCH);
  373.       }
  374.       else
  375.       {
  376.          if(this._streamName != undefined)
  377.          {
  378.             this._streamName += this._streams[_loc3_].src;
  379.          }
  380.          else
  381.          {
  382.             this._streamName = this._streams[_loc3_].src;
  383.          }
  384.          if(this._isRTMP && this._streamName.slice(-4).toLowerCase() == ".flv")
  385.          {
  386.             this._streamName = this._streamName.slice(0,-4);
  387.          }
  388.          this._streamLength = this._streams[_loc3_].dur;
  389.       }
  390.    }
  391.    function parseURL(url)
  392.    {
  393.       var _loc2_ = new Object();
  394.       var _loc3_ = 0;
  395.       var _loc4_ = url.indexOf(":/",_loc3_);
  396.       if(_loc4_ >= 0)
  397.       {
  398.          _loc4_ += 2;
  399.          _loc2_.protocol = url.slice(_loc3_,_loc4_);
  400.          _loc2_.isRelative = false;
  401.       }
  402.       else
  403.       {
  404.          _loc2_.isRelative = true;
  405.       }
  406.       if(_loc2_.protocol != undefined && (_loc2_.protocol == "rtmp:/" || _loc2_.protocol == "rtmpt:/" || _loc2_.protocol == "rtmps:/" || _loc2_.protocol == "rtmpe:/" || _loc2_.protocol == "rtmpte:/"))
  407.       {
  408.          _loc2_.isRTMP = true;
  409.          _loc3_ = _loc4_;
  410.          if(url.charAt(_loc3_) == "/")
  411.          {
  412.             _loc3_ = _loc3_ + 1;
  413.             var _loc7_ = url.indexOf(":",_loc3_);
  414.             var _loc8_ = url.indexOf("/",_loc3_);
  415.             if(_loc8_ < 0)
  416.             {
  417.                if(_loc7_ < 0)
  418.                {
  419.                   _loc2_.serverName = url.slice(_loc3_);
  420.                }
  421.                else
  422.                {
  423.                   _loc4_ = _loc7_;
  424.                   _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  425.                   _loc3_ = _loc4_ + 1;
  426.                   _loc2_.serverName = url.slice(_loc3_);
  427.                }
  428.                return _loc2_;
  429.             }
  430.             if(_loc7_ >= 0 && _loc7_ < _loc8_)
  431.             {
  432.                _loc4_ = _loc7_;
  433.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  434.                _loc3_ = _loc4_ + 1;
  435.                _loc4_ = _loc8_;
  436.                _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  437.             }
  438.             else
  439.             {
  440.                _loc4_ = _loc8_;
  441.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  442.             }
  443.             _loc3_ = _loc4_ + 1;
  444.          }
  445.          if(url.charAt(_loc3_) == "?")
  446.          {
  447.             var _loc9_ = url.slice(_loc3_ + 1);
  448.             var _loc6_ = this.parseURL(_loc9_);
  449.             if(!(_loc6_.protocol == undefined || !_loc6_.isRTMP))
  450.             {
  451.                _loc2_.wrappedURL = "?";
  452.                _loc2_.wrappedURL += _loc6_.protocol;
  453.                if(_loc6_.serverName != undefined)
  454.                {
  455.                   _loc2_.wrappedURL += "/";
  456.                   _loc2_.wrappedURL += _loc6_.serverName;
  457.                }
  458.                if(_loc6_.wrappedURL != undefined)
  459.                {
  460.                   _loc2_.wrappedURL += "/?";
  461.                   _loc2_.wrappedURL += _loc6_.wrappedURL;
  462.                }
  463.                _loc2_.appName = _loc6_.appName;
  464.                _loc2_.streamName = _loc6_.streamName;
  465.                return _loc2_;
  466.             }
  467.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  468.          }
  469.          else
  470.          {
  471.             _loc4_ = url.indexOf("/",_loc3_);
  472.             if(_loc4_ < 0)
  473.             {
  474.                _loc2_.appName = url.slice(_loc3_);
  475.                return _loc2_;
  476.             }
  477.             _loc2_.appName = url.slice(_loc3_,_loc4_);
  478.             _loc3_ = _loc4_ + 1;
  479.             _loc4_ = url.indexOf("/",_loc3_);
  480.             if(_loc4_ < 0)
  481.             {
  482.                _loc2_.streamName = url.slice(_loc3_);
  483.                if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  484.                {
  485.                   _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  486.                }
  487.                return _loc2_;
  488.             }
  489.             _loc2_.appName += "/";
  490.             _loc2_.appName += url.slice(_loc3_,_loc4_);
  491.             _loc3_ = _loc4_ + 1;
  492.             _loc2_.streamName = url.slice(_loc3_);
  493.             if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  494.             {
  495.                _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  496.             }
  497.          }
  498.       }
  499.       else
  500.       {
  501.          _loc2_.isRTMP = false;
  502.          _loc2_.streamName = url;
  503.       }
  504.       return _loc2_;
  505.    }
  506.    function canReuseOldConnection(parseResults)
  507.    {
  508.       if(this._nc == null || !this._ncConnected)
  509.       {
  510.          return false;
  511.       }
  512.       if(!parseResults.isRTMP)
  513.       {
  514.          if(!this._isRTMP)
  515.          {
  516.             return true;
  517.          }
  518.          this._owner.close();
  519.          this._nc = undefined;
  520.          this._ncConnected = false;
  521.          this.initNCInfo();
  522.          return false;
  523.       }
  524.       if(this._isRTMP)
  525.       {
  526.          if(parseResults.serverName == this._serverName && parseResults.appName == this._appName && parseResults.protocol == this._protocol && parseResults.portNumber == this._portNumber && parseResults.wrappedURL == this._wrappedURL)
  527.          {
  528.             return true;
  529.          }
  530.          this._owner.close();
  531.          this._nc = undefined;
  532.          this._ncConnected = false;
  533.       }
  534.       this.initNCInfo();
  535.       return false;
  536.    }
  537.    function connectHTTP()
  538.    {
  539.       this._nc = new NetConnection();
  540.       this._nc.connect(null);
  541.       this._ncConnected = true;
  542.       return true;
  543.    }
  544.    function connectRTMP()
  545.    {
  546.       clearInterval(this._timeoutIntervalId);
  547.       this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  548.       this._tryNC = new Array();
  549.       var _loc3_ = !(this._protocol == "rtmp:/" || this._protocol == "rtmpe:/") ? 1 : 2;
  550.       var _loc2_ = 0;
  551.       while(_loc2_ < _loc3_)
  552.       {
  553.          this._tryNC[_loc2_] = new NetConnection();
  554.          if(this.fpadZone != null)
  555.          {
  556.             this._tryNC[_loc2_].fpadZone = this.fpadZone;
  557.          }
  558.          this._tryNC[_loc2_].mc = this;
  559.          this._tryNC[_loc2_].pending = false;
  560.          this._tryNC[_loc2_].connIndex = _loc2_;
  561.          this._tryNC[_loc2_].onBWDone = function(p_bw)
  562.          {
  563.             this.mc.onConnected(this,p_bw);
  564.          };
  565.          this._tryNC[_loc2_].onBWCheck = function()
  566.          {
  567.             return ++this.mc._payload;
  568.          };
  569.          this._tryNC[_loc2_].onStatus = function(info)
  570.          {
  571.             this.mc.connectOnStatus(this,info);
  572.          };
  573.          _loc2_ = _loc2_ + 1;
  574.       }
  575.       this.nextConnect();
  576.       return false;
  577.    }
  578.    function connectFPAD(url)
  579.    {
  580.       var _loc7_ = undefined;
  581.       var _loc5_ = undefined;
  582.       var _loc6_ = undefined;
  583.       var _loc2_ = url.indexOf("?");
  584.       while(_loc2_ >= 0)
  585.       {
  586.          _loc2_ = _loc2_ + 1;
  587.          var _loc4_ = url.indexOf("&",_loc2_);
  588.          if(url.substr(_loc2_,4).toLowerCase() == "uri=")
  589.          {
  590.             _loc7_ = url.slice(0,_loc2_);
  591.             _loc2_ += 4;
  592.             if(_loc4_ >= 0)
  593.             {
  594.                _loc5_ = url.slice(_loc2_,_loc4_);
  595.                _loc6_ = url.slice(_loc4_);
  596.             }
  597.             else
  598.             {
  599.                _loc5_ = url.slice(_loc2_);
  600.                _loc6_ = "";
  601.             }
  602.             break;
  603.          }
  604.          _loc2_ = _loc4_;
  605.       }
  606.       if(_loc2_ < 0)
  607.       {
  608.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url must include uri parameter: " + url);
  609.       }
  610.       else
  611.       {
  612.          var _loc8_ = this.parseURL(_loc5_);
  613.          if(!_loc8_.isRTMP)
  614.          {
  615.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url uri parameter must be rtmp url: " + url);
  616.          }
  617.          else
  618.          {
  619.             this._fpadMgr = new mx.video.FPADManager(this);
  620.             return this._fpadMgr.connectXML(_loc7_,_loc5_,_loc6_,_loc8_);
  621.          }
  622.       }
  623.    }
  624.    function nextConnect()
  625.    {
  626.       clearInterval(this._tryNCIntervalId);
  627.       this._tryNCIntervalId = 0;
  628.       var _loc3_ = undefined;
  629.       var _loc2_ = undefined;
  630.       if(this._connTypeCounter == 0)
  631.       {
  632.          _loc3_ = this._protocol;
  633.          _loc2_ = this._portNumber;
  634.       }
  635.       else
  636.       {
  637.          _loc2_ = null;
  638.          if(this._protocol == "rtmp:/")
  639.          {
  640.             _loc3_ = "rtmpt:/";
  641.          }
  642.          else
  643.          {
  644.             if(this._protocol != "rtmpe:/")
  645.             {
  646.                this._tryNC.pop();
  647.                return undefined;
  648.             }
  649.             _loc3_ = "rtmpte:/";
  650.          }
  651.       }
  652.       var _loc4_ = _loc3_ + (this._serverName != undefined ? "/" + this._serverName + (_loc2_ != null ? ":" + _loc2_ : "") + "/" : "") + (this._wrappedURL != undefined ? this._wrappedURL + "/" : "") + this._appName;
  653.       this._tryNC[this._connTypeCounter].pending = true;
  654.       this._tryNC[this._connTypeCounter].connect(_loc4_,this._autoSenseBW);
  655.       if(this._connTypeCounter < this._tryNC.length - 1)
  656.       {
  657.          this._connTypeCounter = this._connTypeCounter + 1;
  658.          this._tryNCIntervalId = setInterval(this,"nextConnect",1500);
  659.       }
  660.    }
  661.    function cleanConns()
  662.    {
  663.       clearInterval(this._tryNCIntervalId);
  664.       this._tryNCIntervalId = 0;
  665.       if(this._tryNC != undefined)
  666.       {
  667.          var _loc2_ = 0;
  668.          while(_loc2_ < this._tryNC.length)
  669.          {
  670.             if(this._tryNC[_loc2_] != undefined)
  671.             {
  672.                delete this._tryNC[_loc2_].onStatus;
  673.                if(this._tryNC[_loc2_].pending)
  674.                {
  675.                   this._tryNC[_loc2_].onStatus = function(info)
  676.                   {
  677.                      this.mc.disconnectOnStatus(this,info);
  678.                   };
  679.                }
  680.                else
  681.                {
  682.                   delete this._tryNC[_loc2_].onStatus;
  683.                   this._tryNC[_loc2_].close();
  684.                }
  685.             }
  686.             delete this._tryNC[_loc2_];
  687.             _loc2_ = _loc2_ + 1;
  688.          }
  689.          delete this._tryNC;
  690.       }
  691.    }
  692.    function tryFallBack()
  693.    {
  694.       if(this._serverName == this.fallbackServerName || this.fallbackServerName == undefined || this.fallbackServerName == null)
  695.       {
  696.          delete this._nc;
  697.          this._nc = undefined;
  698.          this._ncConnected = false;
  699.          this._owner.ncConnected();
  700.       }
  701.       else
  702.       {
  703.          this._connTypeCounter = 0;
  704.          this.cleanConns();
  705.          this._serverName = this.fallbackServerName;
  706.          this.connectRTMP();
  707.       }
  708.    }
  709.    function onConnected(p_nc, p_bw)
  710.    {
  711.       clearInterval(this._timeoutIntervalId);
  712.       this._timeoutIntervalId = 0;
  713.       delete p_nc.onBWDone;
  714.       delete p_nc.onBWCheck;
  715.       delete p_nc.onStatus;
  716.       this._nc = p_nc;
  717.       this._ncUri = this._nc.uri;
  718.       this._ncConnected = true;
  719.       if(this._autoSenseBW)
  720.       {
  721.          this._bitrate = p_bw * 1024;
  722.          if(this._streams != undefined)
  723.          {
  724.             this.bitrateMatch();
  725.          }
  726.          else
  727.          {
  728.             var _loc3_ = this._streamName.split(",");
  729.             var _loc2_ = 0;
  730.             while(_loc2_ < _loc3_.length)
  731.             {
  732.                var _loc4_ = mx.video.NCManager.stripFrontAndBackWhiteSpace(_loc3_[_loc2_]);
  733.                if(_loc2_ + 1 >= _loc3_.length)
  734.                {
  735.                   this._streamName = _loc4_;
  736.                   break;
  737.                }
  738.                if(p_bw <= Number(_loc3_[_loc2_ + 1]))
  739.                {
  740.                   this._streamName = _loc4_;
  741.                   break;
  742.                }
  743.                _loc2_ += 2;
  744.             }
  745.             if(this._streamName.slice(-4).toLowerCase() == ".flv")
  746.             {
  747.                this._streamName = this._streamName.slice(0,-4);
  748.             }
  749.          }
  750.       }
  751.       if(!this._owner.__get__isLive() && this._streamLength == undefined)
  752.       {
  753.          var _loc6_ = new Object();
  754.          _loc6_.mc = this;
  755.          _loc6_.onResult = function(length)
  756.          {
  757.             this.mc.getStreamLengthResult(length);
  758.          };
  759.          this._nc.call("getStreamLength",_loc6_,this._streamName);
  760.       }
  761.       else
  762.       {
  763.          this._owner.ncConnected();
  764.       }
  765.    }
  766.    function connectOnStatus(target, info)
  767.    {
  768.       target.pending = false;
  769.       if(info.code == "NetConnection.Connect.Success")
  770.       {
  771.          this._nc = this._tryNC[target.connIndex];
  772.          this._tryNC[target.connIndex] = undefined;
  773.          this.cleanConns();
  774.       }
  775.       else if(info.code == "NetConnection.Connect.Rejected" && info.ex != null && info.ex.code == 302)
  776.       {
  777.          this._connTypeCounter = 0;
  778.          this.cleanConns();
  779.          var _loc2_ = this.parseURL(info.ex.redirect);
  780.          if(_loc2_.isRTMP)
  781.          {
  782.             this._protocol = _loc2_.protocol;
  783.             this._serverName = _loc2_.serverName;
  784.             this._wrappedURL = _loc2_.wrappedURL;
  785.             this._portNumber = _loc2_.portNumber;
  786.             this._appName = _loc2_.appName;
  787.             if(_loc2_.streamName != null)
  788.             {
  789.                this._appName += "/" + _loc2_.streamName;
  790.             }
  791.             this.connectRTMP();
  792.          }
  793.          else
  794.          {
  795.             this.tryFallBack();
  796.          }
  797.       }
  798.       else if((info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected") && target.connIndex == this._tryNC.length - 1)
  799.       {
  800.          if(!this.connectAgain())
  801.          {
  802.             this.tryFallBack();
  803.          }
  804.       }
  805.    }
  806.    function reconnectOnStatus(target, info)
  807.    {
  808.       if(info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected")
  809.       {
  810.          delete this._nc;
  811.          this._nc = undefined;
  812.          this._ncConnected = false;
  813.          this._owner.ncReconnected();
  814.       }
  815.    }
  816.    function disconnectOnStatus(target, info)
  817.    {
  818.       if(info.code == "NetConnection.Connect.Success")
  819.       {
  820.          delete target.onStatus;
  821.          target.close();
  822.       }
  823.    }
  824.    function getStreamLengthResult(length)
  825.    {
  826.       if(length > 0)
  827.       {
  828.          this._streamLength = length;
  829.       }
  830.       this._owner.ncConnected();
  831.    }
  832.    function _onFCSConnectTimeOut()
  833.    {
  834.       this.cleanConns();
  835.       this._nc = undefined;
  836.       this._ncConnected = false;
  837.       if(!this.connectAgain())
  838.       {
  839.          this._owner.ncConnected();
  840.       }
  841.    }
  842.    static function stripFrontAndBackWhiteSpace(p_str)
  843.    {
  844.       var _loc1_ = undefined;
  845.       var _loc2_ = p_str.length;
  846.       var _loc4_ = 0;
  847.       var _loc5_ = _loc2_;
  848.       _loc1_ = 0;
  849.       for(; _loc1_ < _loc2_; _loc1_ = _loc1_ + 1)
  850.       {
  851.          switch(p_str.charCodeAt(_loc1_))
  852.          {
  853.             case 9:
  854.             case 10:
  855.             case 13:
  856.             case 32:
  857.                continue;
  858.             default:
  859.                _loc4_ = _loc1_;
  860.          }
  861.       }
  862.       _loc1_ = _loc2_;
  863.       for(; _loc1_ >= 0; _loc1_ = _loc1_ - 1)
  864.       {
  865.          switch(p_str.charCodeAt(_loc1_))
  866.          {
  867.             case 9:
  868.             case 10:
  869.             case 13:
  870.             case 32:
  871.                continue;
  872.             default:
  873.                _loc5_ = _loc1_ + 1;
  874.          }
  875.       }
  876.       if(_loc5_ <= _loc4_)
  877.       {
  878.          return "";
  879.       }
  880.       return p_str.slice(_loc4_,_loc5_);
  881.    }
  882. }
  883.