OverviewFilesCommitsIssuesDocsReleasesPeers

holepunchto-deps / @holepunchto / keet-media / worker / index.js

30 lines · javascript ref:
import worker from 'cross-worker'
import uncaughts from 'uncaughts'

import HRPC from '../shared/spec/hrpc'

import * as media from './media'

const log = (...args) => console.log('[keet-media]', ...args)

log('Worker started 🚀')

const stream = worker.stream()

stream.on('end', () => stream.end())
stream.on('error', (err) => console.error(err))
stream.on('close', () => Bare.exit(0))

const rpc = new HRPC(stream)

rpc.onCreateChatImagePreview(media.createChatImagePreview)
rpc.onCreateChatVideoPreview(media.createChatVideoPreview)
rpc.onCreateChatLinkPreview(media.createChatLinkPreview)
rpc.onCreateProfileAvatar(media.createProfileAvatar)
rpc.onCreateRoomAvatar(media.createRoomAvatar)
rpc.onDecodeImage(media.decodeImage)

uncaughts.on((err) => {
  log('Uncaught error:', err)
})