mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
Explicitly detect mimetype support using test sounds. Fallback to canPlayType().
This commit is contained in:
@@ -46,6 +46,7 @@ public class BasicResource extends AuthenticatingHttpServlet {
|
|||||||
int index = Integer.parseInt(indexString);
|
int index = Integer.parseInt(indexString);
|
||||||
String name = request.getParameter("name");
|
String name = request.getParameter("name");
|
||||||
String tunnelUUID = request.getParameter("uuid");
|
String tunnelUUID = request.getParameter("uuid");
|
||||||
|
String mimetype = request.getParameter("mimetype");
|
||||||
|
|
||||||
// Get session
|
// Get session
|
||||||
GuacamoleSession session;
|
GuacamoleSession session;
|
||||||
@@ -68,6 +69,9 @@ public class BasicResource extends AuthenticatingHttpServlet {
|
|||||||
if (name != null)
|
if (name != null)
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=" + name);
|
response.setHeader("Content-Disposition", "attachment; filename=" + name);
|
||||||
|
|
||||||
|
// If mimetype provided, reflect back
|
||||||
|
response.setContentType(mimetype);
|
||||||
|
|
||||||
// Get output stream and pipe
|
// Get output stream and pipe
|
||||||
OutputStream out = response.getOutputStream();
|
OutputStream out = response.getOutputStream();
|
||||||
GuacamoleResourcePipe resourcePipe = tunnel.getResourcePipe(index);
|
GuacamoleResourcePipe resourcePipe = tunnel.getResourcePipe(index);
|
||||||
|
@@ -88,4 +88,13 @@
|
|||||||
<url-pattern>/resource</url-pattern>
|
<url-pattern>/resource</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<mime-mapping>
|
||||||
|
<extension>mp3</extension>
|
||||||
|
<mime-type>audio/mpeg</mime-type>
|
||||||
|
</mime-mapping>
|
||||||
|
<mime-mapping>
|
||||||
|
<extension>ogg</extension>
|
||||||
|
<mime-type>audio/ogg</mime-type>
|
||||||
|
</mime-mapping>
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
||||||
|
@@ -62,6 +62,9 @@ var GuacamoleUI = {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Supported mimetypes
|
||||||
|
GuacamoleUI.supportedAudio = {};
|
||||||
|
|
||||||
// Constant UI initialization and behavior
|
// Constant UI initialization and behavior
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
@@ -485,6 +488,33 @@ var GuacamoleUI = {
|
|||||||
GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
|
GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function testAudio(url, mimetype) {
|
||||||
|
|
||||||
|
// If browser says we can't play it, don't try
|
||||||
|
var audio = new Audio();
|
||||||
|
if (!audio.canPlayType(mimetype))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Otherwise, test
|
||||||
|
audio.src = url;
|
||||||
|
|
||||||
|
// On error, explicitly unsupported
|
||||||
|
audio.addEventListener("error", function() {
|
||||||
|
GuacamoleUI.supportedAudio[mimetype] = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// On successful play, explicitly supported
|
||||||
|
audio.addEventListener("ended", function() {
|
||||||
|
GuacamoleUI.supportedAudio[mimetype] = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
audio.play();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
testAudio("sounds/silence.mp3", "audio/mpeg");
|
||||||
|
testAudio("sounds/silence.ogg", "audio/ogg");
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Tie UI events / behavior to a specific Guacamole client
|
// Tie UI events / behavior to a specific Guacamole client
|
||||||
@@ -792,9 +822,10 @@ GuacamoleUI.attach = function(guac) {
|
|||||||
|
|
||||||
// Start download
|
// Start download
|
||||||
GuacamoleUI.download.src =
|
GuacamoleUI.download.src =
|
||||||
"resource?index=" + index
|
"resource?index=" + index
|
||||||
+ "&name=" + name
|
+ "&name=" + name
|
||||||
+ "&uuid=" + uuid;
|
+ "&uuid=" + uuid
|
||||||
|
+ "&mimetype=" + mimetypes[0];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -805,6 +836,64 @@ GuacamoleUI.attach = function(guac) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Audio resource
|
||||||
|
else if (uri.substring(0, 8) == "audio://") {
|
||||||
|
|
||||||
|
// Create audio playing object
|
||||||
|
var audio = new Audio();
|
||||||
|
|
||||||
|
// Determine a supported mimetype
|
||||||
|
var mimetype = null;
|
||||||
|
for (var i=0; i<mimetypes.length; i++) {
|
||||||
|
|
||||||
|
// Don't bother if support was not detected
|
||||||
|
if (GuacamoleUI.supportedAudio[mimetypes[i]] == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// If mimetype support explicitly detected, use it
|
||||||
|
if (GuacamoleUI.supportedAudio[mimetypes[i]]) {
|
||||||
|
mimetype = mimetypes[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get level of support for mimetype
|
||||||
|
var certainty = audio.canPlayType(mimetypes[i]);
|
||||||
|
|
||||||
|
// If likely to have support, use that
|
||||||
|
if (certainty == "probably") {
|
||||||
|
mimetype = mimetypes[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, choose if not already chosen, but keep trying
|
||||||
|
else if (certainty == "maybe" && !mimetype)
|
||||||
|
mimetype = mimetypes[i];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If unable to find a mimetype, reject
|
||||||
|
if (!mimetype)
|
||||||
|
guac.rejectResource(index);
|
||||||
|
|
||||||
|
// Otherwise, start playing stream
|
||||||
|
else {
|
||||||
|
|
||||||
|
// Accept file resource
|
||||||
|
guac.acceptResource(index, mimetype);
|
||||||
|
|
||||||
|
// Play audio stream
|
||||||
|
audio.src =
|
||||||
|
"resource?index=" + index
|
||||||
|
+ "&name=" + name
|
||||||
|
+ "&uuid=" + uuid
|
||||||
|
+ "&mimetype=" + mimetype;
|
||||||
|
|
||||||
|
audio.play();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, reject (unknown URI)
|
// Otherwise, reject (unknown URI)
|
||||||
else
|
else
|
||||||
guac.rejectResource(index);
|
guac.rejectResource(index);
|
||||||
|
BIN
guacamole/src/main/webapp/sounds/silence.mp3
Normal file
BIN
guacamole/src/main/webapp/sounds/silence.mp3
Normal file
Binary file not shown.
BIN
guacamole/src/main/webapp/sounds/silence.ogg
Normal file
BIN
guacamole/src/main/webapp/sounds/silence.ogg
Normal file
Binary file not shown.
BIN
guacamole/src/main/webapp/sounds/silence.wav
Normal file
BIN
guacamole/src/main/webapp/sounds/silence.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user