diff --git a/src/lib/camera/RecordingManagement.ts b/src/lib/camera/RecordingManagement.ts index 06ffe7e66..09889745e 100644 --- a/src/lib/camera/RecordingManagement.ts +++ b/src/lib/camera/RecordingManagement.ts @@ -1018,6 +1018,10 @@ class CameraRecordingStream extends EventEmitter implements DataStreamProtocolHa let offset = 0; let dataChunkSequenceNumber = 1; while (offset < fragment.length) { + if (this.closed) { + break; + } + const data = fragment.slice(offset, offset + maxChunk); offset += data.length; diff --git a/src/lib/datastream/DataStreamServer.ts b/src/lib/datastream/DataStreamServer.ts index 9d997f862..292351e9b 100644 --- a/src/lib/datastream/DataStreamServer.ts +++ b/src/lib/datastream/DataStreamServer.ts @@ -715,7 +715,9 @@ export class DataStreamConnection extends EventEmitter { header.protocol = protocol; header.event = event; - this.sendHDSFrame(header, message); + if (this.state === ConnectionState.READY) { + this.sendHDSFrame(header, message); + } } /**