From 2568383352b7d4213ebe258fec13df70981292b8 Mon Sep 17 00:00:00 2001 From: Bilal Date: Mon, 20 Jul 2020 14:36:04 +0200 Subject: [PATCH] use full live stream url --- app/assets/javascripts/channels/broadcasts.coffee | 2 +- app/channels/broadcasts_channel.rb | 1 + app/controllers/stream_notifications_controller.rb | 8 +++++++- app/models/broadcast.rb | 4 ++++ ...309_add_full_live_stream_playback_url_to_broadcasts.rb | 5 +++++ 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20200720131309_add_full_live_stream_playback_url_to_broadcasts.rb diff --git a/app/assets/javascripts/channels/broadcasts.coffee b/app/assets/javascripts/channels/broadcasts.coffee index f163bee..823da04 100644 --- a/app/assets/javascripts/channels/broadcasts.coffee +++ b/app/assets/javascripts/channels/broadcasts.coffee @@ -26,7 +26,7 @@ $(document).on "turbolinks:load", -> $("#broadcast_video").html data.video_content new (Clappr.Player)( parentId: '#broadcast_video' - source: data.playback_url + source: data.full_live_stream_playback_url width: '100%', height: '100%', mute: true, diff --git a/app/channels/broadcasts_channel.rb b/app/channels/broadcasts_channel.rb index dd3d941..ad96756 100644 --- a/app/channels/broadcasts_channel.rb +++ b/app/channels/broadcasts_channel.rb @@ -16,6 +16,7 @@ class BroadcastsChannel < ApplicationCable::Channel event: :broadcast_stream_update, status: broadcast.status, playback_url: broadcast.stream_playback_url, + full_live_stream_playback_url: broadcast.full_live_stream_playback_url, video_content: video_content, status_content: status_content, streamer_status: broadcast.streamer_status diff --git a/app/controllers/stream_notifications_controller.rb b/app/controllers/stream_notifications_controller.rb index ce76ff6..e7fdb27 100644 --- a/app/controllers/stream_notifications_controller.rb +++ b/app/controllers/stream_notifications_controller.rb @@ -14,6 +14,11 @@ class StreamNotificationsController < ApplicationController when "video.live_stream.recording" @broadcast.streamer_recording! notify_users + when "video.asset.ready" + full_live_stream_playback_uid = notification.dig(:data, :playback_ids, 0, :id) + @broadcast.full_live_stream_playback_uid = full_live_stream_playback_uid + @broadcast.save + notify_users when "video.live_stream.active" @broadcast.active! notify_users @@ -59,7 +64,8 @@ class StreamNotificationsController < ApplicationController end def set_broadcast - if notification_type == "video.asset.static_renditions.ready" + case notification_type + when "video.asset.static_renditions.ready", "video.asset.ready" live_stream_id = notification.dig(:stream_notification, :data, :live_stream_id) @broadcast = Broadcast.find_by(stream_uid: live_stream_id) else diff --git a/app/models/broadcast.rb b/app/models/broadcast.rb index 564fd41..a9c9041 100644 --- a/app/models/broadcast.rb +++ b/app/models/broadcast.rb @@ -30,6 +30,10 @@ class Broadcast < ApplicationRecord "https://stream.mux.com/#{stream_playback_uid}.m3u8" end + def full_live_stream_playback_url + "https://stream.mux.com/#{full_live_stream_playback_uid}.m3u8" + end + def stream_server_url ENV['MUX_BROADCAST_SERVER_URL'] end diff --git a/db/migrate/20200720131309_add_full_live_stream_playback_url_to_broadcasts.rb b/db/migrate/20200720131309_add_full_live_stream_playback_url_to_broadcasts.rb new file mode 100644 index 0000000..84f78b5 --- /dev/null +++ b/db/migrate/20200720131309_add_full_live_stream_playback_url_to_broadcasts.rb @@ -0,0 +1,5 @@ +class AddFullLiveStreamPlaybackUrlToBroadcasts < ActiveRecord::Migration[6.0] + def change + add_column :broadcasts, :full_live_stream_playback_uid, :string + end +end