Event Broadcasting Flashcards

1
Q

What are the current broadcasting drivers supported by Laravel?

A

Pusher, Redis and a log driver

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the log driver?

A

The log driver is for local development and debugging.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Additionally what other driver is available to disable broadcasting?

A

The “null” driver.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Before being able to broadcast any events what service provider needs to be registered in config/app.php file?

A

BroadcastServiceProvider

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the name of the token required by Laravel Echo for auth?

A

CSRF Token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

By default where does Laravel Echo look for the Laravel.csrfToken javascript object?

A

resources/views/layouts/app.blade.php

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

At the start of a project what command will generate the app.blade.php file?

A

make:auth Artisan command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If you are not using the default layout where would you define the meta tag for CRSF token?

A

In your applications head HTML element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If your using Pusher to broadcast events what is the prerequisite package required?

A

pusher/pusher-php-server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where would you config your Pusher credentials?

A

In the config/broadcasting.php configuration file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the additional options provided in the config/broadcastsing.php file?

A

cluster and encrypted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When using Pusher and Laravel Echo where you specify Pusher as your desired broadcaster within resources/assets/js/ ?

A

bootstrap.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When you are using Redis as broadcaster what composer command would you use to fetch the required library?

A

composer require predis/predis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In order for Redis to work what does it need to be paired with?

A

A WebSocket server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

By default where would you include the Socket.IO Javascript client library?

A

In your applications head HTML element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the name of currently maintained Socket.IO server GitHub repository?

A

tlaverdure/laravel-echo-server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Before broadcasting events what will you need to configure and run, helping the response time of your application?

A

Queue Listener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the two basic types of channels events can be broadcast over?

A

public and private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the difference between public and private channels?

A

In order for a user to subscribe to a private channel a user must be authenticated and authorized to listen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

In order for to broadcast an event what interface is required?

A

ShouldBroadcast:

class ShippingStatusUpdated implements ShouldBroadcast

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of the broadcastOn() method?

A

This method is responsible for returning the channels that the event should broadcast on.

22
Q

Where would we define our channel authorization rules?

A

routes/channels.php

23
Q

What are the two arguments accepted by the channel method?

A

the name of the channel and a callback which returns true or false indicating whether the user is authorized to listen on the channel.

24
Q

What do all the authorization callbacks on the channel method receive as the first method?

A

The currently authenticated user

25
Q

What is the second argument for the authorization callbacks on the channel method?

A

wildcard parameters

26
Q

By default, what is included when an event that has been broadcast?

A

public properties

27
Q

Channels within the broadcastOn() method should be instances of?

A

Channel, PrivateChannel or PresenceChannel

28
Q

Aside of the PrivateChannel what other channel is considered private?

A

PresenceChannel

29
Q

What is the purpose of the broadcastAs() method?

A

You may customize the broadcast name by defining a broadcastAs method on the event:

public function broadcastAs()
{
return ‘server.created’;
}

30
Q

What is the purpose of the broadcastWith() method?

A

This method should return the array of data that you wish to broadcast as the event payload:

public function broadcastWith()
{
return [‘id’ => $this->user->id];
}

31
Q

What is the purpose of the broadcastQueue propertie?

A

You may customize the queue used by the broadcaster by defining a broadcastQueue property on your event class. This property should specify the name of the queue you wish to use when broadcasting:

public $broadcastQueue = ‘your-queue-name’;

32
Q

What is the purpose of the Broadcast::routes method?

A

In the BroadcastServiceProvider included with your Laravel application, you will see a call to the Broadcast::routes method. This method will register the /broadcasting/auth route to handle authorization requests

33
Q

Where will the Broadcast::routes automatically place its routes?

A

web middleware group

34
Q

What would you pass to to customize the assigned attributes on the Broadcast::routes method?

A

You may pass an array of route attributes to the method if you would like to customize the assigned attributes:

Broadcast::routes($attributes);

35
Q

What method is used to register channel authorization callbacks within routes/channels.php?

A

Broadcast::channel

36
Q

Like HTTP routes, channel routes may also take advantage of what types of binding?

A

implicit and explicit route model binding

For example, instead of receiving the string or numeric order ID, you may request an actual Order model instance:

use App\Order;

Broadcast::channel(‘order.{order}’, function ($user, Order $order) {
return $user->id === $order->user_id;
});

37
Q

When building an application that utilizes event broadcasting what may you substitute with the event function?

A

broadcast function

broadcast(new ShippingStatusUpdated($update));

instead of

event(new ShippingStatusUpdated($update));

38
Q

What is the purpose of the toOthers() method?

A

The toOthers method allows you to exclude the current user from the broadcast’s recipients:

broadcast(new ShippingStatusUpdated($update))->toOthers();

39
Q

What is the purpose of the leave() method?

A

To leave a channel, you may call the leave method on your Echo instance:

Echo.leave(‘orders’);

40
Q

What is the purpose of the listen() method?

A

The listen method listens for a specified event:

Echo.channel(‘orders’)
.listen(‘OrderShipped’, (e) => {
console.log(e.order.name);
});

41
Q

Laravel Echo will automatically assume the events are located in which namespace?

A

App\Events

42
Q

To configure the route namespace when you instantiate Echo what would you pass as an configuration option?

A

namespace:

window.Echo = new Echo({
broadcaster: ‘pusher’,
key: ‘your-pusher-key’,
namespace: ‘App.Other.Namespace’
});

43
Q

What is the alternative then passing a namespace configuration option when you instantiate Echo?

A

Alternatively, you may prefix event classes with a . when subscribing to them using Echo. This will allow you to always specify the fully-qualified class name:

Echo.channel('orders')
    .listen('.Namespace.Event.Class', (e) => {
        //
    });
44
Q

What is the purpose of Presence Channels?

A

Presence channels build on the security of private channels while exposing the additional feature of awareness of who is subscribed to the channel.

45
Q

If a user is not authorized to join a presence channel what must be returned from the callback?

A

false or null

46
Q

What are the presence channel Echo methods available?

A

join, here, joining, leaving and listen

47
Q

What is the purpose of the Echo here() method?

A

The here callback will be executed immediately once the channel is joined successfully, and will receive an array containing the user information for all of the other users currently subscribed to the channel.

48
Q

What is the purpose of the Echo joining() method?

A

The joining method will be executed when a new user joins a channel.

49
Q

What is the purpose of the Echo leaving() method?

A

The leaving method will be executed when a user leaves the channel.

50
Q

What is the purpose of the Echo whisper() method?

A

Sometimes you may wish to broadcast an event to other connected clients without hitting your Laravel application at all. This can be particularly useful for things like “typing” notifications, where you want to alert users of your application that another user is typing a message on a given screen. To broadcast client events, you may use Echo’s whisper method:

Echo.channel(‘chat’)
.whisper(‘typing’, {
name: this.user.name
});

51
Q

What is the purpose of the Echo listenForWhisper() method?

A

To listen for client events, you may use the listenForWhisper method:

Echo.channel(‘chat’)
.listenForWhisper(‘typing’, (e) => {
console.log(e.name);
});