Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HKSV: Skip updateRecordingActive delegate call if value didn't change #944

Merged
merged 4 commits into from
Sep 17, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
HKSV: Skip updateRecordingActive delegate call if value didn't change
  • Loading branch information
Supereg committed Apr 23, 2022
commit 6eead5133217b72a9b7c2b93c87d3998c0466110
19 changes: 16 additions & 3 deletions src/lib/camera/RecordingManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ export class RecordingManagement {
*/
sensorServices: Service[] = [];

/**
* Defines if recording is enabled for this recording management.
*/
private recordingActive = false;

constructor(
options: CameraRecordingOptions,
delegate: CameraRecordingDelegate,
Expand Down Expand Up @@ -436,7 +441,14 @@ export class RecordingManagement {
.setProps({ adminOnlyAccess: [Access.WRITE] });

this.recordingManagementService.getCharacteristic(Characteristic.Active)
.onSet(value => this.delegate.updateRecordingActive(!!value))
.onSet(value => {
if (!!value === this.recordingActive) {
return; // skip delegate call if state didn't change!
Supereg marked this conversation as resolved.
Show resolved Hide resolved
}

this.recordingActive = !!value;
this.delegate.updateRecordingActive(this.recordingActive);
})
.on(CharacteristicEventTypes.CHANGE, () => this.stateChangeDelegate?.())
.setProps({ adminOnlyAccess: [Access.WRITE] });

Expand Down Expand Up @@ -486,7 +498,7 @@ export class RecordingManagement {
return;
}

if (!this.recordingManagementService.getCharacteristic(Characteristic.Active).value) {
if (!this.recordingActive) {
connection.sendResponse(Protocols.DATA_SEND, Topics.OPEN, id, HDSStatus.PROTOCOL_SPECIFIC_ERROR, {
status: HDSProtocolSpecificErrorReason.NOT_ALLOWED,
});
Expand Down Expand Up @@ -749,7 +761,7 @@ export class RecordingManagement {
},
selectedConfiguration: this.selectedConfiguration?.base64,

recordingActive: !!this.recordingManagementService.getCharacteristic(Characteristic.Active).value,
recordingActive: this.recordingActive,
recordingAudioActive: !!this.recordingManagementService.getCharacteristic(Characteristic.RecordingAudioActive).value,

eventSnapshotsActive: !!this.operatingModeService.getCharacteristic(Characteristic.EventSnapshotsActive).value,
Expand Down Expand Up @@ -777,6 +789,7 @@ export class RecordingManagement {
}
}

this.recordingActive = serialized.recordingActive;
this.recordingManagementService.updateCharacteristic(Characteristic.Active, serialized.recordingActive);
this.recordingManagementService.updateCharacteristic(Characteristic.RecordingAudioActive, serialized.recordingAudioActive);

Expand Down