You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 5-network/12-server-sent-events/article.md
+29-29Lines changed: 29 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,64 +207,64 @@ Then the browser automatically reconnects.
207
207
[codetabs src="eventsource"]
208
208
209
209
210
-
## Summary
210
+
## Итоги
211
211
212
-
The`EventSource`object communicates with the server. It establishes a persistent connection and allows the server to send messages over it.
212
+
Объект`EventSource`"общается" с сервером. Он устанавливает постоянное соединение и позволяет серверу отправлять через него сообщения.
213
213
214
-
It offers:
215
-
-Automatic reconnect, with tunable `retry`timeout.
216
-
-Message ids to resume events, the last identifier is sent in `Last-Event-ID` header.
217
-
-The current state is in the `readyState` property.
214
+
Он предоставляет:
215
+
-Автоматическое переподключение после истечения настраиваемой с помощью `retry`задержки.
216
+
-Идентификаторы сообщений для восстановления "общения" с сервером, последний идентификатор посылается в заголовке `Last-Event-ID`.
217
+
-Текущее состояние, записанное в свойстве `readyState`.
218
218
219
-
That makes`EventSource`a viable alternative to `WebSocket`, as it's more low-level and lacks these features.
219
+
Это делает`EventSource`достойной альтернативой протоколу `WebSocket`, который не имеет этих функций.
220
220
221
-
In many real-life applications, the power of `EventSource`is just enough.
221
+
Для многих приложений возможностей `EventSource`вполне достаточно.
222
222
223
-
Supported in all modern browsers (not IE).
223
+
Поддерживается во всех современных браузерах (кроме Internet Explorer).
224
224
225
-
The syntax is:
225
+
Синтаксис:
226
226
227
227
```js
228
228
let source =newEventSource(url, [credentials]);
229
229
```
230
230
231
-
The second argument has only one possible option: `{ withCredentials: true }`, it allows sending cross-domain credentials.
231
+
Второй аргумент - объект с одним свойством: `{ withCredentials: true }`, позволяет передавать вместе с запросом авторизирующие заголовки.
232
232
233
-
Overall cross-domain security is same as for `fetch`and other network methods.
233
+
В целом, кросс-доменная безопасность на таком же уровне, как у `fetch`и других методов работы с сетью.
234
234
235
-
### Properties of an `EventSource` object
235
+
### Свойства объекта `EventSource`
236
236
237
237
`readyState`
238
-
: The current connection state: either `EventSource.CONNECTING (=0)`, `EventSource.OPEN (=1)`or`EventSource.CLOSED (=2)`.
238
+
: Текущее состояние подключения: `EventSource.CONNECTING (=0)`, `EventSource.OPEN (=1)`или`EventSource.CLOSED (=2)`.
239
239
240
240
`lastEventId`
241
-
: The last received `id`. Upon reconnection the browser sends it in the header`Last-Event-ID`.
241
+
: `id` последнего полученного сообщения. При переподключении браузер посылает его в заголовке`Last-Event-ID`.
242
242
243
-
### Methods
243
+
### Методы
244
244
245
245
`close()`
246
-
: Closes the connection соединение.
246
+
: Закрывает соединение.
247
247
248
-
### Events
248
+
### События
249
249
250
250
`message`
251
-
: Message received, the data is in`event.data`.
251
+
: Сообщение получено, переданные данные записаны в`event.data`.
252
252
253
253
`open`
254
-
: The connection is established.
254
+
: Соединение установлено.
255
255
256
256
`error`
257
-
: In case of an error, including both lost connection (will auto-reconnect) and fatal errors. We can check `readyState` to see if the reconnection is being attempted.
257
+
: Потеряно соединение (произойдет переподключение) или произошла фатальная ошибка. Мы можем обратиться к свойству `readyState`, чтобы проверить происходит ли переподключение.
258
258
259
-
The server may set a custom event name in `event:`. Such events should be handled using `addEventListener`, not`on<event>`.
259
+
Сервер может выставить собственное событие с помощью `event:`. Такие события должны быть обработаны с помощью `addEventListener`, а не`on<event>`.
0 commit comments