patrickmichalina / onvif-rx

📹 Communicate with ONVIF devices and cameras in server and browser environments.
MIT License
23 stars 11 forks source link

Optional Parameters #45

Closed Mudrekh closed 3 years ago

Mudrekh commented 3 years ago

Hi @patrickmichalina,

I was messing around with your library and ran into an issue with optional parameters, specifically using Media.GetVideoEncoderConfigurationOptions. Originally, I could only get the function to complete by specifying both parameters, but it seems based on the specification that I should be able to use the function without needing to supply the params to get 'generic' configuration options for the device.

After some digging, it seems like the issue can be traced to function. When passed no parameters in the calling function, the resulting object passed to this function is something like

{ 
  trt_ConfigurationToken: undefined,
  trt_ProfileToken: undefined 
}

which causes the function to throw an error at Object.keys later in the recursive chain when evaluating undefined. I believe the problem can be solved by replacing the line with return params ? reducer(params)(reqNode)() : ''. However, I am not to familiar with typescipt as well as the other effects this may have in the library. Does this seem correct? Another option would be to add a line like if (!obj[key]) return acc; before this line

The resulting strings w/params and without params after making this change:

<trt:GetVideoSourceConfigurationOptions><trt:ProfileToken>recording</trt:ProfileToken><trt:ConfigurationToken>0</trt:ConfigurationToken></trt:GetVideoSourceConfigurationOptions>

<trt:GetVideoSourceConfigurationOptions></trt:GetVideoSourceConfigurationOptions>

which my device correctly interprets.

patrickmichalina commented 3 years ago

Thanks I'll try to take a look. It's been some time since working on this and due for some updates. ;)

patrickmichalina commented 3 years ago

Thanks for the code