haxball.js 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/package.json +4 -2
- package/src/index.js +2 -1
- package/test/room.js +1 -1
- package/types/index.d.ts +6 -0
package/README.md
CHANGED
|
@@ -32,16 +32,18 @@ npm install haxball.js
|
|
|
32
32
|
#### 💻 Module Usage Example
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
+
// room.js
|
|
36
|
+
|
|
35
37
|
const HaxballJS = require("haxball.js");
|
|
36
38
|
|
|
37
39
|
HaxballJS.then((HBInit) => {
|
|
38
|
-
//
|
|
40
|
+
// Same as in Haxball Headless Host Documentation
|
|
39
41
|
const room = HBInit({
|
|
40
42
|
roomName: "Haxball.JS",
|
|
41
43
|
maxPlayers: 16,
|
|
42
44
|
public: true,
|
|
43
45
|
noPlayer: true,
|
|
44
|
-
token: "
|
|
46
|
+
token: "YOUR_TOKEN_HERE", // Required
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
room.setDefaultStadium("Big");
|
|
@@ -54,6 +56,61 @@ HaxballJS.then((HBInit) => {
|
|
|
54
56
|
});
|
|
55
57
|
```
|
|
56
58
|
|
|
59
|
+
#### 💻 (Optional) TypeScript
|
|
60
|
+
From v2.1.0, the package has basic typings included. Typings are automatically imported alongside `haxball.js` package.
|
|
61
|
+
|
|
62
|
+
Install TypeScript and ts-node in your project:
|
|
63
|
+
```bash
|
|
64
|
+
npm install typescript --save-dev
|
|
65
|
+
npm install ts-node --save-dev
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Name the file `room.ts` instead of `room.js` and use example room code from the previous section.
|
|
69
|
+
|
|
70
|
+
You may run the server with `ts-node room.ts` instead of `node room.js`.
|
|
71
|
+
|
|
72
|
+
#### 💻 (Optional) Modularize Room Script
|
|
73
|
+
You can build full room scripts as NPM packages, that export `roomBuilder` function. These functions can be easily imported by another packages (launchers, remote orchestrators, etc.).
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// super-futsal-room/index.ts
|
|
77
|
+
|
|
78
|
+
import { Headless } from "haxball.js"
|
|
79
|
+
|
|
80
|
+
// Every user installing the package will have to
|
|
81
|
+
// implement this interface in order to run it.
|
|
82
|
+
interface RoomArgs {
|
|
83
|
+
token: string
|
|
84
|
+
timeLimit: number
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const roomBuilder = (HBInit: Headless, args: RoomArgs) => {
|
|
88
|
+
let room = HBInit({
|
|
89
|
+
roomName: "Hello TypeScript!",
|
|
90
|
+
token: args.token
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
room.setTimeLimit(args.timeLimit)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default roomBuilder;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
// room-launcher/index.ts
|
|
101
|
+
|
|
102
|
+
// Local path as example, but may refer to installed npm package
|
|
103
|
+
import roomBuilder from "../super-futsal-room";
|
|
104
|
+
import HaxballJS from "haxball.js";
|
|
105
|
+
|
|
106
|
+
HaxballJS.then((HBInit => roomBuilder(HBInit, {
|
|
107
|
+
// Interface for config arguments is provided by the room script author
|
|
108
|
+
// Not defining them results in TypeScript error
|
|
109
|
+
token: "YOUR_TOKEN_HERE",
|
|
110
|
+
timeLimit: 3
|
|
111
|
+
})))
|
|
112
|
+
```
|
|
113
|
+
|
|
57
114
|
---
|
|
58
115
|
|
|
59
116
|
<h2 id="technologies">🚀 Technologies</h2>
|
|
@@ -83,6 +140,7 @@ HaxballJS.then((HBInit) => {
|
|
|
83
140
|
- [x] Promise based
|
|
84
141
|
- [x] Synchronous
|
|
85
142
|
- [x] Performant
|
|
143
|
+
- [x] Strongly Typed
|
|
86
144
|
|
|
87
145
|
[Back To The Top](#title)
|
|
88
146
|
|
|
@@ -114,6 +172,7 @@ HaxballJS.then((HBInit) => {
|
|
|
114
172
|
<p>
|
|
115
173
|
|
|
116
174
|
<a href="https://github.com/mertushka"><img width="60" src="https://avatars1.githubusercontent.com/u/34413473?v=4"/>
|
|
175
|
+
<a href="https://github.com/jakjus"><img width="60" src="https://avatars.githubusercontent.com/u/43467994?v=4"/>
|
|
117
176
|
|
|
118
177
|
</p>
|
|
119
178
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "haxball.js",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A powerful library for interacting with the Haxball Headless API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "mocha --recursive --exit"
|
|
8
9
|
},
|
|
@@ -15,15 +16,16 @@
|
|
|
15
16
|
"author": "mertushka",
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"dependencies": {
|
|
19
|
+
"@koush/wrtc": "^0.5.3",
|
|
18
20
|
"@peculiar/webcrypto": "^1.3.3",
|
|
19
21
|
"json5": "^2.2.1",
|
|
20
22
|
"node-fetch": "^2.6.6",
|
|
21
23
|
"pako": "^2.0.4",
|
|
22
|
-
"wrtc": "^0.4.7",
|
|
23
24
|
"ws": "^8.5.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@mapbox/node-pre-gyp": "^1.0.9",
|
|
28
|
+
"@types/haxball-headless-browser": "^0.1.0",
|
|
27
29
|
"mocha": "^9.2.2"
|
|
28
30
|
},
|
|
29
31
|
"repository": {
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const wrtc = require("wrtc");
|
|
1
|
+
const wrtc = require("@koush/wrtc");
|
|
2
2
|
const fetch = require("node-fetch");
|
|
3
3
|
const WebSocket = require("ws");
|
|
4
4
|
const JSON5 = require("json5");
|
|
5
5
|
const pako = require("pako");
|
|
6
6
|
const { Crypto } = require("@peculiar/webcrypto");
|
|
7
|
+
const { performance } = require("perf_hooks");
|
|
7
8
|
const crypto = new Crypto();
|
|
8
9
|
const headless = new Promise((resolve) => {
|
|
9
10
|
(function (cb) {
|
package/test/room.js
CHANGED
|
@@ -10,7 +10,7 @@ describe("HBInit Tests", function () {
|
|
|
10
10
|
maxPlayers: 16,
|
|
11
11
|
public: true,
|
|
12
12
|
noPlayer: true,
|
|
13
|
-
token: "thr1.
|
|
13
|
+
token: "thr1.AAAAAGLmYKJ3LdGsopf1Mw.BWMK36G23Ys", // Make sure update here before testing
|
|
14
14
|
});
|
|
15
15
|
} catch (error) {
|
|
16
16
|
done(error);
|