$(document).on "turbolinks:load", -> # Only connect if a broadcast-token meta tag is present broadcast_meta = document.querySelector("meta[name=broadcast-token]") return unless broadcast_meta broadcastToken = broadcast_meta.getAttribute("content") App.public = App.cable.subscriptions.create { channel: "BroadcastsChannel", token: broadcastToken }, connected: -> # Called when the subscription is ready for use on the server disconnected: -> # Called when the subscription has been terminated by the server received: (data) -> return unless document.querySelector("meta[name=broadcast-token][content='#{broadcastToken}']") switch data.event when "broadcast_stream_update" then @refreshBroadcastVideo(data) when "stream_recording_ready" then @showBroadcastRecordings(data) refreshBroadcastVideo: (data) -> $("#broadcast_updates").html data.status_content if data.streamer_status == 'recording' && data.status == 'active' $("#broadcast_video").html data.video_content new (Clappr.Player)( parentId: '#broadcast_video' source: data.playback_url width: '100%', height: '100%', mute: true, autoPlay: true, hlsMinimumDvrSize: 1) if data.streamer_status == "idle" && data.status == "idle" $("#broadcast_video").html data.video_content showBroadcastRecordings: (data) -> $(".flash-message").html data.flash_content $("#broadcast_recordings").html data.recordings_content $("#broadcast_recordings_nav").html data.recordings_nav_content