@edwiser/moodle-playground-client
v0.1.0
Published
Embed and control Moodle Playground instances programmatically
Maintainers
Readme
@edwiser/moodle-playground-client
Embed and programmatically control Moodle Playground instances.
Usage
<iframe id="playground" style="width:100%;height:600px;border:none"></iframe>
<script type="module">
import { startMoodlePlayground } from '@edwiser/moodle-playground-client';
const iframe = document.getElementById('playground');
const playground = await startMoodlePlayground(iframe, {
moodleVersion: '5.0',
phpVersion: '8.3',
mode: 'seamless',
});
await playground.isReady();
await playground.navigate('/course/view.php?id=2');
</script>API
startMoodlePlayground(iframe, options)
remoteUrl-- URL of the playground remote.html (default: production)blueprint-- Blueprint object to applymoodleVersion-- Moodle version (default: "5.0")phpVersion-- PHP version (default: "8.3")mode-- Display mode (default: "seamless")lazy-- Defer boot until user interaction (default: false)
Returns a client handle with these methods:
isReady()-- Promise that resolves when the playground is readynavigate(path)-- Navigate to a Moodle URL pathrunPhp(code)-- Execute PHP code and return the outputlistFiles(dir)-- List files in a MEMFS directoryreadFile(path)-- Read a file from MEMFSwriteFile(path, data)-- Write a file to MEMFSexportSite()-- Export the playground state as a ZIPimportSite(zipBuffer)-- Import a ZIP to restore statedestroy()-- Clean up and disconnect
