Skip to content

Commit

Permalink
feat: api to set ringtone (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux authored Jun 19, 2024
1 parent 3584155 commit 022d1ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/Adapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions src/modules/Adapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 022d1ec

Please sign in to comment.