Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions frontend/Instance.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Show } from "solid-js";
import { Component, Show, createSignal } from "solid-js";
import { Flex, createDisclosure, notificationService } from "@hope-ui/solid";

import { Instance as InstanceData } from "../types/instance";
Expand All @@ -12,12 +12,13 @@ const Instance: Component<{
setSearch: (search: Search) => void;
}> = (props) => {
let iframeRef: HTMLIFrameElement | undefined = undefined;
let [dropUpdates, setDropUpdates] = createSignal(false);

const handleReload = () => {
if (iframeRef == null) {
return;
}

setDropUpdates(false) // reset our state because inner sim/webxdc state is reset in reload
iframeRef.contentWindow?.postMessage("reload", props.instance.url);

notificationService.show({
Expand All @@ -29,6 +30,14 @@ const Instance: Component<{
defaultIsOpen: false,
});

const toggleDropUpdates = () => {
if (iframeRef == null) {
return;
}
setDropUpdates(!dropUpdates())
iframeRef.contentWindow?.postMessage({ name: "dropUpdates", value: dropUpdates()}, props.instance.url)
}

const getStyle = () => {
return {
// XXX these dimensions should be configurable somehow
Expand All @@ -49,6 +58,8 @@ const Instance: Component<{
onStart={onOpen}
onStop={onClose}
isStarted={isOpen}
dropUpdates={dropUpdates()}
onToggleDropUpdates={toggleDropUpdates}
/>
<Show
when={isOpen()}
Expand Down
8 changes: 8 additions & 0 deletions frontend/InstanceHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "@hope-ui/solid";
import { IoRefreshOutline, IoStop, IoPlay } from "solid-icons/io";
import { FiExternalLink, FiTrash } from "solid-icons/fi";
import { RiDeviceWifiLine, RiDeviceWifiOffLine } from 'solid-icons/ri'

import type { Instance as InstanceData } from "../types/instance";
import { sent, received, mutateInstances } from "./store";
Expand All @@ -21,6 +22,8 @@ const InstanceHeader: Component<{
onStart: () => void;
onStop: () => void;
isStarted: Accessor<boolean>;
dropUpdates: boolean;
onToggleDropUpdates: () => void;
}> = (props) => {
const sentCount = createMemo(() => {
return sent(props.instance.id);
Expand Down Expand Up @@ -113,6 +116,11 @@ const InstanceHeader: Component<{
onClick={() => handleRemoveInstance(props.instance.id)}
icon={<FiTrash size={22} color="#000000" />}
/>
<InstanceButton
label="Drop Updates"
onClick={props.onToggleDropUpdates}
icon={props.dropUpdates ? <RiDeviceWifiOffLine size={22} color={"#FF0000"} /> : <RiDeviceWifiLine size={22} color={"#000000"} /> }
/>
</Flex>
</Flex>
);
Expand Down
1 change: 0 additions & 1 deletion sim/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export function createWebXdc(
setUpdateListener: (listener, serial = 0): Promise<void> => {
transport.onMessage((message) => {
if (isUpdatesMessage(message)) {
log("recv update", message.updates);
for (const update of message.updates) {
listener(update);
}
Expand Down
18 changes: 18 additions & 0 deletions sim/webxdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ export class DevServerTransport implements Transport {
messageListener: SocketMessageListener | null = null;
promise: Promise<Info>;
resolveInfo!: (info: Info) => void;
dropUpdates: boolean = false;

constructor(url: string) {
this.socket = new WebSocket(url);
this.promise = new Promise((resolve) => {
this.resolveInfo = resolve;
});
window.addEventListener("message", (event) => {
const isAllowed =
event.origin.includes("localhost:") ||
(location.host.endsWith(".webcontainer.io") &&
event.origin.includes(".webcontainer.io"));
if (!isAllowed) {
return;
}
if (typeof event.data === 'object') {
if (event.data.name === 'dropUpdates') {
this.dropUpdates = event.data.value
}
}
});
}

send(data: any): void {
Expand All @@ -34,6 +49,9 @@ export class DevServerTransport implements Transport {
this.socket.removeEventListener("message", this.messageListener);
}
const listener = (event: Event): void => {
if (this.dropUpdates) {
return
}
callback(JSON.parse((event as any).data));
};
this.messageListener = listener;
Expand Down