raylib-wasm-transpiler/tools/js-class-c-struct-transpiler/test/test_server.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-06-13 01:08:44 -04:00
import LoginRequest from "./build/LoginRequest";
import LoginResponse from "./build/LoginResponse";
import User from "./build/User";
import Vector3 from "./build/Vector3";
2024-05-27 19:03:58 -04:00
var decoder = new TextDecoder("utf-8");
var port = 8089;
var ws = require("ws");
var wss = new ws.WebSocketServer({ port: port });
console.log("WebSocket server listening on ws://localhost:" + port + "/");
wss.on("connection", function (ws) {
console.log("Client connected!");
ws.on("message", function (message, isBinary) {
if (!isBinary) {
var text = decoder.decode(new Uint8Array(message).buffer);
console.log("received TEXT: " + text.length + " characters:");
console.log(' "' + text + '"');
} else {
2024-06-12 23:05:45 -04:00
const entity = new LoginRequest({}, new Uint8Array(message));
console.log(entity.Login.Email);
console.log(entity.Login.Password);
2024-06-13 01:08:44 -04:00
const user = new User({
Name: "Test User",
Login: entity.Login,
Position: new Vector3({ x: 0, y: 0, z: 0 }),
});
console.log(user.Name);
const response = new LoginResponse({ success: true });
ws.send(response._ptr, { binary: true }); // Echo back the received message
}
});
});