diff --git a/src/lib/Adapter/index.js b/src/lib/Adapter/index.js index 6fc848736..229145722 100644 --- a/src/lib/Adapter/index.js +++ b/src/lib/Adapter/index.js @@ -674,6 +674,19 @@ class Adapter extends AdapterCore { }); } + updateRingtone({ + name, + uri, + volume, + }) { + this._postMessage({ + type: 'rc-adapter-update-ringtone', + name, + uri, + volume, + }); + } + get showCurrentCallBtn() { return this._widgetCurrentPath.indexOf('/calls/active') === -1 && this.showDuration; } diff --git a/src/modules/Adapter/index.js b/src/modules/Adapter/index.js index 023bdc37a..2876fa95e 100644 --- a/src/modules/Adapter/index.js +++ b/src/modules/Adapter/index.js @@ -336,6 +336,10 @@ export default class Adapter extends AdapterModuleCore { this._syncWebphoneSessions(); break; } + case 'rc-adapter-update-ringtone': { + this._updateRingtone(data); + break; + } default: super._onMessage(data); break; @@ -1097,6 +1101,27 @@ export default class Adapter extends AdapterModuleCore { }); } + async _updateRingtone({ name, uri, volume }) { + if (typeof volume === 'number' && volume >= 0 && volume <= 1) { + this._audioSettings.setData({ ringtoneVolume: volume }); + } + if (typeof name === 'string' && typeof uri === 'string') { + if ( + uri.indexOf('https://') !== 0 && + uri.indexOf('http://') !== 0 && + uri.indexOf('data:audio/') !== 0 + ) { + return; + } + this._webphone.setRingtone({ + incomingAudio: uri, + incomingAudioFile: name, + outgoingAudio: this._webphone.defaultOutgoingAudio, + outgoingAudioFile: this._webphone.defaultOutgoingAudioFile, + }); + } + } + // eslint-disable-next-line _postMessage(data) { if (window && window.parent) {