Members
-
running :boolean
-
Description
Is the room running.
Details
-
hhmLoaded :boolean
-
Description
Is Haxball Headless Manager loaded.
Details
-
usable :boolean
-
Description
Is the instance still usable.
Details
-
roomInfo :object
-
Description
If room is running, contains its data (like e.g.
roomInfo.roomLink
). If not running, then this isnull
. Returns a copy of the original object.Details
-
openRoomLock :boolean
-
Description
If opening of the room is in process, then this will be
true
.Details
-
plugins :PluginController
-
Description
Object that can be used to control and get information about plugins.
Requires the room to be running!
Details
-
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().
Details
-
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
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.
Details
-
<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
Fires
Throws
Details
-
<async> closeRoom()
-
Description
Closes the headless HaxBall room by navigating the page out of the headless HaxBall URL.
Fires
Throws
Details
-
<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
Throws
Details
-
<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
Details
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.
Details
-
page-crash
-
Description
Emitted when the browser tab crashes. Renders this RoomController unusable.
Parameters
Name Type Description error
Error The error that was thrown.
Details
-
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.
Details
-
error-logged
-
Description
Emitted when a browser tab logs an error to the console.
Parameters
Name Type Description message
string The logged error message.
Details
-
warning-logged
-
Description
Emitted when a browser tab logs a warning to the console.
Parameters
Name Type Description message
string The logged warning message.
Details
-
info-logged
-
Description
Emitted when a browser tab logs to console.
Parameters
Name Type Description message
string The logged message.
Details
-
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
Details
-
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.
Details
-
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.
Details
-
close-room-stop
-
Description
Emitted when RoomController#closeRoom has finished.
Parameters
Name Type Attributes Description error
Error <optional> If error happened during closeRoom.
Details
-
room-event
-
Description
Emitted when supported HaxBall roomObject event happens.
Parameters
Name Type Description roomEventArgs
RoomEventArgs Event arguments.
Details
-
plugin-loaded
-
Description
Emitted when a plugin is loaded.
Parameters
Name Type Description pluginData
PluginData Information about the plugin.
Details
-
plugin-removed
-
Description
Emitted when a plugin is removed.
Parameters
Name Type Description pluginData
PluginData Information about the plugin.
Details
-
plugin-enabled
-
Description
Emitted when a plugin is enabled.
Parameters
Name Type Description pluginData
PluginData Information about the plugin.
Details
-
plugin-disabled
-
Description
Emitted when a plugin is disabled.
Parameters
Name Type Description pluginData
PluginData Information about the plugin.
Details