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

Fix crash when missing xml tags #88

Open
mifi opened this issue Jun 22, 2022 · 0 comments
Open

Fix crash when missing xml tags #88

mifi opened this issue Jun 22, 2022 · 0 comments

Comments

@mifi
Copy link

mifi commented Jun 22, 2022

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant