Skip to content

Commit

Permalink
refactoring listen method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyo_ago committed Dec 4, 2014
1 parent d8ea78e commit de9cf3a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/chatwork.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,18 @@ class ChatworkStreaming extends EventEmitter
@post "#{baseUrl}/messages", body, callback

listen: =>
lastMessage = 0
setInterval =>
timeout = =>
@Room(id).Messages().show (err, messages) =>
for message in messages
if lastMessage < message.message_id
@emit 'message',
id,
message.message_id,
message.account,
message.body,
message.send_time,
message.update_time
lastMessage = message.message_id
, 1000 / (@rate / (60 * 60))
@emit 'message',
id,
message.message_id,
message.account,
message.body,
message.send_time,
message.update_time
setTimeout timeout, 1000 / (@rate / (60 * 60))
timeout()

Message: (mid) =>
show: (callback) =>
Expand Down

0 comments on commit de9cf3a

Please sign in to comment.