Skip to content

Commit

Permalink
Merge pull request #31 from theRichu/patch-1
Browse files Browse the repository at this point in the history
Solve EventEmitter leakage problem by replace `fn.on` by `fn.once`
  • Loading branch information
guo-yu committed Feb 5, 2015
2 parents 12890f9 + 1e7a90d commit 52076fd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libs/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function play(done, selected) {
var self = this;

if (done !== 'next')
this.on('done', _.isFunction(done) ? done : errHandler);
this.once('done', _.isFunction(done) ? done : errHandler);

if (this.list.length <= 0)
return false;
Expand All @@ -86,8 +86,8 @@ function play(done, selected) {

pool
.pipe(new lame.Decoder())
.on('format', onPlaying)
.on('finish', onFinished);
.once('format', onPlaying)
.once('finish', onFinished);

function onPlaying(f) {
var speaker = new Speaker(f);
Expand All @@ -100,7 +100,7 @@ function play(done, selected) {
// This is where the song acturaly played end,
// can't trigger playend event here cause
// unpipe will fire this speaker's close event.
this.pipe(speaker).on('close', function() {
this.pipe(speaker).once('close', function() {
self.emit('stopped', song);
});
}
Expand Down Expand Up @@ -141,7 +141,7 @@ function download(src, callback) {

request
.get(query, responseHandler)
.on('error', errorHandler);
.once('error', errorHandler);

function responseHandler(res){
called = true;
Expand Down Expand Up @@ -280,7 +280,7 @@ function addSong(song) {
*/
function bindEvents() {
var self = this;
this.on('playing', function(song) {
this.once('playing', function(song) {
self.playing = song;
self.history.push(song);
});
Expand Down

0 comments on commit 52076fd

Please sign in to comment.