-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[16.0][IMP] web_notify:t3894 Allow notify with sound #2923
Open
GabbasovDinar
wants to merge
1
commit into
OCA:16.0
Choose a base branch
from
cetmix:16.0-t3894-web_notify-sound-on-notification
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+281
−31
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* David Vidal | ||
|
||
* Cetmix OÜ <https://cetmix.com/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** @odoo-module alias=web_notify.AudioPlayer **/ | ||
|
||
import {Component, useState} from "@odoo/owl"; | ||
|
||
/** | ||
* @typedef AudioPlayerProps | ||
* @property {string} src URL of the audio file to be played | ||
* @property {number} [volume=1.0] Volume level of the audio (from 0.0 to 1.0) | ||
* @property {boolean} [loop=false] Whether the audio should loop | ||
* @property {Function} [onEnded] Callback function to be called when the audio ends | ||
*/ | ||
|
||
/** | ||
* The AudioPlayer component is responsible for playing audio files with | ||
* specified settings like volume and looping. It also provides the ability | ||
* to trigger actions when the audio playback ends. | ||
*/ | ||
export class AudioPlayer extends Component { | ||
setup() { | ||
this.state = useState({isPlaying: false}); | ||
this.audioElement = new Audio(this.props.src); | ||
|
||
// Set audio properties | ||
this.audioElement.volume = this.props.volume || 1.0; | ||
this.audioElement.loop = this.props.loop || false; | ||
|
||
// Start playing the audio | ||
this.audioElement | ||
.play() | ||
.then(() => { | ||
this.state.isPlaying = true; | ||
}) | ||
.catch((error) => { | ||
console.error("Audio playback failed:", error); | ||
}); | ||
|
||
// Listen for the end of the audio playback | ||
this.audioElement.addEventListener("ended", this.onAudioEnded.bind(this)); | ||
} | ||
|
||
/** | ||
* Stops the audio playback and triggers the onEnded callback if provided. | ||
*/ | ||
stopAudio() { | ||
this.audioElement.pause(); | ||
this.audioElement.currentTime = 0; | ||
this.state.isPlaying = false; | ||
|
||
if (this.props.onEnded) { | ||
this.props.onEnded(); | ||
} | ||
} | ||
|
||
/** | ||
* Handler for when the audio playback ends. | ||
*/ | ||
onAudioEnded() { | ||
if (!this.props.loop) { | ||
this.stopAudio(); | ||
} | ||
} | ||
|
||
willUnmount() { | ||
// Clean up the audio element and listeners | ||
this.audioElement.removeEventListener("ended", this.onAudioEnded); | ||
this.audioElement.pause(); | ||
} | ||
} | ||
|
||
AudioPlayer.template = "web_notify.AudioPlayer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright 2024 Cetmix OÜ | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="web_notify.AudioPlayer" owl="1"> | ||
<!-- No visual elements needed, audio is controlled programmatically --> | ||
</t> | ||
|
||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using a service like SoundEffects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chienandalu
this service is limited to predefined sound effect settings and does not allow you to specify a link to any sound. In my case, only the sound effect link is passed for playback, which allows any sound to be dynamically played back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean, you can take inspiration in that code to implement your own sound service, resulting in a simpler impletation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chienandalu I was already inspired by this effect to write the current solution :-)