/hxcom/Flash.hx
Haxe | 237 lines | 139 code | 47 blank | 51 comment | 15 complexity | ef0ec4b674290859a843797100aa10ac MD5 | raw file
Possible License(s): GPL-3.0
- package hxcom;
- #if js
- import hxcom.App;
- class Flash {
-
- static function __init__() {
- VERSION_REQUIRED = { major : 10, minor : 1 };
- var v = untyped swfobject.getFlashPlayerVersion();
- has = v.major >= VERSION_REQUIRED.major && v.minor >= VERSION_REQUIRED.minor;
- visible = false;
- }
-
- public static var VERSION_REQUIRED(default,null) : { major : Int, minor :Int };
- public static inline var H = 140;
-
- public static var has(default,null) : Bool;
- public static var visible(default,null) : Bool;
- public static var app(default,null) : String;
-
- public static var e : Dynamic;
- public static var q : JQ;
-
- public static function init( cb : Void->Void ) {
- if( !has ) cb();
- else {
- untyped swfobject.embedSWF( "hxcom.swf", "flash", "0", "0", VERSION_REQUIRED.major+"."+VERSION_REQUIRED.minor );
- var i = 0;
- var timer = new haxe.Timer( 50 );
- timer.run = function() {
- e = untyped js.Lib.document.getElementById( "flash" );
- try {
- if( e.init() ) {
- timer.stop();
- q = new JQ(e);
- has = true;
- jabber.SocketConnection.init( "flash", function(e:String){
- cb();
- });
- }
- timer.stop();
- } catch( e : Dynamic ) {
- if( ++i == 16 ) {
- timer.stop();
- has = false;
- cb();
- }
- }
- }
- }
- }
-
- public static function show( h : Int = 140 ) {
- if( !has ) return;
- q.css( 'height', h+'px' );
- q.css( 'width', '100%' );
- visible = true;
- }
-
- public static function hide() {
- if( !has ) return;
- q.css( 'height', '0px' );
- q.css( 'width', '0px' );
- visible = false;
- }
-
- //public static function height() {
-
- public static function activateApplication( id : String ) {
- if( !has ) return;
- e.activateApplication( Flash.app = id );
- }
-
- public static function activateRoom( id : String ) {
- if( !has ) return;
- e.activateRoom( id );
- }
-
- /*
- static function _openIt() {
- trace("ON OPEN");
- show();
- }
-
- static function _closeIt() {
- trace("ON CLOSE");
- hide();
- }
- */
- }
- #elseif flash
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.events.KeyboardEvent;
- import flash.external.ExternalInterface;
- import hxcom.flash.App;
- class Flash {
-
- static function __init__() {
- RTMFP_SERVER = "rtmfp://stratus.adobe.com/";
- RTMFP_DEVKEY = haxe.Resource.getString( "cirrus_key" );
- }
-
- public static var RTMFP_SERVER(default,null) : String;
- public static var RTMFP_DEVKEY(default,null) : String;
-
- public static var visible(default,null) : Bool;
-
- static var container : Sprite;
- static var app : App;
- static var av : FlashAV;
- static var fs : FlashFileShare;
- static var str3am : FlashStr3am;
-
- //// JS -->>
-
- static function init() : Bool {
-
- //var socketbridge = new FlashSocketBridgeTLS();
- var socketbridge = new FlashSocketBridge();
- socketbridge.init();
-
- container = new Sprite();
- flash.Lib.current.addChild( container );
-
- FlashSFX.init();
- FlashTTS.init();
-
- hxcom.flash.LSO.init();
-
- //TODO
- //addApplication( FlashAV.getInstance() );
- av = FlashAV.getInstance();
- fs = FlashFileShare.getInstance();
- //str3am = FlashStr3am.getInstance();
-
- // temp
- activateApplication( FlashAV.ID );
-
- ExternalInterface.addCallback( "show", show );
- ExternalInterface.addCallback( "hide", hide );
- ExternalInterface.addCallback( "activateApplication", activateApplication );
- ExternalInterface.addCallback( "activateRoom", activateRoom );
-
- //flash.Lib.current.stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
- //flash.Lib.current.stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
-
- return true;
- }
-
- ///// --- JS ->
-
- static function show() {
- visible = true;
- }
-
- static function hide() {
- visible = false;
- }
-
- static function activateApplication( id : String ) {
- if( app != null ) {
- if( id == app.id )
- return;
- app.hide();
- container.removeChild( app );
- }
- switch( id ) {
- case FlashAV.ID : app = av;
- case FlashFileShare.ID : app = fs;
- }
- app.show();
- container.addChild( app );
- }
-
- static function activateRoom( id : String ) {
- trace("ACTIVE ROOM = "+id );
- }
-
- /////
-
- /*
-
- static function onKeyDown( e : KeyboardEvent ) {
- trace(e.keyCode);
- if( e.ctrlKey ) {
- switch( e.keyCode ) {
- case 4294967295 : //ctrl+x // WTF!
- toogleVisibility( FlashFileShare.ID );
- case 89 : //ctrl+y
- toogleVisibility( FlashAV.ID );
- }
- }
- }
-
- static function toogleVisibility( id : String ) {
- if( view.id == id ) {
- if( visible ) {
- //hide();
- // TODO notify javascript
- //Flash.onOpen();
- ExternalInterface.call( "hxcom.Flash._closeIt" );
- } else show();
- } else {
- setView( id );
- ExternalInterface.call( "hxcom.Flash._openIt" );
- //if( !visible ) show();
- }
- }
- */
-
- static function main() {
-
- #if DEBUG
- if( haxe.Firebug.detect() ) haxe.Firebug.redirectTraces();
- #end
-
- flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
- flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
- var cm = new flash.ui.ContextMenu();
- cm.hideBuiltInItems();
- flash.Lib.current.contextMenu = cm;
-
- visible = false;
-
- ExternalInterface.addCallback( "init", init );
- }
-
- }
- #end