每当有新来电时,我都在寻找播放声音
问问题
181 次
1 回答
3
https://www.twilio.com/docs/flex/developer/ui/sound-and-audio上的Twilio 文档不清楚,所以我从https://support.twilio.com/hc/en-us/articles/撤下了360010784433-How-Do-You-Make-the-Browser-Ring-When-a-Flex-Call-Comes-In-。这是一个准系统 Flex UI 插件:
import { FlexPlugin } from "flex-plugin";
export default class MyPlugin extends FlexPlugin {
constructor() {
super("MyPlugin");
}
init(flex, manager) {
const alertSound = new Audio(
"https://public-path-to-your-audio.mp3"
);
alertSound.loop = true;
const resStatus = [
"accepted",
"canceled",
"rejected",
"rescinded",
"timeout",
];
manager.workerClient.on(
"reservationCreated",
function (reservation) {
if (reservation.task.taskChannelUniqueName === "voice" && reservation.task.attributes.direction === 'inbound') {
alertSound.play();
}
resStatus.forEach((e) => {
reservation.on(e, () => {
alertSound.pause();
});
});
}
);
}
}
于 2021-05-25T04:56:17.077 回答