forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
43
Kha/Sources/kha/netsync/WebSocketClient.hx
Normal file
43
Kha/Sources/kha/netsync/WebSocketClient.hx
Normal file
@ -0,0 +1,43 @@
|
||||
package kha.netsync;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
class WebSocketClient implements Client {
|
||||
var myId: Int;
|
||||
var socket: Dynamic;
|
||||
|
||||
public function new(id: Int, socket: Dynamic) {
|
||||
myId = id;
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
public function send(bytes: Bytes, mandatory: Bool): Void {
|
||||
socket.send(bytes.getData());
|
||||
// socket.send(bytes.getData(), {binary: true});
|
||||
}
|
||||
|
||||
public function receive(receiver: Bytes->Void): Void {
|
||||
socket.on('message', function(message) {
|
||||
// js.Node.console.log(message);
|
||||
receiver(Bytes.ofData(message));
|
||||
});
|
||||
}
|
||||
|
||||
public function onClose(close: Void->Void): Void {
|
||||
socket.onclose = function() {
|
||||
close();
|
||||
};
|
||||
}
|
||||
|
||||
public var controllers(get, null): Array<Controller>;
|
||||
|
||||
function get_controllers(): Array<Controller> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var id(get, null): Int;
|
||||
|
||||
function get_id(): Int {
|
||||
return myId;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user