Skip to main content

Get started in the browser

Connect web apps (plain JavaScript, React, Svelte and others) to an IOSignal server to build chats, device control screens, video-call signaling and game screens. If you are new, read core concepts in five minutes first; tags, delivery types and the home channel are the same in every environment.

1. Install​

EnvironmentHowPage
Vite, React, Svelte or another bundlernpm install iosignal, then import IO from 'iosignal/browser/esm/io.js'Browser modules
HTML and a CDNA <script> with the ESM or IIFE build of iosignal@9HTML and CDN

2. First connection​

This single HTML file connects to the public server. Open it in two tabs and run io.signal('room#chat', 'hi') in one tab's console.

<script type="module">
import IO from 'https://cdn.jsdelivr.net/npm/iosignal@9/dist/browser/esm/io.js';

const io = new IO('wss://io.iosignal.net/ws');
window.io = io;
io.listen('room#chat', (tag, message) => console.log(tag, message));
io.on('ready', () => console.log('CID:', io.cid));
</script>

3. What differs in the browser​

  • Import path: browsers use import IO from 'iosignal/browser/esm/io.js' (a default export). import { IO } from 'iosignal' is the Node.js entry point; keep it out of browser bundles.
  • wss:// on HTTPS pages: a page served over HTTPS that connects to a ws:// server may be blocked by the browser. For local development, use a http://localhost page with ws://localhost:7777. Connections
  • Component lifecycle: call io.destroy() when a component goes away. When components share one instance, register with link() and release one component's handlers with unlinkAll(component). JS subscriptions and lifecycle
  • When to subscribe: register fixed tags with listen() before connecting; subscribe to tags that change at run time with subscribe() in a ready handler. ready arrives again after a reconnection.
  • Home channel scope: a browser's home channel is set by its public IP too. It can find devices on the same router with #search, but this is not a security boundary. Home channel

4. Build guides​

What you want to buildPages and examples
A chatReact, Svelte and Vanilla chat examples
Video calls (WebRTC signaling)WebRTC example, lab.iosignal.net/webrtc
A screen that finds and controls devicesThe discovery and control rules in Build a device (app.iosignal.net compatible), remocon.kr
Real-time game or quiz screensGet started with games
Looking up methods and eventsClient API

5. Examples​

  • iosignal-examples: React, Svelte, Vanilla and CDN chats, a channel-negotiation chat, WebRTC, Host Quiz
  • Web lab: connect to a server, send and subscribe to any tag and watch the log.

6. When you are stuck​