From bf85703f4b2dbcb3be4da87f32ccf7e6d62a7975 Mon Sep 17 00:00:00 2001 From: Jessy Date: Fri, 21 Feb 2020 11:49:56 +0100 Subject: [PATCH] Add new requests to add/remove configurations to/from profiles. Add tests. --- lib/media.js | 180 +++++++++++++++++- test/media.coffee | 49 ++++- .../media.AddAudioEncoderConfiguration.xml | 5 + .../media.AddAudioSourceConfiguration.xml | 5 + .../media.AddVideoEncoderConfiguration.xml | 5 + .../media.AddVideoSourceConfiguration.xml | 5 + .../media.RemoveAudioEncoderConfiguration.xml | 5 + .../media.RemoveAudioSourceConfiguration.xml | 5 + 8 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 test/serverMockup/media.AddAudioEncoderConfiguration.xml create mode 100644 test/serverMockup/media.AddAudioSourceConfiguration.xml create mode 100644 test/serverMockup/media.AddVideoEncoderConfiguration.xml create mode 100644 test/serverMockup/media.AddVideoSourceConfiguration.xml create mode 100644 test/serverMockup/media.RemoveAudioEncoderConfiguration.xml create mode 100644 test/serverMockup/media.RemoveAudioSourceConfiguration.xml diff --git a/lib/media.js b/lib/media.js index 70ca4d93..08d667df 100644 --- a/lib/media.js +++ b/lib/media.js @@ -687,7 +687,185 @@ module.exports = function(Cam) { }.bind(this)); }; - // TODO AddVideoEncoderConfiguration + /** + * @callback Cam~AddAudioEncoderConfigurationCallback + * @property {?Error} error + * @property {null} + * @property {string} xml Raw XML response + */ + + /** + * This operation adds an AudioEncoderConfiguration to an existing media profile. If a configuration exists in the media profile, it will be replaced. The change shall be persistent. A device shall support adding a compatible AudioEncoderConfiguration to a profile containing an AudioSourceConfiguration and shall support streaming audio data of such a profile. + * @param {object} options + * @param {string} options.profileToken Reference to the profile where the configuration should be added + * @param {string} options.configurationToken Contains a reference to the AudioSourceConfiguration to add + * @param {Cam~AddAudioEncoderConfigurationCallback} callback + */ + Cam.prototype.addAudioEncoderConfiguration = function(options,callback) { + let body = this._envelopeHeader() + + '' + + '' + options.profileToken + '' + + '' + options.configurationToken + '' + + '' + + this._envelopeFooter(); + this._request({ + service: 'media', + body: body, + }, function(err, data, xml) { + if (callback) { + callback.call(this, err, null, xml); + } + }.bind(this)); + }; + + /** + * @callback Cam~AddAudioSourceConfigurationCallback + * @property {?Error} error + * @property {null} + * @property {string} xml Raw XML response + */ + + /** + * This operation adds an AudioSourceConfiguration to an existing media profile. If a configuration exists in the media profile, it will be replaced. The change shall be persistent. + * @param {object} options + * @param {string} options.profileToken Reference to the profile where the configuration should be added + * @param {string} options.configurationToken Contains a reference to the AudioSourceConfiguration to add + * @param {Cam~AddAudioSourceConfigurationCallback} callback + */ + Cam.prototype.addAudioSourceConfiguration = function(options,callback) { + let body = this._envelopeHeader() + + '' + + '' + options.profileToken + '' + + '' + options.configurationToken + '' + + '' + + this._envelopeFooter(); + this._request({ + service: 'media', + body: body, + }, function(err, data, xml) { + if (callback) { + callback.call(this, err, null, xml); + } + }.bind(this)); + }; + + /** + * @callback Cam~AddVideoEncoderConfigurationCallback + * @property {?Error} error + * @property {null} + * @property {string} xml Raw XML response + */ + + /** + * This operation adds a VideoEncoderConfiguration to an existing media profile. If a configuration exists in the media profile, it will be replaced. The change shall be persistent. A device shall support adding a compatible VideoEncoderConfiguration to a Profile containing a VideoSourceConfiguration and shall support streaming video data of such a profile. + * @param {object} options + * @param {string} options.profileToken Reference to the profile where the configuration should be added + * @param {string} options.configurationToken Contains a reference to the VideoEncoderConfiguration to add + * @param {Cam~AddVideoEncoderConfigurationCallback} callback + */ + Cam.prototype.addVideoEncoderConfiguration = function(options,callback) { + let body = this._envelopeHeader() + + '' + + '' + options.profileToken + '' + + '' + options.configurationToken + '' + + '' + + this._envelopeFooter(); + this._request({ + service: 'media', + body: body, + }, function(err, data, xml) { + if (callback) { + callback.call(this, err, null, xml); + } + }.bind(this)); + }; + + /** + * @callback Cam~AddVideoSourceConfigurationCallback + * @property {?Error} error + * @property {null} + * @property {string} xml Raw XML response + */ + + /** + * This operation adds a VideoSourceConfiguration to an existing media profile. If such a configuration exists in the media profile, it will be replaced. The change shall be persistent. + * @param {object} options + * @param {string} options.profileToken Reference to the profile where the configuration should be added + * @param {string} options.configurationToken Contains a reference to the VideoSourceConfiguration to add + * @param {Cam~AddVideoSourceConfigurationCallback} callback + */ + Cam.prototype.addVideoSourceConfiguration = function(options,callback) { + let body = this._envelopeHeader() + + '' + + '' + options.profileToken + '' + + '' + options.configurationToken + '' + + '' + + this._envelopeFooter(); + this._request({ + service: 'media', + body: body, + }, function(err, data, xml) { + if (callback) { + callback.call(this, err, null, xml); + } + }.bind(this)); + }; + + /** + * @callback Cam~RemoveAudioEncoderConfigurationCallback + * @property {?Error} error + * @property {null} + * @property {string} xml Raw XML response + */ + + /** + * This operation removes an AudioEncoderConfiguration from an existing media profile. If the media profile does not contain an AudioEncoderConfiguration, the operation has no effect. The removal shall be persistent. + * @param {string} profileToken Contains a reference to the media profile from which the AudioEncoderConfiguration shall be removed. + * @param {Cam~RemoveAudioEncoderConfigurationCallback} callback + */ + Cam.prototype.removeAudioEncoderConfiguration = function(profileToken,callback) { + let body = this._envelopeHeader() + + '' + + '' + profileToken + '' + + '' + + this._envelopeFooter(); + this._request({ + service: 'media', + body: body, + }, function(err, data, xml) { + if (callback) { + callback.call(this, err, null, xml); + } + }.bind(this)); + }; + + /** + * @callback Cam~RemoveAudioSourceConfigurationCallback + * @property {?Error} error + * @property {null} + * @property {string} xml Raw XML response + */ + + /** + * This operation removes an AudioSourceConfiguration from an existing media profile. If the media profile does not contain an AudioSourceConfiguration, the operation has no effect. The removal shall be persistent. Audio source configurations should only be removed after removing an AudioEncoderConfiguration from the media profile. + * @param {string} profileToken Contains a reference to the media profile from which the AudioOutputConfiguration shall be removed. + * @param {Cam~RemoveAudioSourceConfigurationCallback} callback + */ + Cam.prototype.removeAudioSourceConfiguration = function(profileToken,callback) { + let body = this._envelopeHeader() + + '' + + '' + profileToken + '' + + '' + + this._envelopeFooter(); + this._request({ + service: 'media', + body: body, + }, function(err, data, xml) { + if (callback) { + callback.call(this, err, null, xml); + } + }.bind(this)); + }; /* Cam.prototype.getVideoEncoderConfigurationOptions = function(options, callback) { diff --git a/test/media.coffee b/test/media.coffee index 5a10acb6..ad20b998 100644 --- a/test/media.coffee +++ b/test/media.coffee @@ -209,4 +209,51 @@ describe 'Media', () -> assert.ok ['name', '$', 'multicast'].every (prop) -> !!res[prop] done() - \ No newline at end of file + + describe 'addAudioEncoderConfiguration', () -> + it 'should add an AudioEncoderConfiguration to a Profile', (done) -> + cam.addAudioEncoderConfiguration { + profileToken: 'profileToken', + configurationToken: 'configurationToken', + }, (err, res) -> + assert.equal err, null + done() + + describe 'addAudioSourceConfiguration', () -> + it 'should add an AudioSourceConfiguration to a Profile', (done) -> + cam.addAudioSourceConfiguration { + profileToken: 'profileToken', + configurationToken: 'configurationToken', + }, (err, res) -> + assert.equal err, null + done() + + describe 'addVideoEncoderConfiguration', () -> + it 'should add a VideoEncoderConfiguration to a Profile', (done) -> + cam.addVideoEncoderConfiguration { + profileToken: 'profileToken', + configurationToken: 'configurationToken', + }, (err, res) -> + assert.equal err, null + done() + + describe 'addVideoSourceConfiguration', () -> + it 'should add a VideoSourceConfiguration to a Profile', (done) -> + cam.addVideoSourceConfiguration { + profileToken: 'profileToken', + configurationToken: 'configurationToken', + }, (err, res) -> + assert.equal err, null + done() + + describe 'removeAudioEncoderConfiguration', () -> + it 'should remove an AudioEncoderConfiguration from a Profile', (done) -> + cam.removeAudioEncoderConfiguration 'profileToken', (err, res) -> + assert.equal err, null + done() + + describe 'removeAudioSourceConfiguration', () -> + it 'should remove an AudioSourceConfiguration from a Profile', (done) -> + cam.removeAudioSourceConfiguration 'profileToken', (err, res) -> + assert.equal err, null + done() diff --git a/test/serverMockup/media.AddAudioEncoderConfiguration.xml b/test/serverMockup/media.AddAudioEncoderConfiguration.xml new file mode 100644 index 00000000..4d8641d5 --- /dev/null +++ b/test/serverMockup/media.AddAudioEncoderConfiguration.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/serverMockup/media.AddAudioSourceConfiguration.xml b/test/serverMockup/media.AddAudioSourceConfiguration.xml new file mode 100644 index 00000000..13be1dfd --- /dev/null +++ b/test/serverMockup/media.AddAudioSourceConfiguration.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/serverMockup/media.AddVideoEncoderConfiguration.xml b/test/serverMockup/media.AddVideoEncoderConfiguration.xml new file mode 100644 index 00000000..5a5b8c26 --- /dev/null +++ b/test/serverMockup/media.AddVideoEncoderConfiguration.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/serverMockup/media.AddVideoSourceConfiguration.xml b/test/serverMockup/media.AddVideoSourceConfiguration.xml new file mode 100644 index 00000000..43321853 --- /dev/null +++ b/test/serverMockup/media.AddVideoSourceConfiguration.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/serverMockup/media.RemoveAudioEncoderConfiguration.xml b/test/serverMockup/media.RemoveAudioEncoderConfiguration.xml new file mode 100644 index 00000000..ea6bd1aa --- /dev/null +++ b/test/serverMockup/media.RemoveAudioEncoderConfiguration.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/serverMockup/media.RemoveAudioSourceConfiguration.xml b/test/serverMockup/media.RemoveAudioSourceConfiguration.xml new file mode 100644 index 00000000..cfd76a3d --- /dev/null +++ b/test/serverMockup/media.RemoveAudioSourceConfiguration.xml @@ -0,0 +1,5 @@ + + + + +