An open API service indexing awesome lists of open source software.

https://github.com/next-dev-team/gameserver

This is sample starter build on leaf framework
https://github.com/next-dev-team/gameserver

Last synced: 10 months ago
JSON representation

This is sample starter build on leaf framework

Awesome Lists containing this project

README

          

game serve based on Leaf server framework
===========
A game server based on [Leaf framework](https://github.com/name5566/leaf).

```
import React, { useEffect, useState } from "react";
import "./App.css";
import { number } from "decoders";
import { Select } from "antd";
const { Option } = Select;
function App() {
const [data, setData] = useState({});
const [ws, setWebsocket] = useState();
const [isGameStarted, setIsGameStated] = useState(false);
useEffect(() => {
const ws = new WebSocket("ws://127.0.0.1:3654");
setWebsocket(ws);
ws.binaryType = "arraybuffer";
ws.onopen = (event) => {
// Send Hello message
ws.send(
JSON.stringify({
Hello: {
Name: "Sinak",
},
})
);
};

ws.onmessage = function (e) {
console.log("event:", e?.data?.size);
var decoder = new window.TextDecoder("utf-8");
var result = JSON.parse(decoder.decode(e.data));
console.log(result);
setData(result);
};
}, []);
useEffect(()=>{
ws?.send(
JSON.stringify({
GameState: {
status: isGameStarted? 2:1,
},
})
);
},[isGameStarted])

return (


Get started with web socket


Ready to guess!!


{JSON.stringify(data)}




{
setIsGameStated(!isGameStarted);
ws?.send(
JSON.stringify({
GameState: {
status: 1,
},
})
);
}}
>
{!isGameStarted ? "Start Game" : "Stop Game"}

{isGameStarted && (
<>
{
ws?.send(
JSON.stringify({
GuessGame: {
text: "big",
},
})
);

}}
>
Big

{
ws?.send(
JSON.stringify({
GuessGame: {
text: "small",
},
})
);

}}
>
Small

>
)}

);
}

export default App;

```

Licensing
---------

Leaf server is licensed under the Apache License, Version 2.0. See [LICENSE](https://github.com/name5566/leafserver/blob/master/LICENSE) for the full license text.