WebAudioModel.js 3.4 KB

12345678910111213141516171819202122
  1. export class WebAudioModel extends SDK.SDKModel{constructor(target){super(target);this._enabled=false;this._agent=target.webAudioAgent();target.registerWebAudioDispatcher(this);SDK.targetManager.addModelListener(SDK.ResourceTreeModel,SDK.ResourceTreeModel.Events.FrameNavigated,this._flushContexts,this);}
  2. _flushContexts(){this.dispatchEventToListeners(Events.ModelReset);}
  3. suspendModel(){this.dispatchEventToListeners(Events.ModelSuspend);return this._agent.disable();}
  4. resumeModel(){if(!this._enabled){return Promise.resolve();}
  5. return this._agent.enable();}
  6. ensureEnabled(){if(this._enabled){return;}
  7. this._agent.enable();this._enabled=true;}
  8. contextCreated(context){this.dispatchEventToListeners(Events.ContextCreated,context);}
  9. contextWillBeDestroyed(contextId){this.dispatchEventToListeners(Events.ContextDestroyed,contextId);}
  10. contextChanged(context){this.dispatchEventToListeners(Events.ContextChanged,context);}
  11. audioListenerCreated(listener){this.dispatchEventToListeners(Events.AudioListenerCreated,listener);}
  12. audioListenerWillBeDestroyed(contextId,listenerId){this.dispatchEventToListeners(Events.AudioListenerWillBeDestroyed,{contextId,listenerId});}
  13. audioNodeCreated(node){this.dispatchEventToListeners(Events.AudioNodeCreated,node);}
  14. audioNodeWillBeDestroyed(contextId,nodeId){this.dispatchEventToListeners(Events.AudioNodeWillBeDestroyed,{contextId,nodeId});}
  15. audioParamCreated(param){this.dispatchEventToListeners(Events.AudioParamCreated,param);}
  16. audioParamWillBeDestroyed(contextId,nodeId,paramId){this.dispatchEventToListeners(Events.AudioParamWillBeDestroyed,{contextId,paramId});}
  17. nodesConnected(contextId,sourceId,destinationId,sourceOutputIndex,destinationInputIndex){this.dispatchEventToListeners(Events.NodesConnected,{contextId,sourceId,destinationId,sourceOutputIndex,destinationInputIndex});}
  18. nodesDisconnected(contextId,sourceId,destinationId,sourceOutputIndex,destinationInputIndex){this.dispatchEventToListeners(Events.NodesDisconnected,{contextId,sourceId,destinationId,sourceOutputIndex,destinationInputIndex});}
  19. nodeParamConnected(contextId,sourceId,destinationId,sourceOutputIndex){this.dispatchEventToListeners(Events.NodeParamConnected,{contextId,sourceId,destinationId,sourceOutputIndex,});}
  20. nodeParamDisconnected(contextId,sourceId,destinationId,sourceOutputIndex){this.dispatchEventToListeners(Events.NodeParamDisconnected,{contextId,sourceId,destinationId,sourceOutputIndex,});}
  21. async requestRealtimeData(contextId){return await this._agent.getRealtimeData(contextId);}}
  22. SDK.SDKModel.register(WebAudioModel,SDK.Target.Capability.DOM,false);export const Events={ContextCreated:Symbol('ContextCreated'),ContextDestroyed:Symbol('ContextDestroyed'),ContextChanged:Symbol('ContextChanged'),ModelReset:Symbol('ModelReset'),ModelSuspend:Symbol('ModelSuspend'),AudioListenerCreated:Symbol('AudioListenerCreated'),AudioListenerWillBeDestroyed:Symbol('AudioListenerWillBeDestroyed'),AudioNodeCreated:Symbol('AudioNodeCreated'),AudioNodeWillBeDestroyed:Symbol('AudioNodeWillBeDestroyed'),AudioParamCreated:Symbol('AudioParamCreated'),AudioParamWillBeDestroyed:Symbol('AudioParamWillBeDestroyed'),NodesConnected:Symbol('NodesConnected'),NodesDisconnected:Symbol('NodesDisconnected'),NodeParamConnected:Symbol('NodeParamConnected'),NodeParamDisconnected:Symbol('NodeParamDisconnected'),};self.WebAudio=self.WebAudio||{};WebAudio=WebAudio||{};WebAudio.WebAudioModel=WebAudioModel;WebAudio.WebAudioModel.Events=Events;