Skip to content

Commit 1492dcf

Browse files
author
Gia Thanh Vuong
committed
fix snapshot to use nat address
1 parent d7355ed commit 1492dcf

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

lib/modules/device.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,10 @@ OnvifDevice.prototype._mediaGetSnapshotUri = function() {
635635
this.services.media.getSnapshotUri(params, (error, result) => {
636636
if(!error) {
637637
try {
638-
profile['snapshot'] = result['data']['GetSnapshotUriResponse']['MediaUri']['Uri'];
639-
} catch(e) {}
638+
let snapshotUri = result['data']['GetSnapshotUriResponse']['MediaUri']['Uri'];
639+
snapshotUri = this._getSnapshotUri(snapshotUri);
640+
profile['snapshot'] = snapshotUri;
641+
} catch(e) { console.log(e);}
640642
}
641643
profile_index ++;
642644
getSnapshotUri();
@@ -668,4 +670,17 @@ OnvifDevice.prototype._getUri = function(directUri) {
668670
return newUri;
669671
}
670672

673+
OnvifDevice.prototype._getSnapshotUri = function(directUri) {
674+
if (!this.keepAddr) return directUri;
675+
const base = mUrl.parse('http://' + this.address);
676+
const parts = mUrl.parse(directUri);
677+
const newParts = {
678+
protocol: parts.protocol,
679+
host: base.host,
680+
pathname: base.pathname + parts.pathname
681+
};
682+
const newUri = mUrl.format(newParts);
683+
return newUri;
684+
}
685+
671686
module.exports = OnvifDevice;

0 commit comments

Comments
 (0)