haxball.js is a powerful Node.js module that allows you to easily interact with the Haxball Headless API.
- ๐ค How To Use
- ๐ Technologies
- ๐ฑ Minimal Requirements
- ๐ Features
- ๐ก How To Contribute
- ๐ License
npm install haxball.jsconst HaxballJS = require('haxball.js').default;import HaxballJS from 'haxball.js';import HaxballJS from 'haxball.js';
HaxballJS().then((HBInit) => {
// Same as in Haxball Headless Host Documentation
const room = HBInit({
roomName: 'Haxball.JS',
maxPlayers: 16,
public: true,
noPlayer: true,
token: 'YOUR_TOKEN_HERE', // Required
});
room.setDefaultStadium('Big');
room.setScoreLimit(5);
room.setTimeLimit(0);
room.onRoomLink = function (link) {
console.log(link);
};
// If there are no admins left in the room give admin to one of the remaining players.
function updateAdmins() {
// Get all players
var players = room.getPlayerList();
if (players.length == 0) return; // No players left, do nothing.
if (players.find((player) => player.admin) != null) return; // There's an admin left so do nothing.
room.setPlayerAdmin(players[0].id, true); // Give admin to the first non admin player in the list
}
room.onPlayerJoin = function (player) {
updateAdmins();
};
room.onPlayerLeave = function (player) {
updateAdmins();
};
});Haxball.JS uses @webrtc-node/webrtc as the default WebRTC library. However, you can use a custom WebRTC implementation by specifying it in the HaxballJS config using the webrtc option.
Example:
import HaxballJS from 'haxball.js';
import {
RTCPeerConnection,
RTCIceCandidate,
RTCSessionDescription,
} from './custom-webrtc.js';
HaxballJS({
webrtc: {
RTCPeerConnection,
RTCIceCandidate,
RTCSessionDescription,
},
}).then((HBInit) => {...});Haxball has a limit of 2 rooms per IP. Therefore, you can use proxy with adding proxy: "http://<YOUR_PROXY_IP>" in your HaxballJS config.
Example:
HaxballJS({ proxy: "http://1.1.1.1:80", }).then((HBInit) => {...});- @webrtc-node/webrtc - WebRTC implementation for Node.JS
- ws - Websocket Connection
- json5 - JSON Helper Module
- Node.js Web Crypto API - WebCrypto implementation
- Node.js Zlib API - native compression support
- xhr2 - W3C XMLHttpRequest implementation for Node.JS
- https-proxy-agent - Websocket Proxy Support
- npm
- Node.js Version >=22.18
- Performant
- Strongly Typed
Please check CONTRIBUTING.md
Contributions, issues and features requests are welcome!
๐ฎ Submit PRs to help solve issues or add features
๐ Find and report issues
๐ Star the project
Copyright ยฉ This project is licensed by MIT License.