From f27a5ffa499f68b8ca1226863408a08d324e0856 Mon Sep 17 00:00:00 2001 From: totaam Date: Wed, 18 May 2022 11:22:36 +0700 Subject: [PATCH] #175 all browsers support AudioContext --- html5/connect.html | 2 - html5/index.html | 2 - html5/js/Client.js | 2 +- html5/js/Utilities.js | 16 --- html5/js/lib/AudioContextMonkeyPatch.js | 182 ------------------------ 5 files changed, 1 insertion(+), 203 deletions(-) delete mode 100644 html5/js/lib/AudioContextMonkeyPatch.js diff --git a/html5/connect.html b/html5/connect.html index 4ef61a2d..780aab0b 100644 --- a/html5/connect.html +++ b/html5/connect.html @@ -22,8 +22,6 @@ - - diff --git a/html5/index.html b/html5/index.html index ac269377..976a1944 100644 --- a/html5/index.html +++ b/html5/index.html @@ -19,8 +19,6 @@ - - diff --git a/html5/js/Client.js b/html5/js/Client.js index 967178f0..ce73e394 100644 --- a/html5/js/Client.js +++ b/html5/js/Client.js @@ -124,7 +124,7 @@ class XpraClient { this.audio_framework = null; this.audio_aurora_ctx = null; this.audio_codec = null; - this.audio_context = Utilities.getAudioContext(); + this.audio_context = new AudioContext(); this.audio_state = null; this.aurora_codecs = {}; this.mediasource_codecs = {}; diff --git a/html5/js/Utilities.js b/html5/js/Utilities.js index 7678e913..487dede8 100644 --- a/html5/js/Utilities.js +++ b/html5/js/Utilities.js @@ -223,22 +223,6 @@ const Utilities = { return layout; }, - getAudioContextClass : function() { - return window.AudioContext || window.webkitAudioContext || window.audioContext; - }, - - getAudioContext : function() { - if (Utilities.audio_context) { - return Utilities.audio_context; - } - const acc = Utilities.getAudioContextClass(); - if(!acc) { - return null; - } - Utilities.audio_context = new acc(); - return Utilities.audio_context; - }, - isMacOS : function() { return navigator.platform.includes('Mac'); }, diff --git a/html5/js/lib/AudioContextMonkeyPatch.js b/html5/js/lib/AudioContextMonkeyPatch.js deleted file mode 100644 index 8e5ed0ca..00000000 --- a/html5/js/lib/AudioContextMonkeyPatch.js +++ /dev/null @@ -1,182 +0,0 @@ -/* Copyright 2013 Chris Wilson - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* - -This monkeypatch library is intended to be included in projects that are -written to the proper AudioContext spec (instead of webkitAudioContext), -and that use the new naming and proper bits of the Web Audio API (e.g. -using BufferSourceNode.start() instead of BufferSourceNode.noteOn()), but may -have to run on systems that only support the deprecated bits. - -This library should be harmless to include if the browser supports -unprefixed "AudioContext", and/or if it supports the new names. - -The patches this library handles: -if window.AudioContext is unsupported, it will be aliased to webkitAudioContext(). -if AudioBufferSourceNode.start() is unimplemented, it will be routed to noteOn() or -noteGrainOn(), depending on parameters. - -The following aliases only take effect if the new names are not already in place: - -AudioBufferSourceNode.stop() is aliased to noteOff() -AudioContext.createGain() is aliased to createGainNode() -AudioContext.createDelay() is aliased to createDelayNode() -AudioContext.createScriptProcessor() is aliased to createJavaScriptNode() -AudioContext.createPeriodicWave() is aliased to createWaveTable() -OscillatorNode.start() is aliased to noteOn() -OscillatorNode.stop() is aliased to noteOff() -OscillatorNode.setPeriodicWave() is aliased to setWaveTable() -AudioParam.setTargetAtTime() is aliased to setTargetValueAtTime() - -This library does NOT patch the enumerated type changes, as it is -recommended in the specification that implementations support both integer -and string types for AudioPannerNode.panningModel, AudioPannerNode.distanceModel -BiquadFilterNode.type and OscillatorNode.type. - -*/ -(function (global, exports, perf) { - 'use strict'; - - function fixSetTarget(param) { - if (!param) // if NYI, just return - return; - if (!param.setTargetAtTime) - param.setTargetAtTime = param.setTargetValueAtTime; - } - - if (window.hasOwnProperty('webkitAudioContext') && - !window.hasOwnProperty('AudioContext')) { - window.AudioContext = webkitAudioContext; - - if (!AudioContext.prototype.hasOwnProperty('createGain')) - AudioContext.prototype.createGain = AudioContext.prototype.createGainNode; - if (!AudioContext.prototype.hasOwnProperty('createDelay')) - AudioContext.prototype.createDelay = AudioContext.prototype.createDelayNode; - if (!AudioContext.prototype.hasOwnProperty('createScriptProcessor')) - AudioContext.prototype.createScriptProcessor = AudioContext.prototype.createJavaScriptNode; - if (!AudioContext.prototype.hasOwnProperty('createPeriodicWave')) - AudioContext.prototype.createPeriodicWave = AudioContext.prototype.createWaveTable; - - - AudioContext.prototype.internal_createGain = AudioContext.prototype.createGain; - AudioContext.prototype.createGain = function() { - var node = this.internal_createGain(); - fixSetTarget(node.gain); - return node; - }; - - AudioContext.prototype.internal_createDelay = AudioContext.prototype.createDelay; - AudioContext.prototype.createDelay = function(maxDelayTime) { - var node = maxDelayTime ? this.internal_createDelay(maxDelayTime) : this.internal_createDelay(); - fixSetTarget(node.delayTime); - return node; - }; - - AudioContext.prototype.internal_createBufferSource = AudioContext.prototype.createBufferSource; - AudioContext.prototype.createBufferSource = function() { - var node = this.internal_createBufferSource(); - if (!node.start) { - node.start = function ( when, offset, duration ) { - if ( offset || duration ) - this.noteGrainOn( when || 0, offset, duration ); - else - this.noteOn( when || 0 ); - }; - } else { - node.internal_start = node.start; - node.start = function( when, offset, duration ) { - if( typeof duration !== 'undefined' ) - node.internal_start( when || 0, offset, duration ); - else - node.internal_start( when || 0, offset || 0 ); - }; - } - if (!node.stop) { - node.stop = function ( when ) { - this.noteOff( when || 0 ); - }; - } else { - node.internal_stop = node.stop; - node.stop = function( when ) { - node.internal_stop( when || 0 ); - }; - } - fixSetTarget(node.playbackRate); - return node; - }; - - AudioContext.prototype.internal_createDynamicsCompressor = AudioContext.prototype.createDynamicsCompressor; - AudioContext.prototype.createDynamicsCompressor = function() { - var node = this.internal_createDynamicsCompressor(); - fixSetTarget(node.threshold); - fixSetTarget(node.knee); - fixSetTarget(node.ratio); - fixSetTarget(node.reduction); - fixSetTarget(node.attack); - fixSetTarget(node.release); - return node; - }; - - AudioContext.prototype.internal_createBiquadFilter = AudioContext.prototype.createBiquadFilter; - AudioContext.prototype.createBiquadFilter = function() { - var node = this.internal_createBiquadFilter(); - fixSetTarget(node.frequency); - fixSetTarget(node.detune); - fixSetTarget(node.Q); - fixSetTarget(node.gain); - return node; - }; - - if (AudioContext.prototype.hasOwnProperty( 'createOscillator' )) { - AudioContext.prototype.internal_createOscillator = AudioContext.prototype.createOscillator; - AudioContext.prototype.createOscillator = function() { - var node = this.internal_createOscillator(); - if (!node.start) { - node.start = function ( when ) { - this.noteOn( when || 0 ); - }; - } else { - node.internal_start = node.start; - node.start = function ( when ) { - node.internal_start( when || 0); - }; - } - if (!node.stop) { - node.stop = function ( when ) { - this.noteOff( when || 0 ); - }; - } else { - node.internal_stop = node.stop; - node.stop = function( when ) { - node.internal_stop( when || 0 ); - }; - } - if (!node.setPeriodicWave) - node.setPeriodicWave = node.setWaveTable; - fixSetTarget(node.frequency); - fixSetTarget(node.detune); - return node; - }; - } - } - - if (window.hasOwnProperty('webkitOfflineAudioContext') && - !window.hasOwnProperty('OfflineAudioContext')) { - window.OfflineAudioContext = webkitOfflineAudioContext; - } - -}(window)); -