The primary Audio Context used to play client-facing sounds. The context is undefined until the user's first gesture is observed.
The set of AudioBuffer objects which are cached for different audio paths
The set of singleton Sound instances which are cached for different audio paths
Get a map of the Sound objects which are currently playing.
A user gesture must be registered before audio can be played. This Array contains the Sound instances which are requested for playback prior to a gesture. Once a gesture is observed, we begin playing all elements of this Array.
A flag for whether video playback is currently locked by awaiting a user gesture
A Promise which resolves once the game audio API is unlocked and ready to use.
An internal tracker for the total size of the buffers cache.
The Native interval for the AudioHelper to analyse audio levels from streams Any interval passed to startLevelReports() would need to be a multiple of this value.
The cache size threshold after which audio buffers will be expired from the cache to make more room. 1 gigabyte, by default.
Create a Sound instance for a given audio source URL
Audio creation options
The source URL for the audio file
Play a single Sound by providing its source.
The file path to the audio source being played
The created Sound which is now playing
Register an event listener to await the first mousemove gesture and begin playback once observed.
The unlocked audio context
Request that other connected clients begin preloading a certain sound path.
The source file path requested for preload
A Promise which resolves once the preload is complete
Retrieve an AudioBuffer from the buffers cache, if it is available
The buffer audio source path
The AudioBuffer instance if cached, otherwise undefined
Update the last accessed time and playing status of a cached buffer.
The buffer audio source path
Is the buffer currently playing?
Insert an AudioBuffer into the buffers cache. See https://padenot.github.io/web-audio-perf/#memory-profiling
The buffer audio source path
The AudioBuffer instance
Returns a singleton AudioContext if one can be created. An audio context may not be available due to limited resources or browser compatibility in which case null will be returned
A singleton AudioContext or null if one is not available
Registers a stream for periodic reports of audio levels. Once added, the callback will be called with the maximum decibel level of the audio tracks in that stream since the last time the event was fired. The interval needs to be a multiple of AudioHelper.levelAnalyserNativeInterval which defaults at 50ms
An id to assign to this report. Can be used to stop reports
The MediaStream instance to report activity on.
The callback function to call with the decibel level. callback(dbLevel)
(optional) The interval at which to produce reports.
(optional) The smoothingTimeConstant to set on the audio analyser. Refer to AudioAnalyser API docs.
Returns whether or not listening to the stream was successful
Stop sending audio level reports This stops listening to a stream and stops sending reports. If we aren't listening to any more streams, cancel the global analyser timer.
The id of the reports that passed to startLevelReports.
Expire buffers from the cache when the total cache size exceeds a specified threshold. Buffers which were least recently accessed are removed first, provided they are not currently playing.
Ensures the global analyser timer is started
We create only one timer that runs every 50ms and only create it if needed, this is meant to optimize things and avoid having multiple timers running if we want to analyse multiple streams at the same time. I don't know if it actually helps much with performance but it's expected that limiting the number of timers running at the same time is good practice and with JS itself, there's a potential for a timer congestion phenomenon if too many are created.
Cancel the global analyser timer If the timer is running and has become unnecessary, stops it.
Capture audio level for all speakers and emit a webrtcVolumes custom event with all the volume levels detected since the last emit. The event's detail is in the form of {userId: decibelLevel}
Handle the first observed user gesture
The mouse-move event which enables playback
The Promise resolution function
Additional standard callback events that occur whenever a global volume slider is adjusted
The setting key
The new volume level
Register client-level settings for global volume overrides
Test whether a source file has a supported audio extension type
A requested audio source path
Does the filename end with a valid audio extension?
Given an input file path, determine a default name for the sound based on the filename
An input file path
A default sound name for the path
Open socket listeners which transact ChatMessage data
Play a one-off sound effect which is not part of a Playlist
An object configuring the audio data to play
The audio source file path, either a public URL or a local path relative to the public directory
The volume level at which to play the audio, between 0 and 1.
Begin playback of the audio effect immediately once it is loaded.
Loop the audio effect and continue playing it until it is manually stopped.
A Sound instance which controls audio playback.
Begin loading the sound for a provided source URL adding its
The audio source path to preload
The created and loaded Sound ready for playback
Returns the volume value based on a range input volume control's position. This is using an exponential approximation of the logarithmic nature of audio level perception
Value between [0, 1] of the range input
Counterpart to inputToVolume() Returns the input range value based on a volume
Value between [0, 1] of the volume level
A helper class to provide common functionality for working with the Web Audio API. https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API A singleton instance of this class is available as game#audio.
Game#audio