WEBVTT

1
00:00.760 --> 00:02.040
Hi everyone!

2
00:02.040 --> 00:11.960
In this video we will explore the one more powerful API of the socket.io will be the broadcasting.

3
00:12.800 --> 00:16.920
Well, what exactly about broadcasting?

4
00:18.680 --> 00:25.280
Well, we have a two different types of same message with the broadcasting.

5
00:26.440 --> 00:32.640
The first will be send message to all clients okay.

6
00:32.920 --> 00:37.600
And the second one will be send a message to all clients.

7
00:37.600 --> 00:43.480
But except myself, what do I mean by now?

8
00:44.000 --> 00:52.640
In order to send a message into all the client, we will use the IO over here.

9
00:53.080 --> 00:53.560
Okay.

10
00:54.640 --> 00:58.880
What exactly about IO the socket IO library?

11
00:58.920 --> 01:02.380
It will manage all client inside the "io" object.

12
01:02.420 --> 01:12.060
Okay, so for that reason, in order to send the message for all client, we will use the "io".

13
01:14.380 --> 01:16.380
But how about the second one?

14
01:16.780 --> 01:20.220
We will send message to all client except myself.

15
01:21.060 --> 01:25.220
Well, for example, I am a client one.

16
01:25.820 --> 01:35.260
I want to send a message into the server and at the same time we have a multiple connection.

17
01:40.300 --> 01:40.980
Right here.

18
01:45.420 --> 01:46.700
When I send a message.

19
01:49.020 --> 01:54.900
I want the server here will be sent back to all client.

20
01:55.500 --> 01:58.620
But accept me, okay?

21
01:59.020 --> 02:00.800
It will accept me because

22
02:00.840 --> 02:02.600
I send a message, right?

23
02:03.040 --> 02:03.400
So what?

24
02:03.760 --> 02:05.240
I want to accept myself.

25
02:06.040 --> 02:11.200
So in order to do that, let me show you one more use case.

26
02:11.400 --> 02:20.200
For example, in lecture, when a new user connecting to the client, I want to send a message for other

27
02:20.200 --> 02:26.320
the client will be the new user had join into the chat application.

28
02:26.360 --> 02:29.040
Okay, I want to send a simple message like that.

29
02:29.920 --> 02:40.960
Well, in order to do that right now, inside the connection okay, I will send the socket.

30
02:41.200 --> 02:41.480
Okay.

31
02:41.520 --> 02:42.040
In order emit.

32
02:45.040 --> 02:48.640
Send message for all clients

33
02:50.000 --> 02:52.000
Except myself.

34
02:53.040 --> 02:56.000
In order to do that, we will use the socket okay.

35
02:56.840 --> 03:00.240
And we have a broadcast.

36
03:00.720 --> 03:03.950
And right here we can emit event as normal.

37
03:04.750 --> 03:05.350
Okay.

38
03:06.990 --> 03:09.070
For example right here will be new user.

39
03:12.950 --> 03:19.150
And right here I will use a new user has been joined.

40
03:20.590 --> 03:22.470
To the application.

41
03:23.510 --> 03:29.390
Okay I will send a message like that inside the script over here.

42
03:29.830 --> 03:31.630
We will listening on that.

43
03:40.150 --> 03:40.710
Okay.

44
03:41.470 --> 03:49.430
And in this case I will create a p element and I will append that also let me copy.

45
03:50.150 --> 03:54.950
Right here p element create and text content.

46
03:58.270 --> 04:01.370
In here I will use the.

47
04:04.050 --> 04:08.410
message directly, because this is just a string

48
04:08.450 --> 04:12.090
Okay, so for that reason, the message right here will be also the string.

49
04:12.890 --> 04:18.250
And let me show you like I will refresh.

50
04:18.290 --> 04:22.810
Now we don't see anything in the client right now I will connect.

51
04:24.210 --> 04:25.690
We will not see anything.

52
04:25.690 --> 04:33.770
But if I go back to the first client, you can see it will console.log a new user has been joined into

53
04:33.810 --> 04:35.010
this application.

54
04:35.050 --> 04:35.970
Very very cool.

55
04:35.970 --> 04:36.370
Right?

56
04:37.010 --> 04:39.250
Let me create another client.

57
04:40.730 --> 04:43.370
This client will not have anything.

58
04:43.370 --> 04:49.090
But right here you can see it has a console log, right.

59
04:50.170 --> 04:53.210
It has some text okay.

60
04:53.210 --> 04:55.650
That's about the broadcasting event.

61
04:56.770 --> 05:02.210
So I hope you understand this video and I will see you in the next one.