(chunk: Blob)
| 266 | } |
| 267 | |
| 268 | appendChunk(chunk: Blob) { |
| 269 | if (this.disposed) { |
| 270 | return Promise.reject(new Error("Recording spool has been disposed")); |
| 271 | } |
| 272 | |
| 273 | if (this.writeError) { |
| 274 | return Promise.reject(this.writeError); |
| 275 | } |
| 276 | |
| 277 | this.pendingChunks.push(chunk); |
| 278 | this.pendingChunkBytes += chunk.size; |
| 279 | if (this.pendingChunkBytes > this.maxPendingChunkBytes) { |
| 280 | this.writeError = new RecordingSpoolBackpressureError(); |
| 281 | return Promise.reject(this.writeError); |
| 282 | } |
| 283 | |
| 284 | return this.enqueue(async () => { |
| 285 | const index = this.nextChunkIndex; |
| 286 | const updatedSession = { |
| 287 | ...this.session, |
| 288 | totalBytes: this.session.totalBytes + chunk.size, |
| 289 | chunkCount: this.session.chunkCount + 1, |
| 290 | updatedAt: Date.now(), |
| 291 | } satisfies RecordingSpoolSessionRecord; |
| 292 | |
| 293 | await this.backend.appendChunk(updatedSession, index, chunk); |
| 294 | const persistedChunk = this.pendingChunks.shift(); |
| 295 | if (persistedChunk) { |
| 296 | this.pendingChunkBytes = Math.max( |
| 297 | 0, |
| 298 | this.pendingChunkBytes - persistedChunk.size, |
| 299 | ); |
| 300 | } |
| 301 | this.nextChunkIndex = index + 1; |
| 302 | this.session = updatedSession; |
| 303 | }); |
| 304 | } |
| 305 | |
| 306 | // Heartbeat for the liveness contract above: refreshes the session's |
| 307 | // updatedAt without writing a chunk so paused recordings stay recognisably |
nothing calls this directly
no test coverage detected