JOIN MY SPONSORS

Reconnecting

To reconnect, just call .open() on the channel. All listeners, options, and keys remain intact.

reconnect.js
import { connect } from 'itty-sockets'

const channel = connect('my-channel', { announce: true })
  .on('message', console.log)

// reconnect every second if disconnected
setInterval(channel.open, 1000)
Note: There's no penalty for calling .open() multiple times, or on a connection that is already open.

Next: TypeScripttype your listeners, sends, and connections.