Skip to content

Commit bdfb9db

Browse files
mauricetmeyerozdemirburak
authored andcommitted
Fixed a few issues created by the ES6 merge. (#9)
1 parent e5d8a70 commit bdfb9db

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/morsify.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@
191191
}).join(' ').replace(/\s+/g, ' ');
192192
};
193193

194+
const AudioContext = window.AudioContext || window.webkitAudioContext;
195+
const context = new AudioContext();
194196
const audio = (text, opts) => {
195197
const options = getOptions(opts);
196198
const morse = encode(text, opts);
197-
const AudioContext = window.AudioContext || window.webkitAudioContext;
198-
const context = new AudioContext();
199199
const oscillator = context.createOscillator();
200200
const gainNode = context.createGain();
201201
let timeout;
@@ -234,16 +234,21 @@
234234
oscillator.connect(gainNode);
235235
gainNode.connect(context.destination);
236236

237+
238+
const play = () => {
239+
oscillator.start(context.currentTime);
240+
timeout = setTimeout(() => stop(), (t - context.currentTime) * 1000);
241+
};
242+
243+
const stop = () => {
244+
clearTimeout(timeout);
245+
timeout = 0;
246+
oscillator.stop(0);
247+
};
248+
237249
return {
238-
play: () => {
239-
oscillator.start(context.currentTime);
240-
timeout = setTimeout(this.stop.bind(this), (t - context.currentTime) * 1000);
241-
},
242-
stop: () => {
243-
clearTimeout(timeout);
244-
timeout = 0;
245-
oscillator.stop(0);
246-
},
250+
play,
251+
stop,
247252
context,
248253
oscillator,
249254
gainNode

0 commit comments

Comments
 (0)