Guest User

Untitled

a guest
May 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import Echo from 'laravel-echo'
  2.  
  3. window.Pusher = require('pusher-js');
  4.  
  5. window.Echo = new Echo({
  6. broadcaster: 'pusher',
  7. key: '....',
  8. });
  9.  
  10. window.Echo.channel('chat-room')
  11. .listen('.app.Events.ChatMessageWasReceived.php', (e)=>{
  12. console.log(e);
  13. });
  14.  
  15. class ChatMessageWasReceived implements ShouldBroadcast
  16. {
  17. use Dispatchable, InteractsWithSockets, SerializesModels;
  18.  
  19. public $chatMessage;
  20. public $user;
  21.  
  22. /**
  23. * Create a new event instance.
  24. *
  25. * @param $user
  26. * @param $chatMessage
  27. */
  28. public function __construct($chatMessage, $user)
  29. {
  30. $this->user = $user;
  31. $this->chatMessage = $chatMessage;
  32. }
  33.  
  34. /**
  35. * Get the channels the event should broadcast on.
  36. *
  37. * @return IlluminateBroadcastingChannel|array
  38. */
  39. public function broadcastOn()
  40. {
  41. return new PrivateChannel('chat-room');
  42. }
  43. }
Add Comment
Please, Sign In to add comment