From a33bda34ef12f317cfa1bc64cdf8aa108989ff82 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 30 May 2022 17:49:13 -0700 Subject: [PATCH] onvif: dont fail if name/hardware parsing fails --- plugins/onvif/package-lock.json | 6 +++--- plugins/onvif/package.json | 2 +- plugins/onvif/src/main.ts | 25 ++++++++++++++----------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/plugins/onvif/package-lock.json b/plugins/onvif/package-lock.json index 9b005fdd4..1f4a8696e 100644 --- a/plugins/onvif/package-lock.json +++ b/plugins/onvif/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/onvif", - "version": "0.0.86", + "version": "0.0.88", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/onvif", - "version": "0.0.86", + "version": "0.0.88", "license": "Apache", "dependencies": { "@koush/axios-digest-auth": "^0.8.5", @@ -41,7 +41,7 @@ }, "../../sdk": { "name": "@scrypted/sdk", - "version": "0.0.192", + "version": "0.0.198", "license": "ISC", "dependencies": { "@babel/preset-typescript": "^7.16.7", diff --git a/plugins/onvif/package.json b/plugins/onvif/package.json index d5a5823f6..9066ccc13 100644 --- a/plugins/onvif/package.json +++ b/plugins/onvif/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/onvif", - "version": "0.0.86", + "version": "0.0.88", "description": "ONVIF Camera Plugin for Scrypted", "author": "Scrypted", "license": "Apache", diff --git a/plugins/onvif/src/main.ts b/plugins/onvif/src/main.ts index da2d6b704..74c1ef33b 100644 --- a/plugins/onvif/src/main.ts +++ b/plugins/onvif/src/main.ts @@ -348,19 +348,22 @@ class OnvifProvider extends RtspProvider implements DeviceDiscovery, Settings { this.console.error('discovery error', err); return; } - let urn = result['Envelope']['Body'][0]['ProbeMatches'][0]['ProbeMatch'][0]['EndpointReference'][0]['Address'][0].payload; - let xaddrs = result['Envelope']['Body'][0]['ProbeMatches'][0]['ProbeMatch'][0]['XAddrs'][0].payload; - let scopes = result['Envelope']['Body'][0]['ProbeMatches'][0]['ProbeMatch'][0]['Scopes'][0].payload; - scopes = scopes.split(" "); + const urn = result['Envelope']['Body'][0]['ProbeMatches'][0]['ProbeMatch'][0]['EndpointReference'][0]['Address'][0].payload; + const xaddrs = result['Envelope']['Body'][0]['ProbeMatches'][0]['ProbeMatch'][0]['XAddrs'][0].payload; + let name: string; - let hardware = ""; - let name = ""; - for (let i = 0; i < scopes.length; i++) { - if (scopes[i].includes('onvif://www.onvif.org/name')) { name = decodeURI(scopes[i].substring(27)); } - if (scopes[i].includes('onvif://www.onvif.org/hardware')) { hardware = decodeURI(scopes[i].substring(31)); } + try { + let scopes = result['Envelope']['Body'][0]['ProbeMatches'][0]['ProbeMatch'][0]['Scopes'][0].payload; + scopes = scopes.split(" "); + + for (let i = 0; i < scopes.length; i++) { + if (scopes[i].includes('onvif://www.onvif.org/name')) { name = decodeURI(scopes[i].substring(27)); } + } } - let msg = 'Discovery Reply from ' + rinfo.address + ' (' + name + ') (' + hardware + ') (' + xaddrs + ') (' + urn + ')'; - this.console.log(msg); + catch (e) { + } + + this.console.log('Discovery Reply from ' + rinfo.address + ' (' + name + ') (' + xaddrs + ') (' + urn + ')'); const isNew = !deviceManager.getNativeIds().includes(urn); if (!isNew)