Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
e3ffff5
Update article.md
astropsy999 May 24, 2022
ceb3946
Update article.md
astropsy999 May 24, 2022
f6aafd1
Update article.md
astropsy999 May 25, 2022
0f3f2a9
Update article.md
astropsy999 May 25, 2022
ba4c2b9
Update article.md
astropsy999 May 25, 2022
9a855d9
Update article.md
astropsy999 May 26, 2022
ca0b538
Update article.md
astropsy999 May 26, 2022
52e5ab9
Update article.md
astropsy999 May 26, 2022
7d621a6
Update article.md
astropsy999 May 26, 2022
b310810
Update index.html
astropsy999 May 26, 2022
46d37a3
Update article.md
astropsy999 Jun 4, 2022
d5d59f6
Update article.md
astropsy999 Jun 4, 2022
3fe04de
Update article.md
astropsy999 Jun 5, 2022
d161dd1
Update index.html
astropsy999 Jun 5, 2022
52bf3af
Update article.md
astropsy999 Jun 5, 2022
8f3e3fe
Update article.md
astropsy999 Jun 6, 2022
ac9996b
Update article.md
astropsy999 Jun 6, 2022
3bd140e
Update article.md
astropsy999 Jun 7, 2022
18a38a3
Update iframe.html
astropsy999 Jun 7, 2022
75d1f7c
Update index.html
astropsy999 Jun 7, 2022
d9660ab
Update iframe.html
astropsy999 Jun 7, 2022
fb08989
Update facebook.html
astropsy999 Jun 7, 2022
0ef68a9
Update index.html
astropsy999 Jun 7, 2022
6e53413
Update facebook.html
astropsy999 Jun 7, 2022
c80ed0f
Update index.html
astropsy999 Jun 7, 2022
469e2d3
Update article.md
astropsy999 Jun 8, 2022
f84fa7d
Merge branch 'master' into master
astropsy999 Jun 8, 2022
d4c6a64
Update article.md
astropsy999 Jun 8, 2022
935199a
Update article.md
astropsy999 Jun 9, 2022
5f35c46
Update article.md
astropsy999 Jun 10, 2022
999ab9d
Update task.md
astropsy999 Jun 12, 2022
fafe785
Update task.md
astropsy999 Jun 12, 2022
76007bc
Update index.html
astropsy999 Jun 12, 2022
84362d4
Update index.html
astropsy999 Jun 12, 2022
22fdad6
Update index.html
astropsy999 Jun 12, 2022
d051d1e
Update index.html
astropsy999 Jun 12, 2022
f0f4d93
Update index.html
astropsy999 Jun 12, 2022
58e0228
Update index.html
astropsy999 Jun 12, 2022
d3cdbac
Update index.html
astropsy999 Jun 12, 2022
410a0e1
Update index.html
astropsy999 Jun 12, 2022
18f9da2
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
a6806c0
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
82cd9d5
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
6b1b439
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
64ccba1
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
e2a2219
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
ab9ef8d
Update 3-frames-and-windows/06-clickjacking/article.md
astropsy999 Jul 3, 2022
af25da9
Update 3-frames-and-windows/06-clickjacking/clickjacking-visible.view…
astropsy999 Jul 3, 2022
3a10141
Update 3-frames-and-windows/06-clickjacking/clickjacking-visible.view…
astropsy999 Jul 3, 2022
08ed6b1
Update 3-frames-and-windows/06-clickjacking/clickjacking.view/index.html
astropsy999 Jul 3, 2022
74de077
Apply suggestions from code review
dolgachio Jul 12, 2022
494b88d
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 21, 2022
f3db6f5
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 21, 2022
afeb15b
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 21, 2022
10e610c
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 21, 2022
5d29d2d
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 21, 2022
118c6cf
Update 7-animation/2-css-animations/article.md
astropsy999 Jul 21, 2022
c0b84c4
Update 7-animation/2-css-animations/article.md
astropsy999 Jul 21, 2022
ab8be27
Update 7-animation/2-css-animations/article.md
astropsy999 Jul 21, 2022
5ae6e12
Update 7-animation/2-css-animations/article.md
astropsy999 Jul 21, 2022
d2973b3
Update 7-animation/2-css-animations/article.md
astropsy999 Jul 21, 2022
1da1d54
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 28, 2022
2078a03
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 28, 2022
9a56401
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 28, 2022
400fbf6
Update 5-network/12-server-sent-events/article.md
astropsy999 Jul 28, 2022
51a327f
Update 6-data-storage/03-indexeddb/article.md
astropsy999 Jul 28, 2022
80213a9
Update 6-data-storage/03-indexeddb/article.md
astropsy999 Jul 28, 2022
51fc021
Update 6-data-storage/03-indexeddb/article.md
astropsy999 Jul 28, 2022
6529a81
Update 6-data-storage/03-indexeddb/article.md
astropsy999 Jul 28, 2022
fd843a1
Update 7-animation/2-css-animations/article.md
astropsy999 Jul 28, 2022
4e193b5
Apply suggestions from code review
dolgachio Aug 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update article.md
88,9%
  • Loading branch information
astropsy999 authored Jun 4, 2022
commit d5d59f6b9e49abdb8156f26904755ee31613ccbc
78 changes: 39 additions & 39 deletions 5-network/12-server-sent-events/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,98 +148,98 @@ id: 3

## Статус підключення: readyState

The `EventSource` object has `readyState` property, that has one of three values:
Об'єкт `EventSource` має властивість `readyState`, яка має одне з трьох значень:

```js no-beautify
EventSource.CONNECTING = 0; // connecting or reconnecting
EventSource.OPEN = 1; // connected
EventSource.CLOSED = 2; // connection closed
EventSource.CONNECTING = 0; // підключення або перепідключення
EventSource.OPEN = 1; // сполучено
EventSource.CLOSED = 2; // з'єднання закрите
```

When an object is created, or the connection is down, it's always `EventSource.CONNECTING` (equals `0`).
Коли створюється об’єкт або з’єднання розривається `EventSource.CONNECTING` (дорівнює `0`).

We can query this property to know the state of `EventSource`.
Ми можемо запитати цю властивість, щоб дізнатися стан `EventSource`.

## Event types
## Типи подій

By default `EventSource` object generates three events:
Типово об’єкт `EventSource` генерує три події:

- `message` -- a message received, available as `event.data`.
- `open` -- the connection is open.
- `error` -- the connection could not be established, e.g. the server returned HTTP 500 status.
- `message` -- отримане повідомлення, доступне як `event.data`.
- `open` -- з'єднання відкрите.
- `error` -- не вдалося встановити з’єднання, напр. сервер повернув статус HTTP 500.

The server may specify another type of event with `event: ...` at the event start.
Сервер може вказати інший тип події з `event: ...` на початку події.

For example:
Наприклад:

```
event: join
data: Bob
data: Боб

data: Hello
data: Привіт

event: leave
data: Bob
data: Боб
```

To handle custom events, we must use `addEventListener`, not `onmessage`:
Щоб обробляти спеціальні події, ми повинні використовувати `addEventListener`, а не `onmessage`:

```js
eventSource.addEventListener('join', event => {
alert(`Joined ${event.data}`);
alert(`Приєднався ${event.data}`);
});

eventSource.addEventListener('message', event => {
alert(`Said: ${event.data}`);
alert(`Сказав: ${event.data}`);
});

eventSource.addEventListener('leave', event => {
alert(`Left ${event.data}`);
alert(`Вийшов ${event.data}`);
});
```

## Full example
## Повний приклад

Here's the server that sends messages with `1`, `2`, `3`, then `bye` and breaks the connection.
Ось сервер, який надсилає повідомлення з `1`, `2`, `3`, потім `bye` та розриває з'єднання.

Then the browser automatically reconnects.
Потім браузер автоматично відновить з’єднання.

[codetabs src="eventsource"]

## Summary
## Резюме
Comment thread
astropsy999 marked this conversation as resolved.
Outdated

`EventSource` object automatically establishes a persistent connection and allows the server to send messages over it.
Об’єкт `EventSource` автоматично встановлює постійне з’єднання і дозволяє серверу надсилати повідомлення через нього.

It offers:
- Automatic reconnect, with tunable `retry` timeout.
- Message ids to resume events, the last received identifier is sent in `Last-Event-ID` header upon reconnection.
- The current state is in the `readyState` property.
Він пропонує:
- Автоматичне перепідключення, з затримкою `retry` що налаштовується.
- Ідентифікатори повідомлень для відновлення подій, останній отриманий id надсилається в заголовку `Last-Event-ID` після повторного з’єднання.
- Поточний стан знаходиться у властивості `readyState`.

That makes `EventSource` a viable alternative to `WebSocket`, as the latter is more low-level and lacks such built-in features (though they can be implemented).
Це робить `EventSource` життєздатною альтернативою `WebSocket`, оскільки останній є більш низькорівневим і не має таких вбудованих функцій (хоча їх можна реалізувати).

In many real-life applications, the power of `EventSource` is just enough.
У багатьох реальних програмах потужності `EventSource` якраз достатньо.

Supported in all modern browsers (not IE).
Підтримується у всіх сучасних браузерах (не в IE).

The syntax is:
Синтаксис такий:

```js
let source = new EventSource(url, [credentials]);
```

The second argument has only one possible option: `{ withCredentials: true }`, it allows sending cross-origin credentials.
Другий аргумент має лише один можливий варіант: `{ withCredentials: true }`, він дозволяє надсилати облікові дані між різними джерелами.

Overall cross-origin security is same as for `fetch` and other network methods.
Загальна безпека між різними джерелами така ж, як і для `fetch` та інших мережевих методів.

### Properties of an `EventSource` object
### Властивості об'єкта `EventSource`

`readyState`
: The current connection state: either `EventSource.CONNECTING (=0)`, `EventSource.OPEN (=1)` or `EventSource.CLOSED (=2)`.
: Поточний стан підключення: або `EventSource.CONNECTING (=0)`, `EventSource.OPEN (=1)` чи `EventSource.CLOSED (=2)`.

`lastEventId`
: The last received `id`. Upon reconnection the browser sends it in the header `Last-Event-ID`.
: Останній отриманний `id`. Після повторного з’єднання браузер надсилає його в заголовку `Last-Event-ID`.

### Methods
### Методик

`close()`
: Closes the connection.
Expand Down