0.2.1 • Published 1 year ago

hypercast v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

hypercast

Client looks like this.

// client.ts
import { Operator, Hypercast } from 'hypercast/client'

enum MessageType {
  Hello = 'hello',
  Goodbye = 'goodbye',
}

type Messages =
  | {
      type: MessageType.Hello
      name: string
    }
  | {
      type: MessageType.Goodbye
      name: string
    }

const operator = new Operator()
const { topic } = await operator.createTopic()
const hypercast = new Hypercast(topic)

hypercast.on('message', (event) => {
  switch (event.data.type) {
    case MessageType.Hello:
      console.log(`Hello ${event.data.name}`)
    case MessageType.GoodBye:
      console.log(`Hello ${event.data.name}`)
    default:
      console.log(`Unknown message type`)
  }
})

await hypercast.connect()

Then, to send a message:

const ack = hypercast.send({
  type: MessageType.Hello,
  name: 'Cloudflare',
})

// optional
await ack

Self Hosting a Hypercast Instance

Server looks like this, plus a little Wrangler config for the Durable Object.

// worker.ts
import { Operator } from 'hypercast/server'
export { Hypercast } from 'hypercast/server'
export default new Operator('/hypercast') // pathname, if any

And when creating your client, you need to pass in your URL:

const hypercast = new Hypercast(topic, 'https://esb.lol/hypercast')

Or:

const operator = new Operator('https://esb.lol/hypercast')

That's the whole thing.

0.1.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.0.6

1 year ago

0.0.1

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.0

1 year ago