adrema/resources/js/lib/echo.js

36 lines
1023 B
JavaScript
Raw Normal View History

2023-07-25 17:23:48 +02:00
import Pusher from 'pusher-js';
import Echo from 'laravel-echo';
2023-10-16 15:41:37 +02:00
import {useToast} from 'vue-toastification';
const toast = useToast();
2023-07-25 17:23:48 +02:00
window.Pusher = Pusher;
2023-10-16 15:41:37 +02:00
2024-06-28 12:10:18 +02:00
console.log();
2023-10-16 15:41:37 +02:00
function handleJobEvent(event, type = 'success') {
if (event.message) {
toast[type](event.message);
}
}
var echo = new Echo({
2023-07-25 17:23:48 +02:00
broadcaster: 'pusher',
key: 'adremakey',
wsHost: window.location.hostname,
2024-06-28 12:10:18 +02:00
wsPort: import.meta.env.MODE === 'development' ? 6001 : 80,
wssPort: import.meta.env.MODE === 'development' ? 6001 : 443,
2023-07-25 17:23:48 +02:00
forceTLS: false,
disableStats: true,
cluster: 'adrema',
enabledTransports: ['ws', 'wss'],
});
2023-10-16 15:41:37 +02:00
echo.channel('jobs')
.listen('\\App\\Lib\\Events\\JobStarted', (e) => handleJobEvent(e, 'success'))
.listen('\\App\\Lib\\Events\\JobFinished', (e) => handleJobEvent(e, 'success'))
2023-12-30 22:39:26 +01:00
.listen('\\App\\Lib\\Events\\JobFailed', (e) => handleJobEvent(e, 'error'))
2023-12-30 19:28:25 +01:00
.listen('\\App\\Lib\\Events\\Succeeded', (e) => handleJobEvent(e, 'success'));
2023-10-16 15:41:37 +02:00
export default echo;