Skip to content

Commit

Permalink
update: adjust message according to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Mar 13, 2024
1 parent 78968fd commit 2dec312
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/other/jupyterlite/JupyterLiteSession.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { JupyterliteMessageSchema } from "@mat3ra/esse/lib/js/types";
import React from "react";

interface IframeMessage {
type: string;
data: Record<string, unknown>[];
variableName: string;
}

interface JupyterLiteSessionProps {
originURL: string;
defaultNotebookPath?: string;
Expand All @@ -27,17 +22,20 @@ class JupyterLiteSession extends React.Component<JupyterLiteSessionProps> {
window.removeEventListener("message", this.receiveMessage, false);
}

receiveMessage = (event: MessageEvent) => {
receiveMessage = (event: MessageEvent<JupyterliteMessageSchema>) => {
if (event.origin !== new URL(this.props.originURL).origin) return;
if (event.data) {
if (event.data.type === "from-iframe-to-host") {
if (this.props.receiveData) this.props.receiveData(event.data);
if (this.props.receiveData) this.props.receiveData(event.data.payload);
}
}
};

sendData = (data: Record<string, unknown>[], variableName: string) => {
const message: IframeMessage = { type: "from-host-to-iframe", data, variableName };
const message: JupyterliteMessageSchema = {
type: "from-host-to-iframe",
payload: { data, variableName },
};
const iframe = document.getElementById(this.props.frameId) as HTMLIFrameElement | null;
if (iframe && iframe.contentWindow) {
iframe.contentWindow.postMessage(message, this.props.originURL);
Expand Down

0 comments on commit 2dec312

Please sign in to comment.