-
host dosbox-sync.js and dosbox.html.mem (from the public folder) online. Both files need to be hosted in the same location.
-
host dosgame file online as well
-
install package
npm install usedosbox
or
yarn add usedosbox
- update your react component
import React, { createRef, useEffect } from "react";
import { useDosbox } from "usedosbox";
function MyComponent() {
const canvasRef = createRef<CanvasElement>();
const {
startDosbox,
stopDosbox,
isDosboxLoading,
isDosboxReady,
loadedSize,
totalSize,
percentage,
} = useDosbox({
canvasRef,
gameFile: "https://example.com/path/to/gamefile.zip",
dosboxUrl: "https://example.com/path/to/dosbox-sync.js",
});
useEffect(() => {
return () => {
stopDosbox();
};
}, [stopDosbox]);
return (
<>
<button type="button" onClick={startDosbox}>
Start
</button>
<canvas
id="canvas"
ref={canvasRef}
styles={{ width: "600px", height: "400px" }}
/>
</>
);
}
starts dosbox
stops dosbox, recommended for page cleanup
true: dosbox is loading; false: dosbox is not loading
true: dosbox is ready; false: dosbox is not ready
how much game file buffer has been downloaded
e.g. 6kB
how large the final game file is
e.g. 104MB
percentage of game file download
e.g. 50
Yes, useDosbox uses Browserfs to store game save files in IndexedDB.
useDosbox will try to find dosbox.conf in the root directory of game zip. If a dosbox.conf exists, useDosbox will load dosbox using whatever configuration it specifies.