PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/hxcom/Flash.hx

http://github.com/tong/hxcom
Haxe | 237 lines | 139 code | 47 blank | 51 comment | 15 complexity | ef0ec4b674290859a843797100aa10ac MD5 | raw file
Possible License(s): GPL-3.0
  1. package hxcom;
  2. #if js
  3. import hxcom.App;
  4. class Flash {
  5. static function __init__() {
  6. VERSION_REQUIRED = { major : 10, minor : 1 };
  7. var v = untyped swfobject.getFlashPlayerVersion();
  8. has = v.major >= VERSION_REQUIRED.major && v.minor >= VERSION_REQUIRED.minor;
  9. visible = false;
  10. }
  11. public static var VERSION_REQUIRED(default,null) : { major : Int, minor :Int };
  12. public static inline var H = 140;
  13. public static var has(default,null) : Bool;
  14. public static var visible(default,null) : Bool;
  15. public static var app(default,null) : String;
  16. public static var e : Dynamic;
  17. public static var q : JQ;
  18. public static function init( cb : Void->Void ) {
  19. if( !has ) cb();
  20. else {
  21. untyped swfobject.embedSWF( "hxcom.swf", "flash", "0", "0", VERSION_REQUIRED.major+"."+VERSION_REQUIRED.minor );
  22. var i = 0;
  23. var timer = new haxe.Timer( 50 );
  24. timer.run = function() {
  25. e = untyped js.Lib.document.getElementById( "flash" );
  26. try {
  27. if( e.init() ) {
  28. timer.stop();
  29. q = new JQ(e);
  30. has = true;
  31. jabber.SocketConnection.init( "flash", function(e:String){
  32. cb();
  33. });
  34. }
  35. timer.stop();
  36. } catch( e : Dynamic ) {
  37. if( ++i == 16 ) {
  38. timer.stop();
  39. has = false;
  40. cb();
  41. }
  42. }
  43. }
  44. }
  45. }
  46. public static function show( h : Int = 140 ) {
  47. if( !has ) return;
  48. q.css( 'height', h+'px' );
  49. q.css( 'width', '100%' );
  50. visible = true;
  51. }
  52. public static function hide() {
  53. if( !has ) return;
  54. q.css( 'height', '0px' );
  55. q.css( 'width', '0px' );
  56. visible = false;
  57. }
  58. //public static function height() {
  59. public static function activateApplication( id : String ) {
  60. if( !has ) return;
  61. e.activateApplication( Flash.app = id );
  62. }
  63. public static function activateRoom( id : String ) {
  64. if( !has ) return;
  65. e.activateRoom( id );
  66. }
  67. /*
  68. static function _openIt() {
  69. trace("ON OPEN");
  70. show();
  71. }
  72. static function _closeIt() {
  73. trace("ON CLOSE");
  74. hide();
  75. }
  76. */
  77. }
  78. #elseif flash
  79. import flash.display.Sprite;
  80. import flash.events.MouseEvent;
  81. import flash.events.KeyboardEvent;
  82. import flash.external.ExternalInterface;
  83. import hxcom.flash.App;
  84. class Flash {
  85. static function __init__() {
  86. RTMFP_SERVER = "rtmfp://stratus.adobe.com/";
  87. RTMFP_DEVKEY = haxe.Resource.getString( "cirrus_key" );
  88. }
  89. public static var RTMFP_SERVER(default,null) : String;
  90. public static var RTMFP_DEVKEY(default,null) : String;
  91. public static var visible(default,null) : Bool;
  92. static var container : Sprite;
  93. static var app : App;
  94. static var av : FlashAV;
  95. static var fs : FlashFileShare;
  96. static var str3am : FlashStr3am;
  97. //// JS -->>
  98. static function init() : Bool {
  99. //var socketbridge = new FlashSocketBridgeTLS();
  100. var socketbridge = new FlashSocketBridge();
  101. socketbridge.init();
  102. container = new Sprite();
  103. flash.Lib.current.addChild( container );
  104. FlashSFX.init();
  105. FlashTTS.init();
  106. hxcom.flash.LSO.init();
  107. //TODO
  108. //addApplication( FlashAV.getInstance() );
  109. av = FlashAV.getInstance();
  110. fs = FlashFileShare.getInstance();
  111. //str3am = FlashStr3am.getInstance();
  112. // temp
  113. activateApplication( FlashAV.ID );
  114. ExternalInterface.addCallback( "show", show );
  115. ExternalInterface.addCallback( "hide", hide );
  116. ExternalInterface.addCallback( "activateApplication", activateApplication );
  117. ExternalInterface.addCallback( "activateRoom", activateRoom );
  118. //flash.Lib.current.stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
  119. //flash.Lib.current.stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
  120. return true;
  121. }
  122. ///// --- JS ->
  123. static function show() {
  124. visible = true;
  125. }
  126. static function hide() {
  127. visible = false;
  128. }
  129. static function activateApplication( id : String ) {
  130. if( app != null ) {
  131. if( id == app.id )
  132. return;
  133. app.hide();
  134. container.removeChild( app );
  135. }
  136. switch( id ) {
  137. case FlashAV.ID : app = av;
  138. case FlashFileShare.ID : app = fs;
  139. }
  140. app.show();
  141. container.addChild( app );
  142. }
  143. static function activateRoom( id : String ) {
  144. trace("ACTIVE ROOM = "+id );
  145. }
  146. /////
  147. /*
  148. static function onKeyDown( e : KeyboardEvent ) {
  149. trace(e.keyCode);
  150. if( e.ctrlKey ) {
  151. switch( e.keyCode ) {
  152. case 4294967295 : //ctrl+x // WTF!
  153. toogleVisibility( FlashFileShare.ID );
  154. case 89 : //ctrl+y
  155. toogleVisibility( FlashAV.ID );
  156. }
  157. }
  158. }
  159. static function toogleVisibility( id : String ) {
  160. if( view.id == id ) {
  161. if( visible ) {
  162. //hide();
  163. // TODO notify javascript
  164. //Flash.onOpen();
  165. ExternalInterface.call( "hxcom.Flash._closeIt" );
  166. } else show();
  167. } else {
  168. setView( id );
  169. ExternalInterface.call( "hxcom.Flash._openIt" );
  170. //if( !visible ) show();
  171. }
  172. }
  173. */
  174. static function main() {
  175. #if DEBUG
  176. if( haxe.Firebug.detect() ) haxe.Firebug.redirectTraces();
  177. #end
  178. flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
  179. flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
  180. var cm = new flash.ui.ContextMenu();
  181. cm.hideBuiltInItems();
  182. flash.Lib.current.contextMenu = cm;
  183. visible = false;
  184. ExternalInterface.addCallback( "init", init );
  185. }
  186. }
  187. #end