Skip to content

Commit

Permalink
chore(web): update sources to better log when connected/disconnected
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Dec 19, 2024
1 parent b31f466 commit 5decba1
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions apps/web/src/stores/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ export const useSources = defineStore('sources', () => {
status.value = event.data
})
source.value.on('connected', (event) =>
console.info('Connected to Twitch Chat at: ', event.timestamp)
console.info('Connected to', event.source, 'channel', event.channel, 'at', event.timestamp)
)
source.value.on('disconnected', (event) =>
console.info('Disconnected from Twitch chat at: ', event.timestamp, ' ', event?.data)
console.info(
'Disconnected from',
event.source,
'channel',
event.channel,
'at',
event.timestamp
)
)
source.value.on('message', async (event) => {
// Check if message is a command and perform command if proper permission to do so
Expand Down Expand Up @@ -96,20 +103,12 @@ export const useSources = defineStore('sources', () => {
source.value.on('error', (event) => {
console.error('Clip source error: ', event.data)
})
try {
await source.value.connect(ctx)
console.info('Connect to Twitch chat of channel: ', ctx().username)
} catch (e) {
console.error('Failed to connect to Twitch chat: ', e)
}

await source.value.connect(ctx)
}

async function disconnect(): Promise<void> {
try {
await source.value?.disconnect()
} catch (e) {
console.error('Failed to disconnect from ', source.value?.name, ': ', e)
}
await source.value?.disconnect()
}

return { logo, status, connect, disconnect }
Expand Down

0 comments on commit 5decba1

Please sign in to comment.