Skip to content

Commit

Permalink
rename realtime to hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Sep 14, 2021
1 parent 1390f26 commit 315a1c7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ dev.js
/dist/test/ra.zip
cmake-build-*
gulpfile.ts
*.zip
*.zip
src/
2 changes: 1 addition & 1 deletion examples/digger/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
emulators.pathPrefix = "/dist/";
Dos(document.getElementById("jsdos"), {
style: "dark",
realtime: window.realtime,
hardware: window.hardware,
}).run("digger-v3.jsdos");
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-dos",
"version": "7.1.2",
"version": "7.1.3",
"description": "Easiest API to run dos programs in browser",
"main": "dist/js-dos.js",
"types": "dist/types/js-dos-player.d.ts",
Expand Down
40 changes: 20 additions & 20 deletions src/hardware-transport-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { TransportLayer, ClientMessage, MessageHandler, ServerMessage } from "emulators/dist/types/protocol/protocol";
import * as base64 from "base64-js";

export interface Realtime {
export interface Hardware {
readConfig(): string;
sendMessage(payload: string): void;
addKey(key: number, pressed: number, timeMs: number): void;
Expand All @@ -17,7 +17,7 @@ const textDecoder = new TextDecoder();

class HardwareTransportLayer implements TransportLayer {
sessionId: string = Date.now() + "";
realtime: Realtime;
hardware: Hardware;


private alive = true;
Expand All @@ -26,12 +26,12 @@ class HardwareTransportLayer implements TransportLayer {

private handler: MessageHandler = () => { /**/ };

constructor(realtime: Realtime) {
this.realtime = realtime;
constructor(realtime: Hardware) {
this.hardware = realtime;
}

callMain() {
this.realtime.sendMessage("wc-install\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-install\n" + this.sessionId + "\n");
requestAnimationFrame(this.update.bind(this));
}

Expand All @@ -43,51 +43,51 @@ class HardwareTransportLayer implements TransportLayer {

switch (name) {
case "wc-run": {
let errorMessage = this.realtime.writeFile("bundle_0.zip", encode(props.bundles[0]));
let errorMessage = this.hardware.writeFile("bundle_0.zip", encode(props.bundles[0]));

if (errorMessage.length > 0) {
console.error(errorMessage);
throw new Error(errorMessage);
}

if (props.bundles[1] !== undefined) {
errorMessage = this.realtime.writeFile("bundle_1.zip", encode(props.bundles[0]));
errorMessage = this.hardware.writeFile("bundle_1.zip", encode(props.bundles[0]));
if (errorMessage.length > 0) {
console.error(errorMessage);
throw new Error(errorMessage);
}
}

const payload = "wc-run\n";
this.realtime.sendMessage(payload);
this.hardware.sendMessage(payload);
} break;
case "wc-add-key": {
this.realtime.addKey(props.key, props.pressed ? 1 : 0, props.timeMs);
this.hardware.addKey(props.key, props.pressed ? 1 : 0, props.timeMs);
} break;
case "wc-pause": {
this.realtime.sendMessage("wc-pause\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-pause\n" + this.sessionId + "\n");
} break;
case "wc-resume": {
this.realtime.sendMessage("wc-resume\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-resume\n" + this.sessionId + "\n");
} break;
case "wc-mute": {
this.realtime.sendMessage("wc-mute\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-mute\n" + this.sessionId + "\n");
} break;
case "wc-unmute": {
this.realtime.sendMessage("wc-unmute\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-unmute\n" + this.sessionId + "\n");
} break;
case "wc-exit": {
this.alive = false;
this.realtime.sendMessage("wc-exit\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-exit\n" + this.sessionId + "\n");
} break;
case "wc-mouse-move": {
this.realtime.mouseMove(props.x, props.y, props.timeMs);
this.hardware.mouseMove(props.x, props.y, props.timeMs);
} break;
case "wc-mouse-button": {
this.realtime.mouseButton(props.button, props.pressed ? 1 : 0, props.timeMs);
this.hardware.mouseButton(props.button, props.pressed ? 1 : 0, props.timeMs);
} break;
case "wc-pack-fs-to-bundle": {
this.realtime.sendMessage("wc-pack-fs-to-bundle\n" + this.sessionId + "\n");
this.hardware.sendMessage("wc-pack-fs-to-bundle\n" + this.sessionId + "\n");
} break;
default: {
console.log("Unhandled client message (wc):", name, props);
Expand All @@ -108,7 +108,7 @@ class HardwareTransportLayer implements TransportLayer {
const props = optProps || {};
switch (name) {
case "ws-server-ready": {
const config = this.realtime.readConfig();
const config = this.hardware.readConfig();
this.handler("ws-config", { sessionId: this.sessionId, content: config });
// delay ws-server-ready until ws-sound-init
} break;
Expand Down Expand Up @@ -156,7 +156,7 @@ class HardwareTransportLayer implements TransportLayer {
return;
}

const framePayload = this.realtime.getFramePayload();
const framePayload = this.hardware.getFramePayload();
if (framePayload.length === 0) {
return;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ export class HardwareTransportLayerFactory {
};
}

createTransportLayer = (realtime: Realtime): TransportLayer => {
createTransportLayer = (realtime: Hardware): TransportLayer => {
const transport = new HardwareTransportLayer(realtime);
this.serverMessageHandler = transport.onServerMessage.bind(transport);
transport.callMain();
Expand Down
10 changes: 5 additions & 5 deletions src/js-dos-player.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DosInstance, DosFactoryType, DosOptions } from "emulators-ui/dist/types/js-dos";
import { Navbar } from "./js-dos-navbar";
import { createDiv } from "./dom";
import { Realtime, hardwareTransportLayerFactory } from "./hardware-transport-layer";
import { Hardware, hardwareTransportLayerFactory } from "./hardware-transport-layer";

declare const Dos: DosFactoryType;

Expand All @@ -10,7 +10,7 @@ const dosImpl = Dos;
export interface DosPlayerOptions extends DosOptions {
title?: string;
style?: "default" | "dark" | "none";
realtime?: Realtime;
hardware?: Hardware;
}

export interface DosPlayer extends DosInstance {
Expand Down Expand Up @@ -45,10 +45,10 @@ export function DosPlayer(root: HTMLDivElement, options?: DosPlayerOptions): Dos
options.layersOptions.keyboardDiv = keyboard;
options.layersOptions.fullscreenElement = root;

const realtime = options.realtime;
if (realtime !== undefined && realtime !== null) {
const hardware = options.hardware;
if (hardware !== undefined && hardware !== null) {
options.createTransportLayer = () => {
return hardwareTransportLayerFactory.createTransportLayer(realtime);
return hardwareTransportLayerFactory.createTransportLayer(hardware);
};
options.emulatorFunction = "backend";
}
Expand Down

0 comments on commit 315a1c7

Please sign in to comment.