/
752.txt
373 lines (264 loc) · 15.5 KB
/
752.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
[13] [DFN[[CODE(DOMi)@en[[[EventSource]]]]]] は、[[遠隔DOM事象]]を受信するための[[物体]]が実装する
[[DOM]] [[界面]]です。
* 仕様書
[REFS[
- [48] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2014-12-04 10:25:09 +09:00]] 版) <https://html.spec.whatwg.org/#server-sent-events>
]REFS]
* 文脈
[66] いわゆる[[プッシュ型]]の[[サーバー]]から[[クライアント]]への情報伝達に使うことができます。
[67] しかし更新頻度が低ければ[[ポーリング]]でよく、高いか不定なら [[WebSocket]]
が便利なので、 [[SSE]] はあまり出番もないかもしれません。
[EG[
[68] 例えば[[チャット]]は[[サーバー]]から任意のタイミングで発言を送信したいので、
[[SSE]] が使えそうに見えます。しかし[[クライアント]]から[[サーバー]]へも発言を送りたいので、
どうせなら同じ [[WebSocket]] の接続を使った方がよく、一方向の [[SSE]]
を使う理由は薄いです。
]EG]
* [CODE(DOMi)@en[EventSource]] コンストラクター
[73]
[FIG(steps)[
@@
= [74] [[文脈オブジェクト]]の[F[関連設定群オブジェクト]]の[F[大域オブジェクト]]の
[F[[CODE(DOMi)@en[EventSource]]群]]に、
[[弱い参照]]で[VAR[イベント源]]を追加します。
[WEAK[([[unloading document cleanup steps]] で参照されます。)]]
= [75] [VAR[イベント源]]を返します。
]FIG]
* 歴史
** [CODE(HTMLe)@en[event-source]] 要素の登場
[14] はじめ、 [CODE(HTMLe)@en[[[event-source]]]] [[要素]]として [[Ian Hickson]]
により提案されていました。この提案は後に [[Web Applications 1.0]] 仕様書
([[HTML5]]) に組み入れられました。
;; [23] [CITE@en-GB-x-Hixie[Hixie's Natural Log: Server-sent DOM events]] ([TIME[2004-04-28 15:45]] 版) <http://ln.hixie.ch/?start=1083167110&count=1>
;; [22]
[CITE@en-GB-hixie[Server Sent Events 1.0]] ([TIME[2006-07-31 15:51:28 +09:00]] 版) <http://hixie.ch/specs/html/server-sent-events/server-sent-events-1>
>Working Draft 8 June 2004
[DEL[
[1]
[CITE[Web Applications 1.0]] <http://www.whatwg.org/specs/web-apps/current-work/#scs-server-sent>
]DEL]
[27] 2008年2月に大改訂がありましたが、その前の仕様は >>28 のような感じでした。
[28] [CITE@en-GB-hixie[HTML 5]] ([TIME[2007-10-29 06:22:51 +09:00]] 版) <http://www.whatwg.org/specs/web-apps/2007-10-26/#server-sent-events>
[21] [[Opera]] 9 以降で実装されています。 [[ニンテンドーDSiブラウザー]]でも使えます。
[2]
[CITE[Opera Web Chat]] <http://oxzone.opera.com/webchat/>
([[名無しさん]])
[3]
[CITE[Event Streaming to Web Browsers - Web Applications Blog - by Web Applications]] <http://my.opera.com/WebApplications/blog/show.dml/438711>
[19] [CITE@en[Event Streaming to Web Browsers]]
([[Opera Software ASA]] 著, [TIME[2011-02-03 10:59:19 +09:00]] 版)
<http://labs.opera.com/news/2006/09/01/>
[4]
[CITE[EarthQuakes Map Widget - Opera Widgets]] <http://widgets.opera.com/widget/5178>
([[名無しさん]] [WEAK[2006-09-09 03:28:34 +00:00]])
[5]
[CITE[Bug 338583 – Add support for Server-Sent DOM Events (Remote Events)]] ([CODE[2007-08-17 13:54:47 +09:00]] 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=338583>
** [CODE(MIME)@en[application/x-dom-event-stream]] から [CODE(MIME)@en[text/event-stream]] へ
[6]
[[Hixie]] が Status を [Q@en[Being considered for removal]] に設定しているみたいです。
([[名無しさん]] [WEAK[2007-12-09 05:50:04 +00:00]])
[7]
>>6 大改訂があった結果、[CODE(HTMLe)@en[[[event-source]]]]
は [Q@en[Last call for comments]]、
[[鯖送信DOM事象]]の章は [Q@en[Working draft]]
になっています。
([[名無しさん]] [WEAK[2008-02-23 10:28:51 +00:00]])
[8]
>>7 さっきの [[Ian Hickson]] の [['''#'''whatwg]] での発言によると、
削ろうと思ったけど残すべきという意見があって、
それがもっともだと思ったから削るのはやめたと。
([[名無しさん]] [WEAK[2008-02-23 10:41:26 +00:00]])
[9]
[CITE[Re: several messages about <event-source> and related subjects]] ([[Ian Hickson <ian@...>]] 著, [TIME[2008-02-22 10:16:51 +09:00]] 版) <http://permalink.gmane.org/gmane.org.w3c.whatwg.discuss/13321>
[24] [CITE@en[HTML5 Tracker]] ([TIME[2008-02-22 09:43Z]] 版) <http://html5.org/tools/web-apps-tracker?from=1236&to=1238>
[25] >>24 では大規模な変更があり、 [[MIME型]]も [CODE(MIME)@en[[[application/x-dom-event-stream]]]]
から [CODE(MIME)@en[[[text/event-stream]]]] に変更されました。
** [CODE(HTMLe)@en[event-source]] から [CODE(HTMLe)@en[eventsource]] へ
[10] [[HTML5]] で定義されていた [CODE(HTMLe)@en[[[event-source]]]] [[要素]]は、
[CODE(HTMLe)@en[[[eventsource]]]] に改名されました。
;; [26] [CITE@en[Web Applications 1.0 r1863 Rename <event-source> to <eventsource> for consistency, while we sill can]] ([TIME[2008-07-11 18:40:00 +09:00]] 版) <http://html5.org/tools/web-apps-tracker?from=1862&to=1863>
** [CODE(HTMLe)@en[eventsource]] 要素から [CODE(DOMi)@en[EventSource]] 界面へ
[11] 以前から [CODE(HTMLe)@en[[[eventsource]]]] [[要素]]は[[要素]]である意味があるのか疑問視する意見がありましたが、
2009年2月に[[要素]]としては削除され、 [CODE(DOMi)@en[[[EventSource]]]] [[DOM]] [[界面]]となりました。
[12] [CITE[IRC logs: freenode / #whatwg / 20090226]] ([TIME[2009-03-09 18:58:46 +09:00]] 版) <http://krijnhoetmer.nl/irc-logs/whatwg/20090226#l-250>
>17:40 (hsivonen) Hixie: so what's the remaining selling point over Web Sockets? that you can feed EventSource from a regular HTTP server?
>17:40 (Hixie) the only selling point over websocket that it's ever had is that it is compatible with CGI scripts
[15] [CITE@en-US-x-Hixie[Server-Sent Events]] ([TIME[2009-03-27 10:09:23 +09:00]] 版) <http://dev.w3.org/cvsweb/~checkout~/html5/eventsource/Overview.html?content-type=text/html;%20charset=utf-8>
[16] [CITE@en-US-x-Hixie[Server-Sent Events]] ([TIME[2009-04-23 13:50:52 +09:00]] 版) <http://www.w3.org/TR/2009/WD-eventsource-20090423/>
[17] [CITE@en[(X)HTML5 Tracking]]
([TIME[2009-09-06 10:20:51 +09:00]] 版)
<http://html5.org/tools/web-apps-tracker?from=2869&to=2870>
[18] [CITE[IRC logs: freenode / #whatwg / 20100427]]
([TIME[2010-05-16 19:00:37 +09:00]] 版)
<http://krijnhoetmer.nl/irc-logs/whatwg/20100427#l-174>
* テスト・ケース
[20] [CITE[Index of /~wakaba/-temp/test/dom/eventsource]]
([TIME[2011-02-03 11:02:37 +09:00]] 版)
<http://suika.fam.cx/~wakaba/-temp/test/dom/eventsource/>
* メモ
[29] [CITE@en-US-x-Hixie[Server-Sent Events]]
( ([TIME[2011-02-09 06:05:52 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-eventsource-20110208/>
[30] [CITE[''''''[''''''whatwg'''''']'''''' EventSource - Handling a charset in the content-type header]]
( ([TIME[2011-06-18 08:37:41 +09:00]] 版))
<http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-June/032120.html>
[31] [CITE[''''''[''''''whatwg'''''']'''''' Enhancement request: change EventSource to allow cross-domain access]]
( ([TIME[2011-06-18 08:38:12 +09:00]] 版))
<http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-June/032152.html>
[32] [CITE@en-US-x-Hixie[Server-Sent Events]]
( ([TIME[2011-10-19 02:35:51 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-eventsource-20111020/>
[33] [CITE@ja[Opera Desktop Team - Web Sockets enter the Opera House]]
( ([TIME[2010-10-23 00:19:44 +09:00]] 版))
<http://my.opera.com/desktopteam/blog/2010/10/11/websockets>
[34] [CITE@en[Web Applications 1.0 r6848 Require implementations to ignore all MIME type parameters on text/event-stream resourcesAffected topics: Server-Sent Events]]
( ([TIME[2011-12-07 08:52:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6847&to=6848>
[35] [CITE@en-US-x-Hixie[Server-Sent Events]]
([TIME[2009-10-29 03:44:26 +09:00]] 版)
<http://www.w3.org/TR/2009/WD-eventsource-20091029/>
[36] [CITE@en-US-x-Hixie[Server-Sent Events]]
( ([TIME[2012-04-25 05:35:01 +09:00]] 版))
<http://www.w3.org/TR/2012/WD-eventsource-20120426/>
[37] [CITE[''''''[''''''ietf-types'''''']'''''' Registration for text/event-stream]]
( ([TIME[2012-08-07 11:52:20 +09:00]] 版))
<http://www.ietf.org/mail-archive/web/ietf-types/current/msg01713.html>
[38] [CITE@en-US-x-Hixie[Server-Sent Events]]
( ([TIME[2012-10-22 21:35:04 +09:00]] 版))
<http://www.w3.org/TR/2012/WD-eventsource-20121023/>
[39] [CITE@en-US-x-Hixie[Server-Sent Events]]
( ([TIME[2012-12-10 08:07:34 +09:00]] 版))
<http://www.w3.org/TR/2012/CR-eventsource-20121211/>
[40] [CITE@en-US-x-Hixie[Server-Sent Events]]
([TIME[2009-12-18 01:36:25 +09:00]] 版)
<http://www.w3.org/TR/2009/WD-eventsource-20091222/>
[41] [CITE@en-US-x-Hixie[Server-Sent Events]]
( ([TIME[2011-03-10 02:22:44 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-eventsource-20110310/>
[42] [CITE[IRC logs: freenode / #whatwg / 20130917]]
( ([TIME[2013-09-20 00:01:06 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20130917>
[43] [CITE@en[Web Applications 1.0 r3552 Include MIME type registration sections.]]
( ([TIME[2009-08-07 18:44:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=3551&to=3552>
[44] [CITE@en[Web Applications 1.0 r8475 Make the EventSource processing model a mite more generic to allow other user agent types to implement this spec.]]
( ([TIME[2014-02-08 09:31:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=8474&to=8475>
[45] [CITE@en[MIX: Dropping exceptions for XHR and EventSource. · aac819b · w3c/webappsec]]
( ([TIME[2014-11-04 03:25:13 +09:00]] 版))
<https://github.com/w3c/webappsec/commit/aac819b28287e8fd3a9ebad2666336e2bc77a24b>
[46] [CITE@en[RE: ''''''[''''''eventsource'''''']'''''' Seeking status and plans]]
( ([[Zhang, Zhiqiang]] 著, [TIME[2014-10-15 18:10:48 +09:00]] 版))
<http://lists.w3.org/Archives/Public/public-test-infra/2014OctDec/0009.html>
[47] [CITE@en-US[Server-Sent Events]]
( ([TIME[2014-12-05 04:46:25 +09:00]] 版))
<http://www.w3.org/TR/2014/PR-eventsource-20141209/>
[49] [CITE@en[Streaming | Flowdock API]]
( ([TIME[2015-01-05 20:57:48 +09:00]] 版))
<https://www.flowdock.com/api/streaming>
[50] [CITE@en-US[Server-Sent Events]]
( ([TIME[2015-01-29 18:17:14 +09:00]] 版))
<http://www.w3.org/TR/2015/REC-eventsource-20150203/>
[FIG(quote)[
[FIGCAPTION[
[51] [CITE@en[Streaming | Flowdock API]]
([TIME[2015-03-29 18:05:37 +09:00]] 版)
<https://www.flowdock.com/api/streaming>
]FIGCAPTION]
> Event-Stream follows the HTML5 Server-Sent Events specification. Each event contains a JSON-encoded message.
]FIG]
[FIG(quote)[
[FIGCAPTION[
[52] [CITE[REST API - Firebase]]
([TIME[2015-03-29 19:06:44 +09:00]] 版)
<https://www.firebase.com/docs/rest/api/#section-streaming>
]FIGCAPTION]
> Firebase REST endpoints support the EventSource / Server-Sent Events protocol as well.
]FIG]
[53] [CITE@en[1156137 – EventSource only works with HTTP channels]]
([TIME[2015-04-27 23:09:59 +09:00]] 版)
<https://bugzilla.mozilla.org/show_bug.cgi?id=1156137>
[54] [CITE[''''''[''''''whatwg'''''']'''''' Server-sent events feedback]]
( ([TIME[2011-02-05 09:56:18 +09:00]] 版))
<http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-February/030205.html>
[55] [CITE@en[25984 – EventSource should support RequestInfo]]
([TIME[2015-09-16 11:39:00 +09:00]] 版)
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=25984>
[56] [CITE@en[Integrate Fetch into HTML · whatwg/html@7c5555a]]
([TIME[2015-09-18 19:46:07 +09:00]] 版)
<https://github.com/whatwg/html/commit/7c5555a16f2920c02244c10756bb2f1a11e87a22>
[57] [CITE@en[Allow user agents to fail a failed EventSource connection · whatwg/html@3970693]]
([TIME[2015-10-07 13:45:27 +09:00]] 版)
<https://github.com/whatwg/html/commit/3970693427240344dc09ae68cd21214fe3fc6622>
[58] [CITE@en[PSA: Change the Latest Editor's Drafts of WebStorage, WebWorkers, WebMessaging, Server-Sent Events and WebSockets]]
([[Xiaoqian Wu]] 著, [TIME[2015-10-20 02:52:22 +09:00]] 版)
<https://lists.w3.org/Archives/Public/public-webapps/2015OctDec/0099.html>
[59] [CITE@en[URLs are parsed and produce records · whatwg/html@30bc255]]
([TIME[2016-02-14 23:05:21 +09:00]] 版)
<https://github.com/whatwg/html/commit/30bc2557105ad62881ec9670f253febbc9761b44>
[60] [CITE@en[EventSource has no need to set Cache-Control · whatwg/html@6f47a53]]
([TIME[2016-03-08 18:38:51 +09:00]] 版)
<https://github.com/whatwg/html/commit/6f47a53c915ba001cb9e8f7d106a4dcab2a03f98>
[FIG(quote)[
[FIGCAPTION[
[61] [CITE[JSON Mail Access Protocol Specification (JMAP)]]
([TIME[2016-03-11 14:55:42 +09:00]] 版)
<http://jmap.io/spec.html>
]FIGCAPTION]
> There are two mechanisms by which the client can receive the push events. The first is directly via a text/event-stream resource
]FIG]
[62] [CITE@en[Make EventSource use the base URL of its global · whatwg/html@3175b53]]
([TIME[2016-04-22 18:23:18 +09:00]] 版)
<https://github.com/whatwg/html/commit/3175b53a7fab83a62fc1c5674e8356f720d2aa4a>
[63] [CITE@en[Move server-sent events IANA considerations to the index]]
( ([[momdo]]著, [TIME[2016-05-23 21:11:39 +09:00]]))
<https://github.com/whatwg/html/commit/bb1e4e65145b670027de8562e427280a4aa85e94>
[FIG(quote)[
[FIGCAPTION[
[64] [CITE[Server-Sent Eventsでtail -Fっぽいやつ - Qiita]]
( ([TIME[2016-05-26 21:54:34 +09:00]]))
<http://qiita.com/usopyon/items/6067d3d249be7a5d2867>
]FIGCAPTION]
> tail -Fっぽく、ファイルが更新されたらブラウザに差分をPUSHするスクリプトを書いてみました。
]FIG]
[65] [CITE@en[Align Fetch's destination concept with changes in Fetch]]
([[sideshowbarker]]著, [TIME[2016-07-05 02:46:14 +09:00]])
<https://github.com/whatwg/html/commit/5e8f96a85d182d36c177db0d6fdde58b4ded86d4>
[69] [CITE@en[Set some MessageEvent's isTrusted attributes to true]]
([[domenic]]著, [TIME[2016-10-26 02:33:24 +09:00]])
<https://github.com/whatwg/html/commit/eecea4bf565a442e98c2ec98bf298d082d196282>
[70] [CITE@en[Specify the realm for the SSE MessageEvent]]
([[domenic]]著, [TIME[2016-10-28 02:17:38 +09:00]])
<https://github.com/whatwg/html/commit/91d19d647433203f1f319e2afe76e63ceae646ca>
[FIG(quote)[
[FIGCAPTION[
[71] [CITE@en[Streaming | Flowdock API]]
([TIME[2016-12-21 22:49:46 +09:00]])
<https://www.flowdock.com/api/streaming>
]FIGCAPTION]
> Event-Stream (text/event-stream)
> Event-Stream follows the HTML5 Server-Sent Events specification. Each event contains a JSON-encoded message.
]FIG]
[FIG(quote)[
[FIGCAPTION[
[72] [CITE[Realtime messaging - Restdb.io]]
([[the team at restdb.io]]著, [TIME[2016-12-21 23:02:15 +09:00]])
<https://restdb.io/docs/realtime-messaging>
]FIGCAPTION]
> RestDB.io can act as a Realtime messaging hub for your application. You can use the realtime API from web clients and servers, actually any client that can connect to your database using the HTTP EventSource API.
>
]FIG]
[FIG(quote)[
[FIGCAPTION[
[76] [CITE@en[RFC 8040 - RESTCONF Protocol]]
([TIME[2017-03-27 23:03:09 +09:00]])
<https://tools.ietf.org/html/rfc8040>
]FIGCAPTION]
> event stream resource: a resource that represents an SSE
> (Server-Sent Events) event stream. The content consists of text
> using the media type "text/event-stream", as defined by the SSE
> specification
]FIG]
[77] [CITE@en[documentation/Streaming-API.md at master · tootsuite/documentation]]
([TIME[2017-04-14 00:48:51 +09:00]])
<https://github.com/tootsuite/documentation/blob/master/Using-the-API/Streaming-API.md>