GuilhermeC18/node-onvif

Fix crash when missing xml tags

mifi opened this issue ยท 0 comments

mifi commented

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch node-onvif@0.1.7 for the project I'm working on.

If Resolution OR RateControl is missing, node-onvif will crash. this fixed this. See also #37

The error message is Cannot read property width of undefined

Here is the diff that solved my problem:

diff --git a/node_modules/node-onvif/lib/modules/device.js b/node_modules/node-onvif/lib/modules/device.js
index 65ddf42..087d142 100644
--- a/node_modules/node-onvif/lib/modules/device.js
+++ b/node_modules/node-onvif/lib/modules/device.js
@@ -528,12 +528,12 @@ OnvifDevice.prototype._mediaGetProfiles = function () {
 						'token': p['VideoEncoderConfiguration']['$']['token'],
 						'name': p['VideoEncoderConfiguration']['Name'],
 						'resolution': {
-							'width': parseInt(p['VideoEncoderConfiguration']['Resolution']['Width'], 10),
-							'height': parseInt(p['VideoEncoderConfiguration']['Resolution']['Height'], 10),
+							'width': parseInt((p['VideoEncoderConfiguration']['Resolution'] || {})['Width'], 10),
+							'height': parseInt((p['VideoEncoderConfiguration']['Resolution'] || {})['Height'], 10),
 						},
 						'quality': parseInt(p['VideoEncoderConfiguration']['Quality'], 10),
-						'framerate': parseInt(p['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'], 10),
-						'bitrate': parseInt(p['VideoEncoderConfiguration']['RateControl']['BitrateLimit'], 10),
+						'framerate': parseInt((p['VideoEncoderConfiguration']['RateControl'] || {})['FrameRateLimit'], 10),
+						'bitrate': parseInt((p['VideoEncoderConfiguration']['RateControl'] || {})['BitrateLimit'], 10),
 						'encoding': p['VideoEncoderConfiguration']['Encoding']
 					};
 				}

This issue body was partially generated by patch-package.