Skip to content

Instantly share code, notes, and snippets.

@kuschanton
Created June 10, 2022 12:13
Show Gist options
  • Save kuschanton/182c6f2d3187a4be56690e83ccc0b797 to your computer and use it in GitHub Desktop.
Save kuschanton/182c6f2d3187a4be56690e83ccc0b797 to your computer and use it in GitHub Desktop.
Twilio Flex: code snippet to be used in a Flex Plugin to make browser play ringtone when a task comes in
Flex.Manager.getInstance().workerClient.on('reservationCreated', (reservation: Reservation) => {
console.log('reservation', reservation)
let mediaId = Flex.AudioPlayerManager.play({
url: 'https://api.twilio.com/cowbell.mp3',
repeatable: true,
})
reservation.on('accepted', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('canceled', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('completed', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('rejected', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('rescinded', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('timeout', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('wrapup', () => Flex.AudioPlayerManager.stop(mediaId))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment