Skip to content

Commit

Permalink
Add beforeDestroy method and close audio context.
Browse files Browse the repository at this point in the history
Idea from @SohrabZ, issue #2
  • Loading branch information
Stas Kobzar committed May 16, 2018
1 parent 20f6b04 commit 4f8dcd4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/AvBars.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const AvBars = {
audio: null,
analyser: null,
ctx: null,
audioCtx: null,
caps: Array.apply(null, Array(this.fftSize / 2)).map(() => 0)
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/components/AvBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ const methods = {
src.connect(this.analyser)
this.analyser.fftSize = this.fftSize
this.analyser.connect(ctx.destination)

this.audioCtx = ctx;
},
/**
* Canvas gradient. Vertical, from top down
Expand All @@ -153,5 +155,8 @@ export default {
this.setAnalyser()
this.mainLoop()
},
beforeDestroy () {
this.audioCtx.close()
},
methods
}
3 changes: 2 additions & 1 deletion src/components/AvCircle.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ const AvCircle = {
rotate: 1.5,
audio: null,
analyser: null,
ctx: null
ctx: null,
audioCtx: null
}
},
methods: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/AvLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const AvLine = {
return {
audio: null,
analyser: null,
ctx: null
ctx: null,
audioCtx: null
}
},
methods: {
Expand Down

1 comment on commit 4f8dcd4

@SohrabZ
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.