AUX VM Browser
A set of utilities required to run an AUX in a web browser.
Installation
- Install the NPM package
npm install @casual-simulation/aux-vm-browser
- Add the
WorkerEntry.js
file to your Webpack config:
entry: {
vm: path.resolve(
__dirname,
'node_modules',
'@casual-simulation',
'aux-vm-browser',
'html',
'WorkerEntry.js'
),
},
- Add the
iframe_host.html
file to your webpack config via the HtmlWebpackPlugin
:
new HtmlWebpackPlugin({
chunks: ['vm'],
template: path.resolve(
__dirname,
'node_modules',
'@casual-simulation',
'aux-vm-browser',
'html',
'iframe_host.html'
),
title: 'AUX VM',
filename: 'aux-vm-iframe.html',
}),
- Ensure that
aux-vm-iframe.html
is available at the root path of the site.
Usage
Connect to an AUX
import { BotManager, AuxVMImpl } from '@casual-simulation/aux-vm-browser';
import { AuxUser } from '@casual-simulation/aux-vm';
start();
async function start() {
const user: AuxUser = {
id: 'myUserId',
username: 'myUsername',
name: 'myName',
token: 'mySecretToken',
isGuest: false,
};
const id = 'channelId';
const config = {
isBuilder: false,
isPlayer: false,
};
const partitions = BotManager.createPartitions(id, user, config);
const sim = new BotManager(
user,
id,
config,
new AuxVMImpl(user, {
config,
partitions,
})
);
await sim.init();
sim.connection.syncStateChanged.subscribe((synced) => {
if (synced) {
console.log("We're synced!");
} else {
console.log('No longer synced.');
}
});
}