(id, body)
| 25 | } |
| 26 | |
| 27 | send(id, body) { |
| 28 | const res = this.sessions[id]; |
| 29 | if (res && res.connection && res.connection.writable) { |
| 30 | this.eventId++; |
| 31 | res.locals = { |
| 32 | eventId: this.eventId, |
| 33 | body, |
| 34 | id, |
| 35 | }; |
| 36 | res.write(`data: ${body}\neventId:${this.eventId}\n\n`); |
| 37 | |
| 38 | if (res.xhr) { |
| 39 | res.end(); // lets older browsers finish their xhr request |
| 40 | } |
| 41 | } else { |
| 42 | delete this.sessions[id]; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | ping(id) { |
| 47 | const res = this.sessions[id]; |