haxball.js 2.3.2 → 3.0.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/.github/dependabot.yml +11 -0
- package/.github/workflows/build.yml +8 -8
- package/README.md +15 -19
- package/package.json +5 -5
- package/scripts/nodeify.js +11 -3
- package/src/index.js +11 -3
- package/test/room.js +2 -2
- package/types/index.d.ts +8 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "npm" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
@@ -24,10 +24,10 @@ jobs:
|
|
|
24
24
|
outputs:
|
|
25
25
|
hash: ${{ steps.nodeify.outputs.hash }}
|
|
26
26
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
28
|
|
|
29
29
|
- name: 📦 Setup Node.js
|
|
30
|
-
uses: actions/setup-node@
|
|
30
|
+
uses: actions/setup-node@v4
|
|
31
31
|
with:
|
|
32
32
|
node-version: 22.x
|
|
33
33
|
cache: 'npm'
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
49
49
|
fi
|
|
50
50
|
|
|
51
51
|
- name: 📤 Upload Build Artifact
|
|
52
|
-
uses: actions/upload-artifact@
|
|
52
|
+
uses: actions/upload-artifact@v4
|
|
53
53
|
with:
|
|
54
54
|
name: haxball-build
|
|
55
55
|
path: src/build.js
|
|
@@ -66,16 +66,16 @@ jobs:
|
|
|
66
66
|
fail-fast: false
|
|
67
67
|
|
|
68
68
|
steps:
|
|
69
|
-
- uses: actions/checkout@
|
|
69
|
+
- uses: actions/checkout@v4
|
|
70
70
|
|
|
71
71
|
- name: 📦 Setup Node.js
|
|
72
|
-
uses: actions/setup-node@
|
|
72
|
+
uses: actions/setup-node@v4
|
|
73
73
|
with:
|
|
74
74
|
node-version: ${{ matrix.node-version }}
|
|
75
75
|
cache: 'npm'
|
|
76
76
|
|
|
77
77
|
- name: 📥 Download Build
|
|
78
|
-
uses: actions/download-artifact@
|
|
78
|
+
uses: actions/download-artifact@v4
|
|
79
79
|
with:
|
|
80
80
|
name: haxball-build
|
|
81
81
|
path: src
|
|
@@ -105,10 +105,10 @@ jobs:
|
|
|
105
105
|
contents: write
|
|
106
106
|
pull-requests: write
|
|
107
107
|
steps:
|
|
108
|
-
- uses: actions/checkout@
|
|
108
|
+
- uses: actions/checkout@v4
|
|
109
109
|
|
|
110
110
|
- name: 📥 Download Build
|
|
111
|
-
uses: actions/download-artifact@
|
|
111
|
+
uses: actions/download-artifact@v4
|
|
112
112
|
with:
|
|
113
113
|
name: haxball-build
|
|
114
114
|
path: src
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ npm install haxball.js
|
|
|
34
34
|
```js
|
|
35
35
|
const HaxballJS = require('haxball.js');
|
|
36
36
|
|
|
37
|
-
HaxballJS.then((HBInit) => {
|
|
37
|
+
HaxballJS().then((HBInit) => {
|
|
38
38
|
// Same as in Haxball Headless Host Documentation
|
|
39
39
|
const room = HBInit({
|
|
40
40
|
roomName: 'Haxball.JS',
|
|
@@ -54,6 +54,19 @@ HaxballJS.then((HBInit) => {
|
|
|
54
54
|
});
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
#### (Optional) Custom WebRTC Library
|
|
58
|
+
|
|
59
|
+
Haxball.JS uses `node-datachannel` as the default WebRTC library. However, you can use a custom WebRTC implementation by specifying it in the HaxballJS promise using the `webrtc` option.
|
|
60
|
+
|
|
61
|
+
Example:
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const HaxballJS = require('haxball.js');
|
|
65
|
+
const WebRTC = require('webrtc');
|
|
66
|
+
|
|
67
|
+
HaxballJS({ webrtc: WebRTC }).then((HBInit) => {...});
|
|
68
|
+
```
|
|
69
|
+
|
|
57
70
|
#### (Optional) Proxy
|
|
58
71
|
|
|
59
72
|
Haxball has a limit of 2 rooms per IP. Therefore, you can use proxy with adding `proxy: "http://<YOUR_PROXY_IP>"` in your `RoomConfig`.
|
|
@@ -74,24 +87,7 @@ HBInit({
|
|
|
74
87
|
```js
|
|
75
88
|
import HaxballJS from 'haxball.js';
|
|
76
89
|
|
|
77
|
-
HaxballJS.then((HBInit) => {
|
|
78
|
-
// Same as in Haxball Headless Host Documentation
|
|
79
|
-
const room = HBInit({
|
|
80
|
-
roomName: 'Haxball.JS',
|
|
81
|
-
maxPlayers: 16,
|
|
82
|
-
public: true,
|
|
83
|
-
noPlayer: true,
|
|
84
|
-
token: 'YOUR_TOKEN_HERE', // Required
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
room.setDefaultStadium('Big');
|
|
88
|
-
room.setScoreLimit(5);
|
|
89
|
-
room.setTimeLimit(0);
|
|
90
|
-
|
|
91
|
-
room.onRoomLink = function (link) {
|
|
92
|
-
console.log(link);
|
|
93
|
-
};
|
|
94
|
-
});
|
|
90
|
+
HaxballJS().then((HBInit) => {...});
|
|
95
91
|
```
|
|
96
92
|
|
|
97
93
|
#### 💻 (Optional, Highly Experimental!) Bun
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "haxball.js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A powerful library for interacting with the Haxball Headless API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@peculiar/webcrypto": "^1.5.0",
|
|
24
|
-
"@types/haxball-headless-browser": "
|
|
24
|
+
"@types/haxball-headless-browser": "^0.4.0",
|
|
25
25
|
"https-proxy-agent": "^7.0.6",
|
|
26
26
|
"json5": "^2.2.3",
|
|
27
|
-
"node-datachannel": "^0.
|
|
27
|
+
"node-datachannel": "^0.26.0",
|
|
28
28
|
"pako": "^2.1.0",
|
|
29
29
|
"ws": "^8.18.0",
|
|
30
30
|
"xhr2": "^0.2.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@mapbox/node-pre-gyp": "^
|
|
34
|
-
"mocha": "^
|
|
33
|
+
"@mapbox/node-pre-gyp": "^2.0.0",
|
|
34
|
+
"mocha": "^11.1.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
package/scripts/nodeify.js
CHANGED
|
@@ -146,16 +146,24 @@ const pako = require("pako");
|
|
|
146
146
|
const { HttpsProxyAgent } = require("https-proxy-agent");
|
|
147
147
|
const { Crypto } = require("@peculiar/webcrypto");
|
|
148
148
|
const { performance } = require("perf_hooks");
|
|
149
|
-
const { RTCPeerConnection, RTCIceCandidate, RTCSessionDescription } = require("node-datachannel/polyfill");
|
|
150
149
|
const crypto = new Crypto();
|
|
151
150
|
|
|
151
|
+
let { RTCPeerConnection, RTCIceCandidate, RTCSessionDescription } = require("node-datachannel/polyfill");
|
|
152
|
+
|
|
152
153
|
var promiseResolve;
|
|
153
154
|
var proxyAgent;
|
|
154
155
|
var debug = false;
|
|
155
156
|
|
|
156
|
-
const HBLoaded =
|
|
157
|
+
const HBLoaded = (config) => {
|
|
158
|
+
if(config?.webrtc) {
|
|
159
|
+
RTCPeerConnection = config.webrtc.RTCPeerConnection;
|
|
160
|
+
RTCIceCandidate = config.webrtc.RTCIceCandidate;
|
|
161
|
+
RTCSessionDescription = config.webrtc.RTCSessionDescription;
|
|
162
|
+
}
|
|
163
|
+
return new Promise(function (resolve, reject) {
|
|
157
164
|
promiseResolve = resolve;
|
|
158
|
-
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
159
167
|
|
|
160
168
|
const onHBLoaded = function (cb) {
|
|
161
169
|
return cb;
|
package/src/index.js
CHANGED
|
@@ -6,16 +6,24 @@ const pako = require("pako");
|
|
|
6
6
|
const { HttpsProxyAgent } = require("https-proxy-agent");
|
|
7
7
|
const { Crypto } = require("@peculiar/webcrypto");
|
|
8
8
|
const { performance } = require("perf_hooks");
|
|
9
|
-
const { RTCPeerConnection, RTCIceCandidate, RTCSessionDescription } = require("node-datachannel/polyfill");
|
|
10
9
|
const crypto = new Crypto();
|
|
11
10
|
|
|
11
|
+
let { RTCPeerConnection, RTCIceCandidate, RTCSessionDescription } = require("node-datachannel/polyfill");
|
|
12
|
+
|
|
12
13
|
var promiseResolve;
|
|
13
14
|
var proxyAgent;
|
|
14
15
|
var debug = false;
|
|
15
16
|
|
|
16
|
-
const HBLoaded =
|
|
17
|
+
const HBLoaded = (config) => {
|
|
18
|
+
if(config?.webrtc) {
|
|
19
|
+
RTCPeerConnection = config.webrtc.RTCPeerConnection;
|
|
20
|
+
RTCIceCandidate = config.webrtc.RTCIceCandidate;
|
|
21
|
+
RTCSessionDescription = config.webrtc.RTCSessionDescription;
|
|
22
|
+
}
|
|
23
|
+
return new Promise(function (resolve, reject) {
|
|
17
24
|
promiseResolve = resolve;
|
|
18
|
-
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
19
27
|
|
|
20
28
|
const onHBLoaded = function (cb) {
|
|
21
29
|
return cb;
|
package/test/room.js
CHANGED
|
@@ -16,7 +16,7 @@ describe('HBInit Tests', function () {
|
|
|
16
16
|
? it
|
|
17
17
|
: it.skip)('should create room', function (done) {
|
|
18
18
|
this.timeout(30000);
|
|
19
|
-
requireUncached('../src/build').then((HBInit) => {
|
|
19
|
+
requireUncached('../src/build')().then((HBInit) => {
|
|
20
20
|
let room = HBInit({
|
|
21
21
|
roomName: 'Haxball.JS',
|
|
22
22
|
maxPlayers: 16,
|
|
@@ -42,7 +42,7 @@ describe('HBInit Tests', function () {
|
|
|
42
42
|
|
|
43
43
|
if (process.env.CI_HB_PROXY == '1') return done(); // Skip since testing proxy on GitHub Actions is not practical, test this locally instead
|
|
44
44
|
|
|
45
|
-
requireUncached('../src/build').then((HBInit) => {
|
|
45
|
+
requireUncached('../src/build')().then((HBInit) => {
|
|
46
46
|
let room = HBInit({
|
|
47
47
|
roomName: 'Haxball.JS',
|
|
48
48
|
maxPlayers: 16,
|
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import 'haxball-headless-browser';
|
|
2
2
|
|
|
3
|
+
interface HaxballJSConfig {
|
|
4
|
+
webrtc?: any;
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
interface RoomConfigObjectM extends RoomConfigObject {
|
|
4
8
|
proxy?: string;
|
|
5
9
|
debug?: boolean;
|
|
6
10
|
}
|
|
7
|
-
export declare type Headless = (RoomConfig: RoomConfigObjectM) => RoomObject;
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
export type Headless = (roomConfig: RoomConfigObjectM) => RoomObject;
|
|
13
|
+
|
|
14
|
+
declare function HaxballJS(config?: HaxballJSConfig): Promise<Headless>;
|
|
15
|
+
|
|
10
16
|
export default HaxballJS;
|