agsh / onvif

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

GetVideoOutputs not supported #250

Open quanminh5030 opened 1 year ago

quanminh5030 commented 1 year ago

Hi! I am trying to get all the available video output like the one attached below (from onvif - GetVideoOutputs). I have been trying all the methods but seems like none of them support it yet. Can you help me if I have missed st?

Link to the method: http://www.onvif.org/onvif/ver10/deviceio.wsdl#op.GetVideoOutputs

Screenshot from 2022-10-10 11-56-39

agsh commented 1 year ago

@quanminh5030 Hi! Yes, this method is not implemented yet. You can implement it by yourself, basing on a similar method getVideoSources as an example: https://github.com/agsh/onvif/blob/master/lib/media.js#L30 Something like this:

    /**
     * List all available video outputs of a device. A device that has one or more physical video outputs shall support listing of available video outputs through the GetVideoOutputs command
     * @param {Cam~GetVideoOutputsCallback} [callback]
     */
    Cam.prototype.getVideoOutputs = function(callback) {
        this._request({
            service: 'media'
            , body: this._envelopeHeader() +
            '<GetVideoOutputs xmlns="http://www.onvif.org/ver10/media/wsdl"/>' +
            this._envelopeFooter()
        }, function(err, data, xml) {
            if (!err) {
                /**
                 * Video outputs
                 * @name Cam#videoOutputs
                 * @type {Array.<Cam~VideoOutput>}
                 */
                this.videoOutputs = linerase(data).getVideoSourcesResponse.videoOutputs;
                if (!Array.isArray(this.videoOutputs)) {this.videoOutputs = [this.videoOutputs];}
            }
            if (callback) {
                callback.call(this, err, this.videoOutputs, xml);
            }
        }.bind(this));
    };

Don't forget to add jsdoc typedef for other users. Smth like this:

    /**
     * @typedef {Object} Cam~VideoOutput
     * @property {Object} layout
     * @property {Object} layout.paneLayout
     * @property {Object} extension
     * @property {Object} [resolution]
     * @property {number} resolution.width
     * @property {number} resolution.height
     * @property {Object} [refreshRate]
     * @property {Object} [spectRatio]
     * @property {Object} [extension]
     */

    /**
     * @callback Cam~GetVideoSourcesCallback
     * @property {?Error} error
     * @property {Cam~VideoSource|Array.<Cam~VideoSource>} videoSources
     * @property {string} xml Raw SOAP response
     */

Then add the sample XML returned from your device with this request. The simplest way is to execute it and add third argument to the callback function:

cam.getVideoOutputs((err, outputs, xml) => console.log(xml));

And add this XML response to the examples for the tests here: https://github.com/agsh/onvif/tree/master/test/serverMockup And the last step is to write some tests :smiley: This link is for getVideoSources test suite, you can base on it like an example: https://github.com/agsh/onvif/blob/master/test/common.js#L331 And don't forget to make a PR here :)

Or... just send me the returned XML from you device, I'll do it by myself when I have some free time :smile_cat:

RogerHardiman commented 1 year ago

I'm interested in GetVideoOutputs.

I've not seen anyone implement video output with an ONVIF API before. I've used lots of Decoder Codecs from Bosch and Axis, but never checked if they had an ONVIF API for this.

Could I ask which device you are connecting to please?