agsh / onvif

ONVIF node.js implementation
http://agsh.github.io/onvif/
MIT License
699 stars 240 forks source link

cam.getSnapshotUri() not working with public camera id #336

Open JooZef315 opened 6 days ago

JooZef315 commented 6 days ago

I am connecting to a camera with its public Ip as it is not on my local network,

      const cam = new Cam(
        {
          username: "xx",
          password: "xx",
          hostname: "x.x.x.x",
          port: x,
        },
        async function (err) {
          if (err) {
            console.error("Failed to connect to the camera:", err.message || err);
            return reject(new Error(`Connection failed: ${err.message || err}`));
          }         
          await cam.getSnapshotUri(
            { stream: "RTP-Multicast", protocol: "RTSP" },
            function (err, data) {
              console.log(data);
            }
          );
    }
  );

data returns { uri: undefined }

what did i miss? or isn't it possible to take a snapshot with that connection?

RogerHardiman commented 6 days ago

Spotted a few eroors in the code. a) You only need Stream (Multicast) and Protocol (RTSP) for Get StreamUri(). You do not need them for GetSnapshotUri

b) The await on getStreamuri does nothing. The library is a "function with callback" type of library, unless you pass the library through Promisify and then you can use await and would not have a callback. If you were trying to wait for it to finish, and then resolve a promise, you'd call resolve after console.log(data)

this may not explain why it fails though

JooZef315 commented 6 days ago

Spotted a few eroors in the code. a) You only need Stream (Multicast) and Protocol (RTSP) for Get StreamUri(). You do not need them for GetSnapshotUri

b) The await on getStreamuri does nothing. The library is a "function with callback" type of library, unless you pass the library through Promisify and then you can use await and would not have a callback. If you were trying to wait for it to finish, and then resolve a promise, you'd call resolve after console.log(data)

this may not explain why it fails though

thank you for replying @RogerHardiman,

refactored it to this, but still the same error

cam.getSnapshotUri(
{ profileToken: cam.activeSource.profileToken },
function (err, data) {
  console.log(data);
}
);