mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUAC-1354: Use Guacamole.AudioPlayer.getInstance(), etc. to abstract away the various implementations.
This commit is contained in:
@@ -66,6 +66,70 @@ Guacamole.AudioPlayer.getTimestamp = function() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given mimetype is supported by any built-in
|
||||||
|
* implementation of Guacamole.AudioPlayer, and thus will be properly handled
|
||||||
|
* by Guacamole.AudioPlayer.getInstance().
|
||||||
|
*
|
||||||
|
* @param {String} mimetype
|
||||||
|
* The mimetype to check.
|
||||||
|
*
|
||||||
|
* @returns {Boolean}
|
||||||
|
* true if the given mimetype is supported by any built-in
|
||||||
|
* Guacamole.AudioPlayer, false otherwise.
|
||||||
|
*/
|
||||||
|
Guacamole.AudioPlayer.isSupportedType = function isSupportedType(mimetype) {
|
||||||
|
|
||||||
|
return Guacamole.RawAudioPlayer.isSupportedType(mimetype);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all mimetypes supported by any built-in
|
||||||
|
* Guacamole.AudioPlayer, in rough order of priority. Beware that only the core
|
||||||
|
* mimetypes themselves will be listed. Any mimetype parameters, even required
|
||||||
|
* ones, will not be included in the list. For example, "audio/L8" is a
|
||||||
|
* supported raw audio mimetype that is supported, but it is invalid without
|
||||||
|
* additional parameters. Something like "audio/L8;rate=44100" would be valid,
|
||||||
|
* however (see https://tools.ietf.org/html/rfc4856).
|
||||||
|
*
|
||||||
|
* @returns {String[]}
|
||||||
|
* A list of all mimetypes supported by any built-in Guacamole.AudioPlayer,
|
||||||
|
* excluding any parameters.
|
||||||
|
*/
|
||||||
|
Guacamole.AudioPlayer.getSupportedTypes = function getSupportedTypes() {
|
||||||
|
|
||||||
|
return Guacamole.RawAudioPlayer.getSupportedTypes();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an instance of Guacamole.AudioPlayer providing support for the given
|
||||||
|
* audio format. If support for the given audio format is not available, null
|
||||||
|
* is returned.
|
||||||
|
*
|
||||||
|
* @param {Guacamole.InputStream} stream
|
||||||
|
* The Guacamole.InputStream to read audio data from.
|
||||||
|
*
|
||||||
|
* @param {String} mimetype
|
||||||
|
* The mimetype of the audio data in the provided stream.
|
||||||
|
*
|
||||||
|
* @return {Guacamole.AudioPlayer}
|
||||||
|
* A Guacamole.AudioPlayer instance supporting the given mimetype and
|
||||||
|
* reading from the given stream, or null if support for the given mimetype
|
||||||
|
* is absent.
|
||||||
|
*/
|
||||||
|
Guacamole.AudioPlayer.getInstance = function getInstance(stream, mimetype) {
|
||||||
|
|
||||||
|
// Use raw audio player if possible
|
||||||
|
if (Guacamole.RawAudioPlayer.isSupportedType(mimetype))
|
||||||
|
return new Guacamole.RawAudioPlayer(stream, mimetype);
|
||||||
|
|
||||||
|
// No support for given mimetype
|
||||||
|
return null;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of Guacamole.AudioPlayer providing support for raw PCM format
|
* Implementation of Guacamole.AudioPlayer providing support for raw PCM format
|
||||||
* audio. This player relies only on the Web Audio API and does not require any
|
* audio. This player relies only on the Web Audio API and does not require any
|
||||||
|
@@ -635,13 +635,11 @@ Guacamole.Client = function(tunnel) {
|
|||||||
if (guac_client.onaudio)
|
if (guac_client.onaudio)
|
||||||
audioPlayer = guac_client.onaudio(stream, mimetype);
|
audioPlayer = guac_client.onaudio(stream, mimetype);
|
||||||
|
|
||||||
// If unsuccessful, use a default implementation
|
// If unsuccessful, try to use a default implementation
|
||||||
if (!audioPlayer) {
|
if (!audioPlayer)
|
||||||
if (Guacamole.RawAudioPlayer.isSupportedType(mimetype))
|
audioPlayer = Guacamole.AudioPlayer.getInstance(stream, mimetype);
|
||||||
audioPlayer = new Guacamole.RawAudioPlayer(stream, mimetype);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If player somehow successfully retrieved, send success response
|
// If we have successfully retrieved an audio player, send success response
|
||||||
if (audioPlayer) {
|
if (audioPlayer) {
|
||||||
audioPlayers[stream_index] = audioPlayer;
|
audioPlayers[stream_index] = audioPlayer;
|
||||||
guac_client.sendAck(stream_index, "OK", 0x0000);
|
guac_client.sendAck(stream_index, "OK", 0x0000);
|
||||||
|
Reference in New Issue
Block a user