@@ -87,13 +87,15 @@ class WebSocketUtil implements IFlxDestroyable {
8787 * Usefull for trying to connect to a WebSocket Server whilst the game is running.
8888 * WARNING: CAN CAUSE ERRORS IN HSCRIPT!!
8989 **/
90- public var _threadedConnection : Bool = true ;
90+ public var _threadedConnection : Bool = false ;
9191
9292 /**
9393 * If true, when you call `send` the WebSocket will attempt to send in a new thread.
9494 * WARNING: CAN CAUSE ERRORS IN HSCRIPT!!
9595 **/
9696 public var _threadedSend : Bool = false ;
97+
98+ @:dox (hide ) public var __packets : Array <Dynamic > = [];
9799
98100 /**
99101 * @param url The URL of the WebSocket. Usually `ws://localhost:port`.
@@ -130,6 +132,7 @@ class WebSocketUtil implements IFlxDestroyable {
130132 } catch (e ) {
131133 this .onError (e );
132134 }
135+ __packets .push (data );
133136 };
134137
135138 this .webSocket .onclose = function () {
@@ -145,6 +148,10 @@ class WebSocketUtil implements IFlxDestroyable {
145148 if (immediateOpen ) this .open ();
146149 }
147150
151+ public function getRecentPacket (): Dynamic {
152+ return __packets .shift ();
153+ }
154+
148155 /**
149156 * @param rawData The raw data from the server
150157 * @return The packet data if it was found, otherwise null and WebSocketUtil will handle it.
@@ -229,19 +236,12 @@ class WebSocketUtil implements IFlxDestroyable {
229236 * Sends data to the server
230237 **/
231238 public function send (data ) {
232- var _func = () -> {
233- if (data is WebSocketPacket ) data = data .toString ();
234- try {
235- this .webSocket .send (data );
236- } catch (e ) {
237- this .onError (e );
238- }
239- };
240- // because its already threaded.
241- if (this ._threadedSend ) _func ();
242- else new FlxTimer ().start (0.01 , (tmr : FlxTimer ) -> {
243- _func ();
244- });
239+ if (data is WebSocketPacket ) data = data .toString ();
240+ try {
241+ this .webSocket .send (data );
242+ } catch (e ) {
243+ this .onError (e );
244+ }
245245 }
246246
247247 private var _isClosed : Bool = false ;
0 commit comments