From 4aa5a8790859f730ed3da2902e6606981cc82a53 Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Thu, 5 May 2016 13:59:00 +0000 Subject: [PATCH] Update Play Sound module --- modules/browser/play_sound/command.js | 38 +++++++------------------- modules/browser/play_sound/config.yaml | 11 ++++++++ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/modules/browser/play_sound/command.js b/modules/browser/play_sound/command.js index 948cb14c8..648a5b37a 100644 --- a/modules/browser/play_sound/command.js +++ b/modules/browser/play_sound/command.js @@ -5,32 +5,14 @@ // beef.execute(function() { - - function playSound(url) { - function createSound(which) { - window.soundEmbed = document.createElement("audio"); - window.soundEmbed.setAttribute("src", which); - - window.soundEmbed.setAttribute("style", "display: none;"); - window.soundEmbed.setAttribute("autoplay", true); - - } - if (!window.soundEmbed) { - createSound(url); - } - else { - document.body.removeChild(window.soundEmbed); - window.soundEmbed.removed = true; - window.soundEmbed = null; - createSound(url); - } - window.soundEmbed.removed = false; - document.body.appendChild(window.soundEmbed); - } - - - - playSound("<%== @sound_file_uri %>"); - - beef.net.send("<%= @command_url %>", <%= @command_id %>, "Sound Played"); + var url = "<%== @sound_file_uri %>"; + try { + var sound = new Audio(url); + sound.play(); + beef.debug("[Play Sound] Played sound successfully: " + url); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "result=Sound Played", beef.are.status_success()); + } catch (e) { + beef.debug("[Play Sound] HTML5 audio unsupported. Could not play: " + url); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=audio not supported", beef.are.status_error()); + } }); diff --git a/modules/browser/play_sound/config.yaml b/modules/browser/play_sound/config.yaml index 943645f12..870bdaf87 100644 --- a/modules/browser/play_sound/config.yaml +++ b/modules/browser/play_sound/config.yaml @@ -11,5 +11,16 @@ beef: name: "Play Sound" description: "Play a sound on the hooked browser." authors: ["Saafan"] + # http://caniuse.com/audio target: working: ["All"] + not_working: + IE: + min_ver: 1 + max_ver: 8 + FF: + min_ver: 1 + max_ver: 2 + S: + min_ver: 1 + max_ver: 3