Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created July 29, 2014 08:14
Show Gist options
  • Save benphelps/911d88a3a17368a50a29 to your computer and use it in GitHub Desktop.
Save benphelps/911d88a3a17368a50a29 to your computer and use it in GitHub Desktop.
class LiveChat
constructor: (@stream) ->
@element = $("##{@id}")
@stream_id = gon.stream_id
@templates =
message: $('#message_tpl').html();
# Connect to the socket
subscribe: ->
Danthes.subscribe "/stream/#{@stream_id}", (data, channel) ->
@write data
# Append the message to the chat element
write: (data) ->
@element.append Mustache.render @templates.message, data
@scroll()
# Scroll to the bottom of the div
scroll: ->
#@element.scrollTop(@element[0].scrollHeight);
#@element.animate { scrollTop: @element.prop "scrollHeight" }, 200
chat = new LiveChat "chat"
chat.subscribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment