2.1.3 • Published 7 months ago

haxball.js v2.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

NPM Version NPM Monthly Downloads

License Last Commit Language Most Used Implementations Repository Size

Forks Stars Watches

🔖 Table Of Contents


💻 Installing

npm install haxball.js

💻 Module Usage Example

// room.js

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: "<YOUR_PROXY_IP>" in your RoomConfig.

Example:

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

💻 (Optional) TypeScript

From v2.1.0, the package has basic typings included. Typings are automatically imported alongside haxball.js package.

Install TypeScript and ts-node in your project:

npm install typescript --save-dev
npm install ts-node --save-dev

Name the file room.ts instead of room.js and use example room code from the previous section.

You may run the server with ts-node room.ts instead of node room.js. To make it runnable with npm start, add the alias to package.json:

// package.json

//...
  "scripts": {
    "start": "ts-node run.ts"
  }
//...

💻 (Optional) Modularize Room Script

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.).

// super-futsal-room/index.ts

import { Headless } from "haxball.js"

// Every user installing the package will have to
// implement this interface in order to run it.
interface RoomArgs {
    token: string
    timeLimit: number
}

const roomBuilder = (HBInit: Headless, args: RoomArgs) => {
    let room = HBInit({
        roomName: "Hello TypeScript!",
        token: args.token
    })

    room.setTimeLimit(args.timeLimit)
}

export default roomBuilder;
// room-launcher/index.ts

// Local path as example, but may refer to installed npm package
import roomBuilder from "../super-futsal-room";
import HaxballJS from "haxball.js";

HaxballJS.then((HBInit => roomBuilder(HBInit, {
  // Interface for config arguments is provided by the room script author
  // Not defining them results in TypeScript error
  token: "YOUR_TOKEN_HERE",
  timeLimit: 3
})))

  • wrtc - WebRTC implementation for NodeJS
  • ws - Websocket Connection
  • JSON5 - JSON Helper Module
  • @peculiar/webcrypto - Webcrypto implementation for NodeJS
  • pako - ZLIP Port for NodeJS
  • node-fetch - HTTP Requests

Back To The Top


  • NPM
  • NodeJs

Back To The Top


  • Promise based
  • Synchronous
  • Performant
  • Strongly Typed

Back To The Top


  • Make a fork of this repository
  • Clone to you machine and entry on respective paste
  • Create a branch with your resource: git checkout -b my-feature
  • 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

Back To The Top


[Back To The Top](#title)


Copyright © 2023 [Mertushka <mertushka@proton.me>](https://github.com/mertushka)

This project is licensed by [MIT License](https://api.github.com/licenses/mit).

[Back To The Top](#title)


This README was generated with 💟 by [readme-template-generator](https://github.com/mertushka/readme-template-generator)

2.1.3

7 months ago

2.1.2

2 years ago

2.0.3

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.6.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.0.1

3 years ago