Bitskiff

No build step

On this page

Run the host or client SDK in a browser with no build step. An import map tells the browser where @bitskiff/host and @bitskiff/client are, so the import line is the same one a bundled app writes. This is the whole page:

HTML
<script type="importmap">
{
  "imports": {
    "@bitskiff/host": "https://docs.dev.bitskiff.com/sdk/host@0.3.0.js",
    "@bitskiff/host/unattended": "https://docs.dev.bitskiff.com/sdk/host@0.3.0/unattended.js",
    "@bitskiff/client": "https://docs.dev.bitskiff.com/sdk/client@0.3.0.js"
  },
  "integrity": {
    "https://docs.dev.bitskiff.com/sdk/host@0.3.0.js": "sha384-t4tevb6IaP3UssGRlkmHoQscYfON1BN2JyGY3zsoEGm3KmG2W3Mbe4icXcXQ7uGA",
    "https://docs.dev.bitskiff.com/sdk/host@0.3.0/unattended.js": "sha384-HEFX6nOFsYHXKEmBFo28v1a6kREAcKdfOPX7MKE8G8QAgiSpx2DfQy4VYs0KBgjA",
    "https://docs.dev.bitskiff.com/sdk/client@0.3.0.js": "sha384-d2cF/4NoPsVP5hrsmWr6yvH7578xCVoloemqaTxgXX6L5wd03MbZo1jrX1G0MJLa"
  }
}
</script>

<script type="module">
  import { BitskiffHost, qrSvg } from '@bitskiff/host';

  const host = new BitskiffHost({ key: 'bsk_pk_...' });
  host.channel('press').on('message', (m) => console.log(m.client.id, m.data));   // declare and listen

  const session = await host.open();                     // open last: it seals the channels
  document.body.innerHTML = qrSvg(session.joinCode.url);
</script>

Module URLs

Copy the URL and the hash from the docs site of the environment you are shipping against. Each module is built for one environment and talks only to that one. There is no endpoint option to point it somewhere else.

The URLs above are this site's own. They were built for dev and talk to https://api.dev.bitskiff.com. Each module carries its own package's version: the client module's is the client package's, not the host's.

Two URLs serve each build:

  • The exact version, https://docs.dev.bitskiff.com/sdk/host@0.3.0.js. It is never republished, so the code you tested is the code your page loads. Each URL in the map above is the exact version.
  • The line, the same name with the patch number dropped. It is a one-line module that re-exports the newest release on that line, so it moves under you when that line releases again. The exact version it re-exports is still never republished.

The dev build is served at https://docs.dev.bitskiff.com/sdk/host@dev.js, and the other two files under the same names with @dev in place of the version: host@dev/unattended.js and client@dev.js, which a client page wants. None has a hash to pin. They change with every dev roll, so they are for trying a change, never for a live app.

The line is the minor below 1.0 and the major from 1.0 on, because that is the axis a breaking change crosses. Nothing wider than a line is served.

The modules

Three modules are served, @bitskiff/host, @bitskiff/host/unattended and @bitskiff/client, and all three are in the map above. The second is the openForever loop an unattended host runs, a few kilobytes that take the host you already made as an argument: see Unattended hosts. The third is the client SDK: a client page carries the same map and imports BitskiffClient from @bitskiff/client, with no build step either. See Client pages.

Version and integrity

  • Ship the exact-version URL. Keep the line URL for a scratch page. A page you ship pins the version it was tested against.
  • Keep the integrity entry in the import map. The browser refuses to run a module whose hash does not match, which is what makes it safe to load code from another origin on a page that holds your key. A bare import from a URL has nowhere to put an integrity attribute, so the map is where the hash goes. The line URL has no hash to pin, and the module it re-exports is fetched as a dependency that no integrity entry covers. That is the other reason a shipped page names the exact version.

Next steps