Skip to content

Commit

Permalink
OpenFL dependency removed.
Browse files Browse the repository at this point in the history
New haxe targets have been added.
  • Loading branch information
barisyild committed Feb 21, 2020
1 parent 8b69164 commit 74291db
Show file tree
Hide file tree
Showing 71 changed files with 1,185 additions and 828 deletions.
108 changes: 62 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,77 @@
SmartFoxServer 2X Haxe Client API (Very Experimental)
=======================

SmartFoxServer 2X Haxe Client API
=======================

**Special Thanks**

[Originally created by **Vincent Blanchet**](https://github.com/boorik/smartfox-haxe-client)


**OpenFL Dependency is will removing soon!** (Coming Soon)

OpenFL Platforms
----------------------------------
|Platform|Support|
|--|--|
|HTML5|WS/WSS|
|Flash|WS/WSS/Socket/BlueBox|
|Adobe AIR|WS/Socket/BlueBox|
|Windows|WS/WSS/Socket/BlueBox|
|Flash|TCP Socket/WS/WSS/BlueBox|
|Adobe AIR|TCP Socket/WS/BlueBox|
|Windows|TCP Socket/WS/WSS/BlueBox|
|Linux|Untested|
|Mac OS|Untested|
|Android|Untested|
|iOS|Untested|
|Neko|Untested|
|Emscripten|Untested|
|Python|Coming Soon|
|HashLink|Coming Soon|

Pull requests are welcome

Let me know how it works on other targets

Pure Haxe translation of the as3 client for the Smartfox server http://www.smartfoxserver.com/

CURRENTLY WORKING WITH :
----------------------------------

haxe: 4.0.5

haxe-crypto: 0.0.7

haxe-ws: 1.0.5

----------------------------------

Instructions:
=====

Haxe Platforms
----------------------------------
|Platform|Support|
|--|--|
|Python|TCP Socket/WS/WSS|
|Neko|TCP Socket/WS/WSS|
|HashLink|TCP Socket/WS/WSS|
|CPP|TCP Socket/WS/WSS|
|Lua|Untested|
|C#|Untested|
|Java|Untested|
|PHP|FAIL (no thread support!)|

Pull requests are welcome

Let me know how it works on other targets.

Pure Haxe translation of the as3 client for the Smartfox server http://www.smartfoxserver.com/


Warning:
----------------------------------

**BlueBox is not optimized for multi threading, not recommended to use.**

**UDP Socket Support Dropped!** (If you need udp socket feature, please open issue.)


Currently Working With:
----------------------------------

haxe: 4.0.5

haxe-crypto: 0.0.7

haxe-ws: 1.0.5

----------------------------------

Instructions:
=====
Installation

```
haxelib git smartfox-haxe-client https://github.com/barisyild/smartfox-haxe-client.git
```
add in your project.xml:
```
add in your project.xml:
```
<haxelib name="smartfox-haxe-client"/>
```
Then you can use it like the as3 api, check the as3 exemples there :
http://docs2x.smartfoxserver.com/ExamplesFlash/introduction

TODO:
Then you can use it like the as3 api, check the as3 exemples there:
http://docs2x.smartfoxserver.com/ExamplesFlash/introduction

TODO:
====
* test app
* improve typing

Special Thanks
====
* test app
* improve typing
[Originally created by **Vincent Blanchet**](https://github.com/boorik/smartfox-haxe-client)
54 changes: 33 additions & 21 deletions com/smartfoxserver/v2/SmartFox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ import com.smartfoxserver.v2.util.ConfigLoader;
import com.smartfoxserver.v2.util.CryptoInitializer;
import com.smartfoxserver.v2.util.LagMonitor;
import com.smartfoxserver.v2.util.SFSErrorCodes;
import openfl.errors.ArgumentError;

import flash.errors.IllegalOperationError;
import flash.events.EventDispatcher;
import flash.system.Capabilities;
import com.smartfoxserver.v2.errors.ArgumentError;
import com.smartfoxserver.v2.events.EventDispatcher;

//--------------------------------------
// Connection events
Expand Down Expand Up @@ -825,10 +822,10 @@ class SmartFox extends EventDispatcher
private var _lagMonitor:LagMonitor;

// If true the client will fall back to BlueBox if no socket connection is available
private var _useBlueBox:Bool = true;
private var _useBlueBox:Bool = false;

//https WebSocket protocol (Adobe AIR Target may does not support WSS protocol)
public var useWSS:Bool = true;
public var useSSL:Bool = true;

// If true the client is connected
private var _isConnected:Bool = false;
Expand All @@ -838,6 +835,8 @@ class SmartFox extends EventDispatcher

// References the client's User object
private var _mySelf:User;

private var _configLoader:ConfigLoader;

// A unique session token, sent by the server during the handshake
private var _sessionToken:String;
Expand Down Expand Up @@ -882,13 +881,21 @@ class SmartFox extends EventDispatcher
#if flash
"Flash"
#elseif neko
"Neko"
"NekoVM"
#elseif linux
"Linux"
#elseif windows
"Windows"
#elseif cpp
"C++"
#elseif js
"JavaScript"
#elseif html5
"JavaScript"
#elseif hl
"HashLink"
#elseif python
"Python"
#else
"Unknown"
#end
Expand Down Expand Up @@ -1035,7 +1042,7 @@ class SmartFox extends EventDispatcher
if(!_isConnected && !_isConnecting)
_bitSwarm.ioHandler = ioHandler;
else
throw new IllegalOperationError("This operation must be executed before connecting!");
throw "This operation must be executed before connecting!";
}


Expand Down Expand Up @@ -1760,7 +1767,11 @@ class SmartFox extends EventDispatcher
// Checks if application is running as a standalone Adobe Air application
private function isAirRuntime():Bool
{
return Capabilities.playerType.toLowerCase() == "desktop";
#if (flash && air)
return flash.system.Capabilities.playerType.toLowerCase() == "desktop";
#else
return false;
#end
}

/**
Expand Down Expand Up @@ -1990,12 +2001,12 @@ class SmartFox extends EventDispatcher
*/
public function loadConfig(filePath:String="sfs-config.xml", connectOnSuccess:Bool=true):Void
{
var configLoader:ConfigLoader = new ConfigLoader();
configLoader.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
configLoader.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);
_configLoader = new ConfigLoader();
_configLoader.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
_configLoader.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);

_autoConnectOnConfig = connectOnSuccess;
configLoader.loadConfig(filePath);
_configLoader.loadConfig(filePath);
}

/** @private */
Expand Down Expand Up @@ -2074,12 +2085,11 @@ class SmartFox extends EventDispatcher

private function onConfigLoadSuccess(evt:SFSEvent):Void
{
var cfgLoader:ConfigLoader = cast evt.target;
var cfgData:ConfigData = cast evt.params.cfg;

// Remove listeners
cfgLoader.removeEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
cfgLoader.removeEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);
_configLoader.removeEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
_configLoader.removeEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);

// Validate and store configuration
validateAndStoreConfig(cfgData);
Expand All @@ -2093,19 +2103,21 @@ class SmartFox extends EventDispatcher
{
connect(_config.host, _config.port);
}

_configLoader = null;
}

private function onConfigLoadFailure(evt:SFSEvent):Void
{
var cfgLoader:ConfigLoader = cast evt.target;

// remove listeners
cfgLoader.removeEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
cfgLoader.removeEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);
_configLoader.removeEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoadSuccess);
_configLoader.removeEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailure);

// Fire event;
var sfsEvt:SFSEvent = new SFSEvent(SFSEvent.CONFIG_LOAD_FAILURE, { } );
dispatchEvent(sfsEvt);

_configLoader = null;
}


Expand Down
Loading

0 comments on commit 74291db

Please sign in to comment.