* Overloads onData to detect payloads. * * @protected
(data)
| 80 | * @protected |
| 81 | */ |
| 82 | override onData(data) { |
| 83 | debug("polling got data %s", data); |
| 84 | const callback = (packet) => { |
| 85 | // if its the first message we consider the transport open |
| 86 | if ("opening" === this.readyState && packet.type === "open") { |
| 87 | this.onOpen(); |
| 88 | } |
| 89 | |
| 90 | // if its a close packet, we close the ongoing requests |
| 91 | if ("close" === packet.type) { |
| 92 | this.onClose({ description: "transport closed by the server" }); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // otherwise bypass onData and handle the message |
| 97 | this.onPacket(packet); |
| 98 | }; |
| 99 | |
| 100 | // decode payload |
| 101 | decodePayload(data, this.socket.binaryType).forEach(callback); |
| 102 | |
| 103 | // if an event did not trigger closing |
| 104 | if ("closed" !== this.readyState) { |
| 105 | // if we got data we're not polling |
| 106 | this._polling = false; |
| 107 | this.emitReserved("pollComplete"); |
| 108 | |
| 109 | if ("open" === this.readyState) { |
| 110 | this._poll(); |
| 111 | } else { |
| 112 | debug('ignoring poll - transport state "%s"', this.readyState); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * For polling, send a close packet. |
nothing calls this directly
no test coverage detected