Skip to content

mertushka/haxball.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

85 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NPM Version NPM Monthly Downloads

License Last Commit Language Most Used Implementations Repository Size

Forks Stars Watches

haxball.js

haxball.js is a powerful Node.js module that allows you to easily interact with the Haxball Headless API.

๐Ÿ”– Table Of Contents


๐Ÿค” How To Use

๐Ÿ’ป Installing

npm install haxball.js

Module Usage Example

const HaxballJS = require("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);
  };
});

(Optional) Proxy

Haxball has a limit of 2 rooms per IP. Therefore, you can use proxy with adding proxy: "http://<YOUR_PROXY_IP>" in your RoomConfig.

Example:

HBInit({
    ...
    proxy: "http://1.1.1.1:80",
});

๐Ÿ’ป TypeScript

TypeScript Example

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);
  };
});

๐Ÿ’ป (Optional, Highly Experimental!) Bun

It's highly experimental and risky to use it in a production environment, but haxball.js is compatible with Bun.JS.

bun install haxball.js
bun index.ts

๐Ÿš€ Technologies

  • node-datachannel - WebRTC implementation for Node.JS
  • ws - Websocket Connection
  • json5 - JSON Helper Module
  • @peculiar/webcrypto - WebCrypto implementation for Node.JS
  • pako - ZLIB port for NodeJS
  • xhr2 - W3C XMLHttpRequest implementation for Node.JS
  • https-proxy-agent - Websocket Proxy Support
  • @types/haxball-headless-browser - Type definitions

Back To The Top


๐ŸŒฑ Minimal Requirements

  • NPM
  • NodeJS Version >=18

Back To The Top


๐ŸŽŠ Features

  • Promise based
  • Synchronous
  • Performant
  • Strongly Typed

Back To The Top


๐Ÿ’ก How To Contribute

  • Make a fork of this repository
  • Clone to you machine and entry on respective paste
  • Make sure to update testing token on test/room.js with a valid one for Github Actions CI/CD (Important)
  • Create a branch from develop: git checkout -b my-feature develop
  • Commit your changes: git commit -m 'feat: My new feature'
  • Push your branch: git push origin my-feature
  • A green button will appear at the beginning of this repository
  • Click to open and fill in the pull request information

Contributions, issues and features requests are welcome!
๐Ÿ“ฎ Submit PRs to help solve issues or add features
๐Ÿ› Find and report issues
๐ŸŒŸ Star the project

Back To The Top


๐Ÿค— Contributors

Back To The Top


๐Ÿ” License

Copyright ยฉ 2023 mertushka & basro

This project is licensed by MIT License.

Back To The Top