Implementation:A9T9 RPA Player Engine
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Playback_Engine |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for iterating macro command tables with a state-machine playback engine, provided by the Ui.Vision player module.
Description
The Player class (`src/common/player.js`) is a generic, reusable state machine that iterates over a list of resources (commands) and drives playback. It is not specific to RPA commands — it accepts `run`, `prepare`, and `handleResult` callbacks and manages the play/pause/resume/stop lifecycle, loop counting, start/end indices, breakpoints, and status transitions (`PLAYING`, `PAUSED`, `STOPPED`, `ERROR`). It emits lifecycle events: `START`, `PREPARED`, `TO_PLAY`, `PLAYED_LIST`, `PAUSED`, `RESUMED`, `END`, `ERROR`.
`getPlayer` is a factory that returns a singleton Player instance. `initTestCasePlayer` (in `src/modules/players.tsx`) wires the Player to the RPA-specific execution pipeline: it provides the `run` callback (which dispatches commands via `runCommandInPlayTab`), the `prepare` callback (preprocessing), and `handleResult` (log/screenshot capture). This serves both the classic macro recording playback workflow and the AI/MCP macro execution workflow.
Usage
Use the Player when you need to run a macro command table with loop control, pause/resume, breakpoints, and per-command result handling. The `initTestCasePlayer` wrapper is the normal entry point for RPA macros; `getPlayer` returns the shared instance.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/common/player.js (Player class L73-L665, getPlayer L665-L678); src/modules/players.tsx (initTestCasePlayer L108-L500)
Signature
export class Player {
constructor(opts: {
run: Function, // Execute one resource, returns a promise
prepare: Function, // Preprocess resources before play
handleResult: Function // Handle result of each resource
}, state?)
play(config: {
mode: MODE, // PLAY | LOOP | STEP
resources: any[], // Command list to iterate
startIndex: number,
endIndex?: number,
loopsStart?: number, // Loop mode
loopsEnd?: number,
breakpoints?: number[],
callback?: Function
}): void
pause(): void
resume(): void
stop(): void
}
export function getPlayer(opts, state?): Player
Import
import { Player, getPlayer } from '@/common/player'
// RPA-specific factory:
import { initTestCasePlayer } from '@/modules/players'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| opts.run | Function | Yes | Callback to execute a single command, returns a Promise |
| opts.prepare | Function | Yes | Preprocess the resource list before playback |
| opts.handleResult | Function | Yes | Handle the result of each command execution |
| config.resources | any[] | Yes | The command table (array of Command objects) |
| config.mode | MODE | Yes | Playback mode (PLAY, LOOP, STEP) |
| config.startIndex | number | Yes | Index to start playback from |
Outputs
| Name | Type | Description |
|---|---|---|
| Player instance | Player | State machine with PLAYING/PAUSED/STOPPED/ERROR status |
| events | Event | Lifecycle events emitted (START, PREPARED, TO_PLAY, PLAYED_LIST, END, ERROR) |
Usage Examples
Initiate Classic Macro Playback
import { initTestCasePlayer } from '@/modules/players'
import { getVarsInstance } from '@/common/variables'
import { store } from '@/redux'
const player = initTestCasePlayer({
store,
vars: getVarsInstance(),
interpreter: window.interpreter,
xCmdCounter: 0,
ocrCmdCounter: 0,
proxyCounter: 0
})
player.play({
mode: 'PLAY',
resources: commandTable,
startIndex: 0
})
Generic Player with Custom Run Loop
import { Player } from '@/common/player'
const player = new Player({
run: (cmd) => executeCommand(cmd),
prepare: (resources) => Promise.resolve(resources),
handleResult: (result) => logResult(result)
})
player.play({ mode: 'PLAY', resources: cmds, startIndex: 0 })