Support custom sound files for Web Notifications

NEW
Unassigned

Status

()

4 years ago
5 months ago

People

(Reporter: mikedeboer, Unassigned)

Tracking

(Depends on: 4 bugs, {meta})

unspecified
Points:
---
Dependency tree / graph
Bug Flags:
firefox-backlog +
qe-verify +

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(1 attachment)

(Reporter)

Description

4 years ago
DOM Web Notifications in Gecko sports a NotificationBehavior dictionary, which allow to specify a custom sound file to be played when the Notification is triggered.

See https://mxr.mozilla.org/mozilla-central/source/dom/webidl/Notification.webidl?rev=9712d6370c3f&mark=65,72,75#58 for the IDL definition.
Please note that this is out of date with the current state of the WHATWG spec at http://notifications.spec.whatwg.org/. We're using a proprietary `mozbehavior` object to specify sound and vibration pattern for B2G/ Gaia.

Example:
```js
new Notification("title", {
  mozbehavior: {
    soundFile: "chrome://url/to/soundFile.ogg"
  }
});
```

As such, this works for FirefoxOS, but not on the major desktop platforms.

This bug tracks that work.
Flags: qe-verify+
Flags: firefox-backlog+
(Reporter)

Updated

4 years ago
Depends on: 1105225
(Reporter)

Updated

4 years ago
Depends on: 1105226
(Reporter)

Updated

4 years ago
Depends on: 1105229
(Reporter)

Updated

4 years ago
Depends on: 1105230
Component: Widget → Notifications and Alerts
Product: Core → Toolkit
(Reporter)

Comment 1

4 years ago
:karlt actually proposed an awesome alternative in https://bugzilla.mozilla.org/show_bug.cgi?id=1105230#c1...

For ease of implementation, I suggest to support _not_ playing a sound - which all desktop notification agents support - at first, so that Notification API consumers can start with playing a sound of their own via the <audio> element.

How does that 'sound'? (no pun intended ;) )
(Reporter)

Comment 2

4 years ago
Created attachment 8542946 [details] [diff] [review]
WIP patch

This patch does the following:

1) adds an optional `sound` String argument to the `showAlertNotification` function for nsIAlertService.
2) Supports passing sound names to OSX Notification Manager to allow playing built-in sounds or the 'default' one.
3) Implements the behavior in Notification.cpp to see if the sound passed along with `mozBehavior.soundFile` contains a file that might be playable by the <audio> element.
  a) Tries to play the sound using a HTMLAudioElement instance, which crashes the browser atm. Dunno why, my skill is limited here atm.
  b) If no file is detected, pass the raw string to the alert service OS implementation. It may play a built-in sound.
  c) Pass the ASCII string 'default' to the alert service and let OS specific implementation fall back to its default behavior.
This is standardized, so we should use that API rather than invent a proprietary method: https://notifications.spec.whatwg.org/#sound-url
You need to log in before you can comment on or make changes to this bug.