mirror of
https://github.com/koush/scrypted.git
synced 2026-02-11 01:32:02 +00:00
Update main.ts
Refactored code
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user