You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Falsy Values Incorrectly Evaluated in Option Checks #354
I've encountered an issue in multiple functions where certain properties in the options object are checked using a simple if (options.someProp). This causes problems when someProp is a number and equal to 0, as it is treated as false, even though 0 is a valid value.
For example, with Axis cameras, the token of a video encoder can be 0. When calling setVideoEncoderConfiguration, I receive an incorrect response stating that the token is mandatory, even though I provided it. The same issue occurs with other parameters, such as bitrate.
Would it be possible to update these checks to properly handle 0 as a valid value? I’m happy to create a PR, but the fix will require multiple changes across media.js. If you're open to it, I can proceed with the PR.
@momoAmch hello!
Oh... media.js.. my headache... Written a long-long time ago in ECMAScript5 and not enough tested yet. Right now I'm rewriting it in the typescript and still make this stupid mistake (
But this is of course not a solution. So I'm glad you want to do a PR. I'll be happy to review it 👍
Seem that this regex covers quite a lot of this falsy cases (45 in media.js): options.[\S\)]+[\n\s]*\?
I'd be happy to look at a PR for the 'falsy' stuff.
I've also got 4 Axis cameras in my collection of IP cameras (plus Bosch, Avigion, Hanwha, Sony) etc so can do some tests too.
I'm just catching up on a year of agsh/onvif posts.
Activity
agsh commentedon Apr 9, 2025
@momoAmch hello!
Oh... media.js.. my headache... Written a long-long time ago in ECMAScript5 and not enough tested yet. Right now I'm rewriting it in the typescript and still make this stupid mistake (
onvif/src/media.ts
Line 207 in cae5606
I can offer you a temporary solution to replace a number as value to string when passing options to methods:
But this is of course not a solution. So I'm glad you want to do a PR. I'll be happy to review it 👍
Seem that this regex covers quite a lot of this falsy cases (45 in media.js):
options.[\S\)]+[\n\s]*\?RogerHardiman commentedon Nov 10, 2025
I'd be happy to look at a PR for the 'falsy' stuff.
I've also got 4 Axis cameras in my collection of IP cameras (plus Bosch, Avigion, Hanwha, Sony) etc so can do some tests too.
I'm just catching up on a year of agsh/onvif posts.