Skip to content

Commit daa6376

Browse files
committedFeb 6, 2024
undo sse change
1 parent b623f37 commit daa6376

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed
 

‎lib/stream.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1+
2+
/**
3+
* A server-sent event.
4+
*/
15
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+
*/
214
constructor(event, data, id, retry) {
315
this.event = event;
416
this.data = data;
517
this.id = id;
618
this.retry = retry;
719
}
820

21+
/**
22+
* Convert the event to a string.
23+
*/
924
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;
1927
}
20-
if (this.data) {
21-
result += `data: ${this.data}\n`;
22-
}
23-
result += '\n';
24-
return result;
28+
29+
return "";
2530
}
2631
}
2732

0 commit comments

Comments
 (0)