Socket
Book a DemoInstallSign in
Socket

@curvenote/connect

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@curvenote/connect

Communicate with iframes that want to render Jupyter outputs

latest
Source
npmnpm
Version
0.0.7
Version published
Maintainers
3
Created
Source

curvenote/connect

Communicate with webpages in iframes that want to receive content to render

In a host page

Include an iframe with the following attributes (examples here use React):

<iframe
  id={uid}
  name={uid}
  title={title}
  src={url}
  height={height ?? 150}
  sandbox="allow-scripts"
/>

The uid should be unqiue for each iframe, as there are potentially many on the host page.

It should also add the host.reducer as a slcice within it's Redux store:

import { host } from '@curvenote/connect';

const store = createStore(
  combineReducers({
    // other application reducers
    host: host.reducer,
  }),
  applyMiddleware(thunkMiddleware),
);

and register a message listener, connected to the store:

host.registerMessageListener(store);

Communication actions can then be dispatched to the iframe using the host.commsDispatch function.

import { host, actions } from '@curvenote/connect';

...

host.commsDispatch(
  iframeRef.current,
  actions.connectHostSendContent(uid, data)
);

In the iframe page

Similarly the iframe.reducer should be added to the Redux store for the page

import { iframe } from '@curvenote/connect';

const store = createStore(iframe.reducer, applyMiddleware(thunkMiddleware));

And two listener/observer functions are registered:

iframe.registerMessageListener(
  {
    origin: 'http://localhost:3000',
  },
  store,
  jsonRenderer,
);

iframe.registerResizeObserver(store, document);

Keywords

curvenote

FAQs

Package last updated on 20 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts