Browse Source

Important! event should be implements ShouldBroadcast

pull/1/head
Nafies Luthfi 5 years ago
parent
commit
df9e5fab1a
  1. 3
      app/Events/LongRunJobDone.php
  2. 5
      app/Jobs/LongRunJob.php
  3. 25430
      public/js/app.js
  4. 8
      public/js/app.js.LICENSE.txt
  5. 8
      resources/js/bootstrap.js
  6. 7
      resources/views/welcome.blade.php

3
app/Events/LongRunJobDone.php

@ -4,10 +4,11 @@ namespace App\Events;
use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class LongRunJobDone
class LongRunJobDone implements ShouldBroadcast
{ {
public $message; public $message;

5
app/Jobs/LongRunJob.php

@ -20,8 +20,9 @@ class LongRunJob implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
sleep(3);
$seconds = 5;
sleep($seconds);
event(new LongRunJobDone('Long run job done.'));
event(new LongRunJobDone('Long run job done after '.$seconds.' seconds.'));
} }
} }

25430
public/js/app.js
File diff suppressed because it is too large
View File

8
public/js/app.js.LICENSE.txt

@ -1,3 +1,11 @@
/*!
* Pusher JavaScript Library v6.0.3
* https://pusher.com/
*
* Copyright 2020, Pusher
* Released under the MIT licence.
*/
/** /**
* @license * @license
* Lodash <https://lodash.com/> * Lodash <https://lodash.com/>

8
resources/js/bootstrap.js

@ -30,7 +30,7 @@ window.Echo = new Echo({
disableStats: false disableStats: false
}); });
Pusher.log = function(message)
{
window.console.log(message)
}
// Pusher.log = function(message)
// {
// window.console.log(message)
// }

7
resources/views/welcome.blade.php

@ -103,7 +103,12 @@
<script> <script>
Echo.channel('queue-notifier') Echo.channel('queue-notifier')
.listen('.App\\Events\\LongRunJobDone', (e) => { .listen('.App\\Events\\LongRunJobDone', (e) => {
console.log(e);
noty({
type: 'success',
layout: 'bottomRight',
text: e.message,
timeout: 5000
});
}); });
</script> </script>
@if (Session::has('flash_notification.message')) @if (Session::has('flash_notification.message'))

Loading…
Cancel
Save