-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into emoticon_polish
Conflicts: app/assets/javascripts/backbone/plugins/emoticons.js.coffee
- Loading branch information
Showing
10 changed files
with
171 additions
and
60 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Kandan.Helpers.Audio | ||
@audioHolder: -> | ||
$('.audio_channels')[0] | ||
|
||
@audioChannels: -> | ||
$('audio') | ||
|
||
@createAudioChannel: (id) -> | ||
channel = $("<audio class='audio_#{id}'></audio>") | ||
channel.appendTo(@audioHolder()) | ||
|
||
@destroyAudioChannel: (id) -> | ||
channel = $(".audio_#{id}") | ||
channel.remove() | ||
|
||
@audioChannel: (id) -> | ||
$(".audio_#{id}")[0] | ||
|
||
@currentAudioChannel: -> | ||
@audioChannel(Kandan.Helpers.Channels.getActiveChannelId()) |
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
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
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
181 changes: 138 additions & 43 deletions
181
app/assets/javascripts/backbone/plugins/music_player.js.coffee
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,179 @@ | ||
class Kandan.Plugins.MusicPlayer | ||
|
||
@plugin_namespace: "Kandan.Plugins.MusicPlayer" | ||
@plugin_id: "" | ||
@widget_title: "Player" | ||
@play_regex: /^\/play .+/ | ||
@stop_regex: /^\/stop/ | ||
@local_song_data: false | ||
@pluginNamespace: "Kandan.Plugins.MusicPlayer" | ||
@pluginId: "" | ||
@widgetTitle: "Player" | ||
@playRegex: /^/play .+/ | ||
@stopRegex: /^/stop/ | ||
@resumeRegex: /^/resume/ | ||
@localSongData: false | ||
|
||
|
||
@play_template: _.template('<strong><a class="audio-play">playing</a> <a target="_blank" href="<%- url %>"><%- url %></a></strong>') | ||
@song_template: _.template('<li><%= song.split("/").pop() %></li>') | ||
@playTemplate: _.template('<strong><a class="audio-play">playing</a> <a target="_blank" href="<%- url %>"><%- url %></a></strong>') | ||
@stopTemplate: _.template('<strong><a class="audio-play">stopping</a> the music.') | ||
@resumeTemplate: _.template('<strong><a class="audio-play">resuming</a> the music.') | ||
@songTemplate: _.template('<li><%= song.split("/").pop() %></li>') | ||
|
||
|
||
@set_error: (error_message)-> | ||
console.log "music player error", error_message | ||
@setError: (errorMessage)-> | ||
console.log "music player error", errorMessage | ||
|
||
|
||
@create_song_list: (songs)-> | ||
@createSongList: (songs)-> | ||
$songs = $('<ul class="songs"></ul>') | ||
if songs.length == 0 | ||
$songs = "No songs! Maybe add some?" | ||
else | ||
$songs.append(@song_template({song: song})) for song in songs | ||
$songs.append(@songTemplate({song: song})) for song in songs | ||
return $songs | ||
|
||
|
||
@render: ($widget_el)-> | ||
$widget_element_class = $widget_el.attr('class') | ||
@render: ($widgetEl)-> | ||
$widgetElementClass = $widgetEl.attr('class') | ||
|
||
if @local_song_data | ||
$songs = @create_song_list(@local_song_data) | ||
if @localSongData | ||
$songs = @createSongList(@localSongData) | ||
else | ||
@get_songs({ | ||
@getSongs({ | ||
success: (songs)=> | ||
$songs = @create_song_list(songs) | ||
$songs = @createSongList(songs) | ||
|
||
failure: ()-> | ||
@set_error("Could not load songs") | ||
@setError("Could not load songs") | ||
}) | ||
$widget_el.html($songs) | ||
$widgetEl.html($songs) | ||
|
||
|
||
# TODO add support for sounds | ||
@init: (plugin_id)-> | ||
@plugin_id = plugin_id | ||
@register_modifier() | ||
@register_widget() | ||
# TODO: Add support for sounds | ||
@init: (pluginId)-> | ||
@pluginId = pluginId | ||
Kandan.Data.Channels.registerCallback("change", $.proxy(@onChannelChange, this)) | ||
@registerPlayModifier() | ||
@registerStopModifier() | ||
@registerResumeModifier() | ||
# Disabled for now | ||
#@registerWidget() | ||
|
||
|
||
@register_widget: ()-> | ||
Kandan.Widgets.register @plugin_namespace | ||
@registerWidget: ()-> | ||
Kandan.Widgets.register @pluginNamespace | ||
|
||
|
||
@register_modifier: ()-> | ||
Kandan.Modifiers.register @play_regex, (message, state)=> | ||
if state == Kandan.Helpers.Activities.ACTIVE_STATE | ||
console.log "add song to player and play song" | ||
@store_song url | ||
@registerPlayModifier: ()-> | ||
Kandan.Modifiers.register @playRegex, (message, state) => | ||
url = $.trim(message.content.substr(message.content.indexOf(" ") + 1)); | ||
if true and Kandan.Data.Channels.activeChannelId()? # and state == Kandan.Helpers.Activities.ACTIVE_STATE commented out because state == undefined for some reason | ||
rawInput = Kandan.Helpers.Utils.unescape(url) | ||
soundUrl = null | ||
soundUrl = @localSounds(rawInput) | ||
soundUrl ?= rawInput | ||
|
||
@playUrl(message.channel_id, soundUrl) | ||
else | ||
console.log "song is history" | ||
console.log "Not playing stale song" | ||
|
||
message.content = @playTemplate({url: url}) | ||
return Kandan.Helpers.Activities.buildFromBaseTemplate message | ||
|
||
@registerStopModifier: ()-> | ||
Kandan.Modifiers.register @stopRegex, (message, state) => | ||
url = $.trim(message.content.substr(message.content.indexOf(" ") + 1)); | ||
if true and Kandan.Data.Channels.activeChannelId()? | ||
@stopSound(message.channel_id) | ||
|
||
message.content = @play_template({url: message.content.split @play_regex}) | ||
return Kandan.Helpers.Activities.build_from_base_template message | ||
message.content = @stopTemplate() | ||
return Kandan.Helpers.Activities.buildFromBaseTemplate message | ||
|
||
@registerResumeModifier: ()-> | ||
Kandan.Modifiers.register @resumeRegex, (message, state) => | ||
if true and Kandan.Data.Channels.activeChannelId()? | ||
@play(message.channel_id) | ||
|
||
message.content = @resumeTemplate() | ||
return Kandan.Helpers.Activities.buildFromBaseTemplate message | ||
|
||
|
||
# TODO display error about song not being added by creating an activity locally | ||
@store_song: (url)-> | ||
@get_songs({ | ||
@storeSong: (url)-> | ||
@getSongs({ | ||
success: (data)=> | ||
data.push url | ||
Kandan.Store.set @plugin_id, { | ||
Kandan.Store.set @pluginId, { | ||
success: (data)-> | ||
@local_song_data = data | ||
Kandan.Widgets.render_widget @plugin_namespace | ||
@localSongData = data | ||
Kandan.Widgets.renderWidget @pluginNamespace | ||
} | ||
}) | ||
|
||
|
||
@get_songs: (callbacks)-> | ||
Kandan.Store.get @plugin_id, callbacks | ||
@getSongs: (callbacks)-> | ||
Kandan.Store.get @pluginId, callbacks | ||
|
||
@localFileUrl: (fileName) -> | ||
"http://#{ window.location.hostname }:#{ window.location.port }/sounds/#{ fileName }" | ||
|
||
@localSounds: (name) -> | ||
sounds = { | ||
'claps' : @localFileUrl('golfclap.mp3') | ||
'cheers' : @localFileUrl('cheers.mp3') | ||
'ding' : @localFileUrl('ding.wav') | ||
'gong' : @localFileUrl('gong.mp3') | ||
} | ||
|
||
sounds[name] | ||
|
||
@audioChannels: -> | ||
Kandan.Helpers.Audio.audioChannels() | ||
|
||
@audioChannel: (id) -> | ||
Kandan.Helpers.Audio.audioChannel(id) | ||
|
||
@mute: (channelId) -> | ||
@setVolume(channelId, 0) | ||
|
||
@unmute: (channelId) -> | ||
@setVolume(channelId, 1) | ||
|
||
@toggle: (channelId) -> | ||
if @audioChannel(channelId).volume == 0 | ||
@unmute(channelId) | ||
else | ||
@mute(channelId) | ||
|
||
@setVolume: (channelId, volume) -> | ||
@audioChannel(channelId).volume = volume | ||
|
||
@setAudioUrl: (channelId, url) -> | ||
@audioChannel(channelId).setAttribute('src', url) | ||
|
||
@playUrl: (channelId, url) -> | ||
@setAudioUrl(channelId, url) | ||
@play(channelId) | ||
|
||
@play: (channelId) -> | ||
@audioChannel(channelId).play() | ||
|
||
@stopSound: (channelId) -> | ||
@audioChannel(channelId).pause() | ||
|
||
@currentChannel: () -> | ||
Kandan.Data.Channels.activeChannelId() | ||
|
||
@onChannelChange: () -> | ||
channelId = @currentChannel() | ||
for channel in @audioChannels() | ||
raw = $(channel).attr('class').split("_")[1] | ||
id = parseInt(raw) | ||
continue if isNaN(id) | ||
@mute(id) | ||
|
||
if @audioChannel(channelId)? | ||
@unmute(channelId) | ||
|
||
@playAudioNotice: -> | ||
url = @localFileUrl('ding.wav') | ||
player = $('.audio_private')[0] | ||
player.setAttribute('src', url) | ||
player.play() | ||
|
||
# Kandan.Plugins.register "Kandan.Plugins.MusicPlayer" | ||
# Kandan.Plugins.register "Kandan.Plugins.MusicPlayer" |
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.