PageRenderTime 34ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/bwcheck/src/actionscript/org/flowplayer/bwcheck/detect/BandwidthDetectorFms.as

https://github.com/longlho/flowplayer
ActionScript | 69 lines | 43 code | 12 blank | 14 comment | 5 complexity | 65d0c02d1d24c0c90fe26912cdba1f22 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause
  1. /*
  2. * This file is part of Flowplayer, http://flowplayer.org
  3. *
  4. * By: Daniel Rossi, <electroteque@gmail.com>, Anssi Piirainen Flowplayer Oy
  5. * Copyright (c) 2008-2011 Flowplayer Oy *
  6. * Released under the MIT License:
  7. * http://www.opensource.org/licenses/mit-license.php
  8. */
  9. package org.flowplayer.bwcheck.detect {
  10. import org.flowplayer.bwcheck.detect.*;
  11. import org.flowplayer.bwcheck.detect.AbstractDetectionStrategy;
  12. import flash.utils.setTimeout;
  13. /**
  14. * @author danielr
  15. */
  16. public class BandwidthDetectorFms extends AbstractDetectionStrategy {
  17. private var _host:String;
  18. public function set host(host:String):void {
  19. _host = host;
  20. }
  21. public function onBWCheck(... rest):Number {
  22. log.debug("onBWCheck");
  23. dispatchStatus(rest);
  24. return 0;
  25. }
  26. private function checkBandwidth():void {
  27. connection.call(_service, null);
  28. }
  29. public function onBWDone(... rest):void {
  30. //fixes for #218 cloudfront FMS is unstable to returns zero on the first few calls
  31. //fix for #234 was dispatching event on the first call
  32. if (rest[0] == 0 || rest[0] == null) {
  33. log.debug("Bandwidth Returned is zero starting again");
  34. connection.call(_service, null);
  35. //setTimeout(checkBandwidth, 1000);
  36. } else {
  37. connection.close();
  38. log.debug("onBWDone() " + rest);
  39. var obj:Object = new Object();
  40. obj.kbitDown = rest[0];
  41. obj.latency = rest[3];
  42. dispatchComplete(obj);
  43. }
  44. }
  45. override public function connect(host:String = null):void {
  46. connection.connect(host);
  47. }
  48. override public function detect():void {
  49. log.debug("detect() calling service " + _service);
  50. connection.client = this;
  51. connection.call(_service, null);
  52. }
  53. public function close(... rest):void {
  54. log.debug("close()");
  55. }
  56. }
  57. }