agsh / onvif

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

feat req: custom position in createOSD #311

Closed skords closed 1 week ago

skords commented 6 months ago

Requesting option to add custom position in createOSD method. This is already implemented in setOSD

/**
     * CreateOSD
     * ONVIF can handle custom positons, date/time, text, font sizes, transparency, images etc. We only support Plain Text
     * @param {Object} [options]
     * @param {string} [options.videoSourceConfigurationToken] Token of the Video Source Configuration, which has associated OSDs. Defaults to Active Source
     * @param {string} [options.plaintext] Text to overlay
     * @param {object|string} [options.position] String options: UpperLeft, UpperRight, LowerLeft or LowerRight. Default LowerLeft. Or an object with x and y position
     * @param {number} [options.position.x] x position of OSD, range: -1 to 1, counting from left to right
     * @param {number} [options.position.y] y position of OSD, range: -1 to 1, counting from up to down
     * @param {Cam~GetOSDOptionsCallback} callback
     */
    Cam.prototype.createOSD = function (options, callback) {
        if (callback === undefined) { callback = options; options = {}; }
        let mediaType = (this.media2Support ? 'media2' : 'media');
        let mediaNS = (this.media2Support ? 'http://www.onvif.org/ver20/media/wsdl' : 'http://www.onvif.org/ver10/media/wsdl');
        this._request({
            service: mediaType
            , body: this._envelopeHeader() +
                `<wsdl:CreateOSD xmlns:wsdl="${mediaNS}" xmlns:sch="http://www.onvif.org/ver10/schema">
         <wsdl:OSD token="">
            <sch:VideoSourceConfigurationToken>${(options.videoSourceConfiguationToken || this.activeSource.videoSourceConfigurationToken)}</sch:VideoSourceConfigurationToken>
            <sch:Type>Text</sch:Type>
            <sch:Position>
            <sch:Type>${typeof (options.position) === "object" ? "Custom" : (options.position ? options.position : "LowerLeft")}</sch:Type>
            ${typeof (options.position) === "object" ? ("<sch:Pos x=\"" + options.position.x + "\" y=\"" + options.position.y + "\"/>") : ""}
            </sch:Position>
            <sch:TextString IsPersistentText="false">
               <sch:Type>Plain</sch:Type>
               <sch:PlainText>${options.plaintext}</sch:PlainText>
            </sch:TextString>
         </wsdl:OSD>
      </wsdl:CreateOSD>` +

                this._envelopeFooter()
        }, function (err, data, xml) {
            if (callback) {
                callback.call(this, err, err ? null : linerase(data), xml);
            }
        }.bind(this));
    };
RotemDoar commented 2 weeks ago

This option added in the last version.