Skip to content

Commit

Permalink
wire up video sync events
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Brumm committed Oct 19, 2013
1 parent e59e5d0 commit dfeb26d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/controllers/videos_controller.rb
Expand Up @@ -28,6 +28,8 @@ def video_remove
room = Room.friendly.find room_name
user = current_user.as_json(resource: room)

return unless current_user and (current_user.is?(:owner, room) or current_user.has_role?(:admin))

video = room.videos.find(video_id).destroy

if video
Expand All @@ -39,6 +41,29 @@ def video_remove
end
end

def video_mark_seen
# fail fast
return unless current_user

room_name = data[:room]
video_id = data[:video_id]
room = Room.friendly.find room_name

room.videos.find(video_id).touch(:ended_at)

broadcast_video_list room_name, room.videos
end

def video_sync
# fail fast
return unless current_user # && current_user.is?(:owner, room) || current_user.is?(:mod, room)

room_name = data[:room]
timestamp = data[:timestamp]

WebsocketRails[room_name].trigger(:video_sync, timestamp)
end

private

def broadcast_video_list room_name, videos
Expand Down
2 changes: 2 additions & 0 deletions config/events.rb
Expand Up @@ -15,5 +15,7 @@

subscribe :video_add, to: VideosController, with_method: :video_add
subscribe :video_remove, to: VideosController, with_method: :video_remove
subscribe :video_mark_seen, to: VideosController, with_method: :video_mark_seen
subscribe :video_sync, to: VideosController, with_method: :video_sync

end

0 comments on commit dfeb26d

Please sign in to comment.