-
-
Save pjaspers/686d56fcc7d7081232c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --PropanePlaySoundsStart | |
// | |
// This adds support for some additional sounds in Propane. | |
// | |
// Available via: | |
// | |
// /sound <sound> | |
// | |
var soundRepoURL = "http://github.com/Inferis/campsounds/blob/master/sounds/"; | |
Campfire.SoundPlayer = Class.create({ | |
initialize: function(chat) { | |
var allSounds = new Hash; | |
var soundFiles = ["alive", "loser"]; | |
soundFiles.each(function(sound) { | |
allSounds[sound] = new Audio(soundRepoURL + sound + ".wav?raw=true"); | |
}); | |
this.sounds = allSounds; | |
}, | |
soundExists: function(soundName) { | |
var found = false; | |
for(var sound in this.sounds){ | |
if(sound == soundName) return true; | |
} | |
return false; | |
}, | |
detectSound: function(message) { | |
var match, url, sound, text; | |
if (message.pending()) return; | |
if (!message.kind === "text") return; | |
text = message.bodyElement().innerText; | |
if (!(match = text.match(/^\/sound\s+(.+)/))) return; | |
if (this.soundExists(match[1])) this.sounds[match[1]].play(); | |
}, | |
onMessagesInsertedBeforeDisplay: function(messages) { | |
for (var i = 0; i < messages.length; i++) { | |
this.detectSound(messages[i]); | |
} | |
}, | |
onMessageAccepted: function(message, messageID) { | |
this.detectSound(message); | |
} | |
}); | |
Campfire.Responders.push("SoundPlayer"); | |
window.chat.installPropaneResponder("SoundPlayer", "soundplayer"); | |
// --PropanePlaySoundsStop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment