# meteor-iframe

Make dataverse-kernel running in iframe.

## Installation

```bash
pnpm install @meteor-web3/meteor-iframe
```

## Run demo

### requirements

- [MetaMask](https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn) -
  A cryptocurrency wallet browser extension.
- [Node.js](https://nodejs.org/en/) version >= 16.
- [pnpm](https://pnpm.io/) version >= 7.

```bash
pnpm install // install dependencies
pnpm build  // build the package
pnpm demo // run demo
```

the demo will be running on http://localhost:5173/.

## Usage

Directly import in your project, and it will automatically inject the iframe with id `meteor-iframe`.

```typescript
import "@meteor-web3/meteor-iframe";
```

To communicate with the kernel in iframe, you can use the Communicator.

```typescript
import { Communicator } from "@meteor-web3/communicator";

const communicator = new Communicator({
  source: window,
  target: iframeWindow,
  runningEnv: "Client",
  // (required) only external-wallet is supported for now, so you need to handle the ethereumRequest method yourself.
  methodHandler: async (args) => {
    console.log("Client received method call:", args);
    if (args.method === "ethereumRequest") {
      const res = await window.ethereum.request(args.params);
      console.log("Client responded to ethereumRequest:", res);
      return res;
    }
  }
});
```
