new RoomController( options [, hhm ] )

Description

RoomController provides an interface to communicate with HaxBall roomObject and Haxball Headless Manager (HHM).

Each RoomController controls one tab in the headless browser.

You can create new RoomController instances with the Haxroomie#addRoom factory method.

The API provides a Promise ready way to call the methods or optionally you can listen to the events each method fires.

Parameters
Name Type Attributes Description
options object

Options.

Name Type Attributes Default Description
id object

ID for the room.

page object

Puppeteer.Page object to control.

timeout number <optional>
30

Max time to wait in seconds for the room to open.

hhmVersion string <optional>

Version of Haxball Headless Manager to use.

hhm File <optional>

Haxball Headless Manager source.

Members


running :boolean

Description

Is the room running.

Details
boolean

false


hhmLoaded :boolean

Description

Is Haxball Headless Manager loaded.

Details
boolean

false


usable :boolean

Description

Is the instance still usable.

Details
boolean

true


roomInfo :object

Description

If room is running, contains its data (like e.g. roomInfo.roomLink). If not running, then this is null. Returns a copy of the original object.

Details
object

null


openRoomLock :boolean

Description

If opening of the room is in process, then this will be true.

Details
boolean

false


plugins :PluginController

Description

Object that can be used to control and get information about plugins.

Requires the room to be running!


repositories :RepositoryController

Description

Object that can be used to control and get information about repositories.

Requires the HHM library to be loaded!

To load HHM you can use the init() method or open the room with openRoom().


roles :RoleController

Description

Object that can be used to control and get information about roles.

Requires the room to be running and sav/roles plugin to be loaded and enabled!

Details
RoleController

Methods


<async> init( [ options ] )

Description

Initializes the RoomController by navigating the page to the headless HaxBall URL and loads the Haxball Headless Manager library.

This enables the use of the repositories object to get information about repositories before opening the room.

Note that calling close will undo this.

Parameters
Name Type Attributes Description
options object <optional>

Options.

Name Type Attributes Description
hhmVersion string <optional>

Version of Haxball Headless Manager to load. By default a compatible version is used.

hhm File <optional>

Optionally load HHM source from a string.


<async> openRoom( config ) → {object}

Description

Opens a HaxBall room in a browser tab.

On top of the documentated properties here, the config object can contain any properties you want to use in your own HHM config file.

The config object is usable globally from within the HHM config as the hrConfig object.

Parameters
Name Type Description
config object

Config object that contains the room information.

Name Type Attributes Description
token string

Token to start the room with. Obtain one from https://www.haxball.com/headlesstoken.

roomName string <optional>

Room name.

playerName string <optional>

Host player name.

maxPlayers int <optional>

Max players.

public boolean <optional>

Should the room be public?

geo object <optional>

Geolocation override for the room.

repositories Array.<Repository> <optional>

Array of HHM plugin repositories.

e.g. To load a repository from GitHub:

repositories: [
									  {
									    type: 'github',
									    repository: 'morko/hhm-sala-plugins',
									    path: 'src', // optional (defaults to src)
									    version: 'master', // optional (defaults to master)
									    suffix: '.js', // optional (defaults to .js)
									  }
									],
									

See Repository for the types of repositories you can use.

pluginConfig object <optional>

Haxball Headless Manager plugin config object. Passed to HHM.config.plugins.

See Haxball Headless Manager This tells HHM which plugins to load from the available repositories. You can also give the initial config to plugins here.

roomScript File <optional>

Regular haxball headless script to load when starting the room.

Disables the non essential default plugins.

hhmConfig File <optional>

Configuration for the haxball headless manager (HHM).

defaultRepoVersion string <optional>

Version of saviola's plugin repository for Haxball Headless Manager to load. By default a compatible version is used. This can be overriden by adding the repository in the repository property.

Returns
  • Config that the room was started with. The roomLink property is added to the config (contains URL to the room).
Throws
  • Something is wrong with the arguments.
  • The instance is not usable because the browser page crashed or closed.
  • The room is already running.
  • The room is already being opened.
  • Could not connect to HaxBall headless page.
  • Haxball Headless Manager took too much time to start.
  • The token is invalid or expired.

<async> closeRoom()

Description

Closes the headless HaxBall room by navigating the page out of the headless HaxBall URL.

Fires
Throws
  • The instance is not usable because the browser page crashed or closed.

<async> callRoom( fn ) → {Promise.<any>}

Description

Calls a function of the HaxBall roomObject in the browsers context.

Parameters
Name Type Description
fn string

Name of the haxball roomObject function.

..args any

Arguments for the function.

Returns
  • Return value of the called function.
Throws
  • The instance is not usable because the browser page crashed or closed.
  • The room is not running.

<async> eval( pageFunction [, ...args ] ) → {Promise.<Serializable>}

Description

Wrapper for Puppeteers page.evaluate.

Evaluates the given code in the browser tab this instace is controlling. You can access the HaxBall roomObject with HHM.manager.room.

e.g.

room.eval('HHM.manager.room.getPlayerList()');
			
Parameters
Name Type Attributes Description
pageFunction string | function

JavaScript to evaluate.

args Serializable | JSHandle <optional>
<repeatable>

Arguments to pass to js.

Returns
  • Promise which resolves to the return value of pageFunction.

Events


page-closed

Description

Emitted when the browser tab gets closed. Renders this RoomController unusable.

Parameters
Name Type Description
room RoomController

Instance of RoomController that was controlling the page.


page-crash

Description

Emitted when the browser tab crashes. Renders this RoomController unusable.

Parameters
Name Type Description
error Error

The error that was thrown.


page-error

Description

Emitted when some script throws an error in the browsers tab.

Parameters
Name Type Description
error Error

The error that was thrown.


error-logged

Description

Emitted when a browser tab logs an error to the console.

Parameters
Name Type Description
message string

The logged error message.


warning-logged

Description

Emitted when a browser tab logs a warning to the console.

Parameters
Name Type Description
message string

The logged warning message.


info-logged

Description

Emitted when a browser tab logs to console.

Parameters
Name Type Description
message string

The logged message.


open-room-start

Description

Emitted when RoomController#openRoom has been called.

Parameters
Name Type Attributes Description
error Error | UnusableError | RoomIsRunningError | RoomLockedError <optional>

If error happened when starting to open room.

config object

Config object given as argument to RoomController#openRoom


open-room-stop

Description

Emitted when RoomController#openRoom has finished and the room is running. e.g.

room.on('open-room-stop', (err, roomInfo)=> {
			  if (err) {
			    console.log('Room did not open.', err);
			  } else {
			    console.log('Room was opened', roomInfo);
			  }
			});
			room.openRoom(config);
			
Parameters
Name Type Attributes Description
error Error | ConnectionError | TimeoutError | InvalidTokenError <optional>
  • If error happened when opening the room.
roomInfo object

Information about the room.


close-room-start

Description

Emitted when RoomController#closeRoom has been called.

Parameters
Name Type Attributes Description
error UnusableError <optional>

If the room is at unusable state.


close-room-stop

Description

Emitted when RoomController#closeRoom has finished.

Parameters
Name Type Attributes Description
error Error <optional>

If error happened during closeRoom.


room-event

Description

Emitted when supported HaxBall roomObject event happens.

Parameters
Name Type Description
roomEventArgs RoomEventArgs

Event arguments.


plugin-loaded

Description

Emitted when a plugin is loaded.

Parameters
Name Type Description
pluginData PluginData

Information about the plugin.


plugin-removed

Description

Emitted when a plugin is removed.

Parameters
Name Type Description
pluginData PluginData

Information about the plugin.


plugin-enabled

Description

Emitted when a plugin is enabled.

Parameters
Name Type Description
pluginData PluginData

Information about the plugin.


plugin-disabled

Description

Emitted when a plugin is disabled.

Parameters
Name Type Description
pluginData PluginData

Information about the plugin.