@@ -19,6 +19,7 @@ define([
19
19
sticky : false ,
20
20
play_sound : false
21
21
} ;
22
+ var audio_file = "./notify.mp3" ;
22
23
23
24
var current_time = function ( ) {
24
25
return new Date ( ) . getTime ( ) / 1000 ;
@@ -101,6 +102,23 @@ define([
101
102
}
102
103
} ;
103
104
105
+ var play_notification_sound = function ( opts ) {
106
+ /**
107
+ * NB: the Web Notification API specifies a mechanism for playing sound
108
+ * with notifications. As of 2017-08-22, it is unsupported in all browsers.
109
+ * This is a workaround. It should be updated to an implementation like
110
+ * this when browser support is available:
111
+ *
112
+ * opts["sound"] = require.toUrl(audio_file);
113
+ */
114
+ try {
115
+ var audio = new Audio ( require . toUrl ( audio_file ) ) ;
116
+ audio . play ( ) ;
117
+ } catch ( e ) {
118
+ console . log ( 'HTML5 Audio not supported in browser.' ) ;
119
+ }
120
+ } ;
121
+
104
122
var notify = function ( ) {
105
123
var elapsed_time = current_time ( ) - start_time ;
106
124
if ( enabled && ! first_start && ! busy_kernel && elapsed_time >= min_time ) {
@@ -109,8 +127,8 @@ define([
109
127
icon : Jupyter . notebook . base_url + "static/base/images/favicon.ico" ,
110
128
requireInteraction : params . sticky
111
129
} ;
112
- if ( params . sound ) {
113
- opts [ "sound" ] = require . toUrl ( "./notify.mp3" ) ;
130
+ if ( params . play_sound ) {
131
+ play_notification_sound ( opts ) ;
114
132
}
115
133
var n = new Notification ( Jupyter . notebook . notebook_name , opts ) ;
116
134
n . onclick = function ( event ) { window . focus ( ) ; }
0 commit comments