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

name space handling (xmlns:) #38

Open
peebles opened this issue Aug 6, 2018 · 7 comments
Open

name space handling (xmlns:) #38

peebles opened this issue Aug 6, 2018 · 7 comments

Comments

@peebles
Copy link

peebles commented Aug 6, 2018

I think this library suffers from the same problem that onvif had; namely that when the camera is sending xmlns: name spaces with all of its elements, the xml to json parser is not doing the right thing. My camera outputs something like this:

<tt:Uri xmlns:tt="http://www.onvif.org/ver10/schema">http://169.254.72.162:8081/web/snapshot.jpg</tt:Uri>

Which produces json that looks like this:

    "snapshot": {
      "_": "http://169.254.72.162:8081/web/snapshot.jpg",
      "$": {
        "xmlns:tt": "http://www.onvif.org/ver10/schema"
      }
    },

If I apply the same "fix" as described in the linked ticket, namely:

soap = soap.replace(/xmlns(.*?)=(".*?")/g,'');
mXml2Js.parseString(soap, opts, (error, result) => {
...
});

in lib/modules/soap.js::parse(), then the problem goes away and I get this json:

    "snapshot": "http://169.254.72.162:8081/web/snapshot.jpg",

I realize this is just how xml2js works, but higher level apps (like samples/manager) break when the camera is sending xmlns:

@peebles
Copy link
Author

peebles commented Aug 7, 2018

In soap.js, the current code looks like:

OnvifSoap.prototype.parse = function(soap) {
        let promise = new Promise((resolve, reject) => {
                let opts = {
                        'explicitRoot'     : false,
                        'explicitArray'    : false,
                        //'ignoreAttrs'      : true,
                        'ignoreAttrs'      : false,
                        'tagNameProcessors': [function(name) {
                                let m = name.match(/^([^\:]+)\:([^\:]+)$/);
                                return (m ? m[2] : name);
                        }]
                };
          mXml2Js.parseString(soap, opts, (error, result) => {

If you change 'ignoreAttrs' back to true, then this problem with $ and _ goes away. I wonder why the value was changed ...

@futomi
Copy link
Collaborator

futomi commented Aug 7, 2018

Thank you for your feedback.

I've suspected the explicitArray parameter for now though I'm not sure. Anyway, I think that the parameter causes some issues.

I'm planning to change the explicitArray from false to true. But changing the value has a much greater impact on other codes. That will take a little bit long time.

Unfortunately, I don't have enough time for this project now. Give me some time.

@futomi
Copy link
Collaborator

futomi commented Aug 13, 2018

I misunderstood this issue. Now I understand what is problem.

As you advised, it seems that the xml2js returns different results depends on where a namespace (xmlns) are described in a XML. The node-onvif does not handle the behavior of the xml2js for now.

If you don't mind my asking, could you give me the manufacturer name and the model name of the network camera you have? If it is affordable and available in Japan (where I live), I will buy and try it.

@peebles
Copy link
Author

peebles commented Aug 13, 2018

I built it myself, using: https://github.com/BreeeZe/rpos

@peebles
Copy link
Author

peebles commented Aug 13, 2018

I should note that Open Device Manager Windows and Linux as well as a commercial vendor onvif client can see this camera and manipulate it.

@futomi
Copy link
Collaborator

futomi commented Aug 13, 2018

Wow, you built it by yourself! Great! I'll try it soon.

@futomi
Copy link
Collaborator

futomi commented Aug 13, 2018

I installed the rpos on my Raspberry Pi 3 Model B+ with a camera module v2. It worked fine though I don't have the PiMoroni PanTiltHAT.

You advised a solution:

soap = soap.replace(/xmlns(.*?)=(".*?")/g,'');
mXml2Js.parseString(soap, opts, (error, result) => {
...
});

This solution would solve this issue comprehensively, but all namespace information would be removed from responses of the low-level methods. Some users might expect that namespace information is included in a response. So I focused only on the high-level methods.

I improved the OnvifDevice.getUdpStreamUrl() and the OnvifDevice.fetchSnapshot() method. Now these methods work well with the rpos.

Thank you.

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

2 participants