Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Created July 17, 2012 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjaspers/686d56fcc7d7081232c6 to your computer and use it in GitHub Desktop.
Save pjaspers/686d56fcc7d7081232c6 to your computer and use it in GitHub Desktop.
// --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