WEBVTT

1
00:00.720 --> 00:02.320
Hi everyone.

2
00:02.680 --> 00:06.360
Let's continue with the WebSocket.

3
00:07.640 --> 00:16.320
And in this video let's discuss more about the send and receive the data.

4
00:17.920 --> 00:24.920
Well right here you can see in order to send an event we will use the emit right.

5
00:25.880 --> 00:31.520
For example in this case we will create a new emit will be update.

6
00:32.120 --> 00:32.640
Okay.

7
00:33.200 --> 00:39.760
And you can see right here this is the argument.

8
00:40.200 --> 00:45.440
It means we can put every data if you want.

9
00:45.600 --> 00:45.920
Okay.

10
00:45.960 --> 00:54.520
For example like item one, item two, item three okay something like that.

11
00:55.240 --> 00:58.680
You can put many argument as you can.

12
00:59.800 --> 01:11.700
But right now let's keep the first argument will be the event name in your head, and the rest of that

13
01:11.740 --> 01:16.700
will be the data right here inside the script.

14
01:16.740 --> 01:18.100
Let me show you.

15
01:20.060 --> 01:22.940
I will listen on the update.

16
01:24.540 --> 01:25.060
Right.

17
01:26.660 --> 01:29.860
And in here we will get the callback.

18
01:30.980 --> 01:31.540
Okay.

19
01:32.220 --> 01:36.740
And inside the callback we will got item one, item two, item three.

20
01:38.060 --> 01:39.780
And right here I will console.log.

21
01:43.020 --> 01:44.300
Inside here

22
01:48.260 --> 01:48.820
Okay.

23
01:49.660 --> 02:01.340
Now we will send and receive that in the parameter of this callback function over here.

24
02:06.580 --> 02:09.700
Now you can see I will console.log.

25
02:09.700 --> 02:12.870
That, it very very cool, right.

26
02:17.550 --> 02:18.550
Remember that

27
02:18.750 --> 02:24.190
But with me, I prefer wrap.

28
02:24.470 --> 02:27.510
All of that inside the object.

29
02:27.790 --> 02:28.350
Okay.

30
02:28.750 --> 02:32.950
I prefer using this case for example like product one.

31
02:35.430 --> 02:35.830
Two

32
02:38.790 --> 02:39.590
Here will be.

33
02:44.590 --> 02:51.030
okay, I want to wrap it inside a single object and send that.

34
02:51.790 --> 02:54.870
Okay, let me remove this thing.

35
02:55.790 --> 02:59.030
And inside here we will got the message.

36
02:59.030 --> 03:01.070
Right inside the message.

37
03:01.070 --> 03:02.230
Right here we can.

38
03:03.150 --> 03:03.990
Let me console.log.

39
03:04.990 --> 03:06.230
What is inside the message?

40
03:08.670 --> 03:16.870
Now you can see it already got the object, we don't need to stringify, right?

41
03:19.970 --> 03:20.370
Hmm.

42
03:21.930 --> 03:23.010
Let's continue.

43
03:28.530 --> 03:29.130
Okay.

44
03:36.370 --> 03:40.490
You can destructuring over here.

45
03:42.410 --> 03:43.330
Very easy.

46
03:52.970 --> 03:53.490
Okay.

47
03:56.370 --> 04:00.370
And this will be enough.

48
04:08.810 --> 04:11.530
You can do some logic over here.

49
04:12.170 --> 04:18.290
And one more thing is the acknowledgement.

50
04:19.370 --> 04:20.290
Let me show you.

51
04:20.330 --> 04:21.290
What does it mean?

52
04:21.850 --> 04:24.460
In the last argument, I can pass the?

53
04:24.500 --> 04:24.980
The

54
04:25.460 --> 04:26.300
The callback

55
04:27.300 --> 04:27.740
Okay.

56
04:27.780 --> 04:32.340
For example, I will pass the callback with this message over here.

57
04:33.340 --> 04:35.420
Right here I will call log message.

58
04:36.900 --> 04:44.540
It means in the second parameter, we can retrieve the callback right inside the callback.

59
04:44.540 --> 04:47.420
here we can call for example like

60
04:47.980 --> 04:48.460
Hello.

61
04:50.620 --> 04:51.140
Okay.

62
04:51.620 --> 04:53.180
We will call the callback.

63
04:54.500 --> 04:56.700
And this will trigger this thing

64
04:56.700 --> 05:01.380
And it will console log on the server.

65
05:01.940 --> 05:02.860
Let me show you.

66
05:03.380 --> 05:05.340
I will refresh right here.

67
05:05.340 --> 05:11.140
It will console log inside the server because on the client we already called callback.

68
05:12.220 --> 05:19.020
Well in the in the real world application maybe you can write logic for example, like something like

69
05:19.020 --> 05:19.460
that.

70
05:19.620 --> 05:23.220
Will call the callback to trigger something in the server.

71
05:23.500 --> 05:23.980
Right.

72
05:24.740 --> 05:27.500
So that's for the video.

73
05:27.740 --> 05:29.140
It very easy right.

74
05:30.260 --> 05:31.340
I will see you in the next.