Update main.ts

Refactored code
This commit is contained in:
kvazibox
2022-01-20 18:25:51 +10:00
committed by GitHub
parent 3844ea2951
commit 75cd19e79a

View File

@@ -31,37 +31,30 @@ class AmcrestCamera extends RtspSmartCamera implements VideoCameraConfiguration,
}
async updateDeviceInfo(): Promise<void> {
const vendorResponse = await this.getClient().digestAuth.request({
url: `http://${this.getHttpAddress()}/cgi-bin/magicBox.cgi?action=getVendor`
});
const vendorName = String(vendorResponse.data).replace("vendor=", "");
var deviceInfo = {};
const serialNumberResponse = await this.getClient().digestAuth.request({
url: `http://${this.getHttpAddress()}/cgi-bin/magicBox.cgi?action=getSerialNo`
});
const serialNumber = String(serialNumberResponse.data).replace("sn=", "");
const deviceParameters = [
{"action":"getVendor","replace":"vendor=","parameter":"manufacturer"},
{"action":"getSerialNo","replace":"sn=","parameter":"serialNumber"},
{"action":"getDeviceType","replace":"type=","parameter":"model"},
{"action":"getSoftwareVersion","replace":"version=","parameter":"firmware"}
];
const deviceTypeResponse = await this.getClient().digestAuth.request({
url: `http://${this.getHttpAddress()}/cgi-bin/magicBox.cgi?action=getDeviceType`
});
for (const element of deviceParameters) {
try {
const response = await this.getClient().digestAuth.request({
url: `http://${this.getHttpAddress()}/cgi-bin/magicBox.cgi?action=${element['action']}`
});
const deviceType = String(deviceTypeResponse.data).replace("type=", "");
const result = String(response.data).replace(element['replace'], "");
deviceInfo[element['parameter']] = result;
}
catch (e) {
this.console.error('Error getting device parameter', element['action'], e);
}
}
const softwareVersionResponse = await this.getClient().digestAuth.request({
url: `http://${this.getHttpAddress()}/cgi-bin/magicBox.cgi?action=getSoftwareVersion`
});
const softwareVersion = String(softwareVersionResponse.data).replace("version=", "");
this.info = {
manufacturer: vendorName,
model: deviceType,
firmware: softwareVersion,
version: softwareVersion,
serialNumber: serialNumber,
};
this.info = deviceInfo;
}
async setVideoStreamOptions(options: MediaStreamOptions): Promise<void> {