slidev-addon-inalia
Version:
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href]
50 lines (45 loc) • 1.7 kB
text/typescript
import { defineAppSetup } from '@slidev/types'
import Echo from 'laravel-echo'
import { ofetch } from 'ofetch'
import Pusher from 'pusher-js'
import { fetchTalk } from '../utils/api'
export default defineAppSetup(async ({ app }) => {
if (!import.meta.env.VITE_REVERB_APP_KEY) {
console.warn('Inalia is running in static mode. Set up environment variables to enable real-time features.')
return
}
window.Pusher = Pusher
window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY ?? '9b9ehgq0ba2hjomeiuyu',
wsHost: import.meta.env.VITE_REVERB_HOST ?? 'ws.inalia.app',
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
authorizer: (channel: { name: string }) => {
return {
authorize: (socketId: string, callback: (success: boolean, data: any) => void) => {
ofetch(`${import.meta.env.VITE_INALIA_ENDPOINT ?? 'https://inalia.app'}/api/broadcasting/auth`, {
method: 'POST',
body: {
socket_id: socketId,
channel_name: channel.name,
},
headers: {
Accept: 'application/json',
Authorization: `Bearer ${import.meta.env.VITE_INALIA_API_KEY}`,
},
onResponse: ({ response }) => {
callback(false, response._data)
},
onRequestError: ({ error }) => {
callback(true, error)
},
})
},
}
},
})
app.provide('talk', await fetchTalk())
})