@casual-simulation/aux-vm-browser
Version:
A set of utilities required to securely run an AUX in a web browser.
103 lines • 4.86 kB
TypeScript
import type { AuxChannel, AuxChannelErrorType, AuxConfig, AuxSubChannel, AuxSubVM, AuxVM, ChannelActionResult } from '@casual-simulation/aux-vm/vm';
import type { BotAction, DeviceAction, PartitionAuthMessage, StateUpdatedEvent, StatusUpdate, StoredAux } from '@casual-simulation/aux-common';
import type { Observable } from 'rxjs';
import { Subject } from 'rxjs';
import type { AuxDevice, RuntimeActions, RuntimeStateVersion } from '@casual-simulation/aux-runtime';
import type { SimulationOrigin } from '@casual-simulation/aux-vm/managers';
export declare const DEFAULT_IFRAME_ALLOW_ATTRIBUTE = "accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking";
export declare const DEFAULT_IFRAME_SANDBOX_ATTRIBUTE = "allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts allow-downloads";
/**
* Defines an interface for an AUX that is run inside a virtual machine.
* That is, the AUX is run inside a web worker.
*
* This implementation works similarly to the one in AuxVMImpl, but instead of using an iframe, it loads the web worker directly.
*/
export default class StaticAuxVMImpl implements AuxVM {
protected _localEvents: Subject<RuntimeActions[]>;
protected _deviceEvents: Subject<DeviceAction[]>;
protected _connectionStateChanged: Subject<StatusUpdate>;
protected _stateUpdated: Subject<StateUpdatedEvent>;
protected _versionUpdated: Subject<RuntimeStateVersion>;
protected _onError: Subject<AuxChannelErrorType>;
protected _subVMAdded: Subject<AuxSubVM>;
protected _subVMRemoved: Subject<AuxSubVM>;
protected _subVMMap: Map<string, AuxSubVM & {
channel: AuxChannel;
}>;
protected _onAuthMessage: Subject<PartitionAuthMessage>;
protected _config: AuxConfig;
protected _channel: AuxChannel;
protected _id: string;
protected _relaxOrigin: boolean;
protected _origin: SimulationOrigin;
closed: boolean;
/**
* The ID of the simulation.
*/
get id(): string;
get configBotId(): string;
/**
* Creates a new Simulation VM.
* @param id The ID of the simulation.
* @param origin The origin of the simulation.
* @param config The config that should be used.
* @param relaxOrigin Whether to relax the origin of the VM.
*/
constructor(id: string, origin: SimulationOrigin, config: AuxConfig, relaxOrigin?: boolean);
get origin(): SimulationOrigin;
get subVMAdded(): Observable<AuxSubVM>;
get subVMRemoved(): Observable<AuxSubVM>;
get connectionStateChanged(): Observable<StatusUpdate>;
get onError(): Observable<AuxChannelErrorType>;
get onAuthMessage(): Observable<PartitionAuthMessage>;
/**
* The observable list of events that should be produced locally.
*/
get localEvents(): Observable<RuntimeActions[]>;
get deviceEvents(): Observable<DeviceAction[]>;
/**
* The observable list of bot state updates from this simulation.
*/
get stateUpdated(): Observable<StateUpdatedEvent>;
get versionUpdated(): Observable<RuntimeStateVersion>;
/**
* Initaializes the VM.
*/
init(): Promise<void>;
protected _init(): Promise<void>;
private _connect;
/**
* Sends the given list of events to the simulation.
* @param events The events to send to the simulation.
*/
sendEvents(events: BotAction[]): Promise<void>;
/**
* Executes a shout with the given event name on the given bot IDs with the given argument.
* Also dispatches any actions and errors that occur.
* Returns the results from the event.
* @param eventName The name of the event.
* @param botIds The IDs of the bots that the shout is being sent to.
* @param arg The argument to include in the shout.
*/
shout(eventName: string, botIds?: string[], arg?: any): Promise<ChannelActionResult>;
formulaBatch(formulas: string[]): Promise<void>;
forkAux(newId: string): Promise<void>;
exportBots(botIds: string[]): Promise<StoredAux>;
/**
* Exports the causal tree for the simulation.
*/
export(): Promise<StoredAux>;
getTags(): Promise<string[]>;
updateDevice(device: AuxDevice): Promise<void>;
/**
* Gets a new endpoint for the aux channel.
* Can then be used with a ConnectableAuxVM.
*/
createEndpoint(): Promise<MessagePort>;
sendAuthMessage(message: PartitionAuthMessage): Promise<void>;
unsubscribe(): void;
protected _createSubVM(id: string, origin: SimulationOrigin, configBotId: string, channel: AuxChannel): AuxVM;
protected _handleAddedSubChannel(subChannel: AuxSubChannel): Promise<void>;
protected _handleRemovedSubChannel(channelId: string): Promise<void>;
}
//# sourceMappingURL=StaticAuxVMImpl.d.ts.map