Skip to content

Instantly share code, notes, and snippets.

@cmargroff
Last active July 11, 2017 18:22
Show Gist options
  • Select an option

  • Save cmargroff/386a53fcf45f29555c3bf2cba2cf6c48 to your computer and use it in GitHub Desktop.

Select an option

Save cmargroff/386a53fcf45f29555c3bf2cba2cf6c48 to your computer and use it in GitHub Desktop.
Dispatch events to connected node of an input connected or disconnected
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