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
| Environment | How | Page |
|---|---|---|
| Vite, React, Svelte or another bundler | npm install iosignal, then import IO from 'iosignal/browser/esm/io.js' | Browser modules |
| HTML and a CDN | A <script> with the ESM or IIFE build of iosignal@9 | HTML 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 aws://server may be blocked by the browser. For local development, use ahttp://localhostpage withws://localhost:7777. Connections- Component lifecycle: call
io.destroy()when a component goes away. When components share one instance, register withlink()and release one component's handlers withunlinkAll(component). JS subscriptions and lifecycle - When to subscribe: register fixed tags with
listen()before connecting; subscribe to tags that change at run time withsubscribe()in areadyhandler.readyarrives 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 build | Pages and examples |
|---|---|
| A chat | React, Svelte and Vanilla chat examples |
| Video calls (WebRTC signaling) | WebRTC example, lab.iosignal.net/webrtc |
| A screen that finds and controls devices | The discovery and control rules in Build a device (app.iosignal.net compatible), remocon.kr |
| Real-time game or quiz screens | Get started with games |
| Looking up methods and events | Client 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
- The page does not open or a module is not found: install and run diagnosis
readynever arrives: connection diagnosis- Messages do not show or arrive twice: delivery diagnosis, duplicate reactions