File tree 1 file changed +19
-14
lines changed
1 file changed +19
-14
lines changed Original file line number Diff line number Diff line change
1
+
2
+ /**
3
+ * A server-sent event.
4
+ */
1
5
class ServerSentEvent {
6
+ /**
7
+ * Create a new server-sent event.
8
+ *
9
+ * @param {string } event The event name.
10
+ * @param {string } data The event data.
11
+ * @param {string } id The event ID.
12
+ * @param {number } retry The retry time.
13
+ */
2
14
constructor ( event , data , id , retry ) {
3
15
this . event = event ;
4
16
this . data = data ;
5
17
this . id = id ;
6
18
this . retry = retry ;
7
19
}
8
20
21
+ /**
22
+ * Convert the event to a string.
23
+ */
9
24
toString ( ) {
10
- let result = '' ;
11
- if ( this . id ) {
12
- result += `id: ${ this . id } \n` ;
13
- }
14
- if ( this . event ) {
15
- result += `event: ${ this . event } \n` ;
16
- }
17
- if ( this . retry ) {
18
- result += `retry: ${ this . retry } \n` ;
25
+ if ( this . event === "output" ) {
26
+ return this . data ;
19
27
}
20
- if ( this . data ) {
21
- result += `data: ${ this . data } \n` ;
22
- }
23
- result += '\n' ;
24
- return result ;
28
+
29
+ return "" ;
25
30
}
26
31
}
27
32
You can’t perform that action at this time.
0 commit comments