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

TypeError: Cannot read property 'Width' of undefined #37

Open
jarridgraham opened this issue Jul 19, 2018 · 3 comments
Open

TypeError: Cannot read property 'Width' of undefined #37

jarridgraham opened this issue Jul 19, 2018 · 3 comments

Comments

@jarridgraham
Copy link

Using this example code below and of course changing the IP and login info

const onvif = require('node-onvif');

// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
  xaddr: 'http://192.168.10.10:80/onvif/device_service',
  user : 'admin',
  pass : '123456'
});

// Initialize the OnvifDevice object
device.init().then((info) => {
  // Show the detailed information of the device.
  console.log(JSON.stringify(info, null, '  '));
}).catch((error) => {
  console.error(error);
});

I get the folowing response from a camera

The OnvifDevice object has been initialized successfully.
{
  "Manufacturer": "Honeywell",
  "Model": "H4D2F",
  "FirmwareVersion": "42.0.7",
  "SerialNumber": "00000",
  "HardwareId": "DM368"
}

when I try with a newer version of the camera I get this

Error: Failed to initialize the device: TypeError: Cannot read property 'Width' of undefined
    at services.media.getProfiles (/home/user/node_modules/node-onvif/lib/modules/device.js:464:12)
    at promise.then.catch (/home/user/node_modules/node-onvif/lib/modules/service-media.js:392:4)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

I was wondering what info might be needed to help this issue.

Thanks

@futomi
Copy link
Collaborator

futomi commented Aug 14, 2018

Thank you for your feedback. Sorry my reply is late.

The Honeywell H4D2F is not available in Japan where I live. So I could not investigate this issue.

I added the lastResponse property to the OnvifDevice object for debug. Could you install the latest version of the node-onvif, try the code below, and let me know the output?

const onvif = require('node-onvif');

// Create an OnvifDevice object
let device = new onvif.OnvifDevice({
  xaddr: 'http://192.168.10.10:80/onvif/device_service',
  user : 'admin',
  pass : '123456'
});

// Initialize the OnvifDevice object
device.init().then((info) => {
  console.log(JSON.stringify(info, null, '  '));
}).catch((error) => {
  console.error(error);
  console.log('-----------------------------------');
  console.log(JSON.stringify(device.lastResponse, null, '  '));
  console.log('-----------------------------------');
});

@DJWoodZ
Copy link

DJWoodZ commented Sep 11, 2018

I believe this issue is in this line: https://github.com/futomi/node-onvif/blob/master/lib/modules/device.js#L531 when a device returns a VideoEncoderConfiguration without a Resolution property. A similar issue can happen when there isn't a RateControl property.

If I update the lines in /lib/modules/device.js that attempt to access the Resolution and RateControl properties to substitute undefined for an empty object ({}), it seems to work for my device:

  • p['VideoEncoderConfiguration']['Resolution'] -> (p['VideoEncoderConfiguration']['Resolution'] || {})
  • p['VideoEncoderConfiguration']['RateControl'] -> (p['VideoEncoderConfiguration']['RateControl'] || {})

Complete example:

if (p['VideoEncoderConfiguration']) {
	profile['video']['encoder'] = {
		'token': p['VideoEncoderConfiguration']['$']['token'],
		'name': p['VideoEncoderConfiguration']['Name'],
		'resolution': {
			'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),
		'encoding': p['VideoEncoderConfiguration']['Encoding']
	};
}

@csplkiller
Copy link

I also faced this problem, but this fix works. Thank you. Camera IMOU Bullet 4MP !

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

4 participants