Last active
July 11, 2017 18:22
-
-
Save cmargroff/386a53fcf45f29555c3bf2cba2cf6c48 to your computer and use it in GitHub Desktop.
Dispatch events to connected node of an input connected or disconnected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AudioNode.prototype.originalConnect = AudioNode.prototype.connect; | |
| AudioNode.prototype.originalDisconnect = AudioNode.prototype.disconnect; | |
| //event.detail is the connected or disconnected node | |
| Object.defineProperties(AudioNode.prototype, { | |
| connect: { | |
| value: function(){ | |
| if (arguments[0] instanceof AudioNode) { | |
| arguments[0].dispatchEvent(new CustomEvent('inputconnected', {detail: this})) | |
| } | |
| this.originalConnect.bind(null, arguments); | |
| } | |
| }, | |
| disconnect: { | |
| value: function(){ | |
| if (arguments[0] instanceof AudioNode) { | |
| arguments[0].dispatchEvent(new CustomEvent('inputdisconnected', {detail: this})) | |
| } | |
| this.originalDisonnect.bind(null, arguments); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment