@@ -87,13 +87,15 @@ class WebSocketUtil implements IFlxDestroyable {
87
87
* Usefull for trying to connect to a WebSocket Server whilst the game is running.
88
88
* WARNING: CAN CAUSE ERRORS IN HSCRIPT!!
89
89
**/
90
- public var _threadedConnection : Bool = true ;
90
+ public var _threadedConnection : Bool = false ;
91
91
92
92
/**
93
93
* If true, when you call `send` the WebSocket will attempt to send in a new thread.
94
94
* WARNING: CAN CAUSE ERRORS IN HSCRIPT!!
95
95
**/
96
96
public var _threadedSend : Bool = false ;
97
+
98
+ @:dox (hide ) public var __packets : Array <Dynamic > = [];
97
99
98
100
/**
99
101
* @param url The URL of the WebSocket. Usually `ws://localhost:port`.
@@ -130,6 +132,7 @@ class WebSocketUtil implements IFlxDestroyable {
130
132
} catch (e ) {
131
133
this .onError (e );
132
134
}
135
+ __packets .push (data );
133
136
};
134
137
135
138
this .webSocket .onclose = function () {
@@ -145,6 +148,10 @@ class WebSocketUtil implements IFlxDestroyable {
145
148
if (immediateOpen ) this .open ();
146
149
}
147
150
151
+ public function getRecentPacket (): Dynamic {
152
+ return __packets .shift ();
153
+ }
154
+
148
155
/**
149
156
* @param rawData The raw data from the server
150
157
* @return The packet data if it was found, otherwise null and WebSocketUtil will handle it.
@@ -229,19 +236,12 @@ class WebSocketUtil implements IFlxDestroyable {
229
236
* Sends data to the server
230
237
**/
231
238
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
+ }
245
245
}
246
246
247
247
private var _isClosed : Bool = false ;
0 commit comments