Compare commits

...

6 Commits

Author SHA1 Message Date
Bilal
b3747f51fc rebase 2020-07-22 13:48:47 +02:00
Bilal
7089bef0d3 fix MR comments 2020-07-22 13:47:56 +02:00
Bilal
209da288dc fix MR comments 2020-07-22 13:47:56 +02:00
Bilal
1a2b6c8be3 update specs 2020-07-22 13:47:56 +02:00
Bilal
48a25e266d add spec 2020-07-22 13:43:18 +02:00
Bilal
2568383352 use full live stream url 2020-07-22 13:43:18 +02:00
9 changed files with 68 additions and 38 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -14,6 +14,10 @@ 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.update(full_live_stream_playback_uid: full_live_stream_playback_uid)
notify_users
when "video.live_stream.active"
@broadcast.active!
notify_users
@@ -59,7 +63,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

View File

@@ -30,6 +30,10 @@ class Broadcast < ApplicationRecord
"https://stream.mux.com/#{stream_playback_uid}.m3u8"
end
def full_live_stream_playback_url
full_live_stream_playback_uid.blank? ? stream_playback_url : "https://stream.mux.com/#{full_live_stream_playback_uid}.m3u8"
end
def stream_server_url
ENV['MUX_BROADCAST_SERVER_URL']
end

View File

@@ -0,0 +1,5 @@
class AddFullLiveStreamPlaybackUrlToBroadcasts < ActiveRecord::Migration[6.0]
def change
add_column :broadcasts, :full_live_stream_playback_uid, :string
end
end

View File

@@ -9,20 +9,6 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: -
--
@@ -554,7 +540,8 @@ CREATE TABLE public.broadcasts (
stream_playback_uid character varying,
token character varying,
streamer_status integer DEFAULT 0,
shoot_location_time_zone character varying DEFAULT 'UTC'::character varying
shoot_location_time_zone character varying DEFAULT 'UTC'::character varying,
full_live_stream_playback_uid character varying
);
@@ -3954,6 +3941,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200716094927'),
('20200716103525'),
('20200716105723'),
('20200720051634');
('20200720051634'),
('20200720131309');

View File

@@ -24,6 +24,7 @@ RSpec.describe BroadcastsChannel, type: :channel do
event: "broadcast_stream_update",
status: broadcast.status,
playback_url: broadcast.stream_playback_url,
full_live_stream_playback_url: broadcast.full_live_stream_playback_url,
status_content: status_content,
video_content: video_content,
streamer_status: broadcast.streamer_status

View File

@@ -4,27 +4,45 @@ RSpec.describe StreamNotificationsController, type: :controller do
render_views
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, name: "Live Stream") }
let(:active_status) { {type: "video.live_stream.active", object: { id: "mux_stream" }} }
let(:disconnected_status) { {type: "video.live_stream.disconnected", object: { id: "mux_stream" }} }
let(:idle_status) { {type: "video.live_stream.idle", object: { id: "mux_stream" }} }
let(:idle_status_for_unknown_broadcast) { {type: "video.live_stream.idle", object: { id: "unknown-id" }} }
let(:asset_ready) { {
type: "video.asset.static_renditions.ready",
object: { id: "asset_uid" },
data: {
playback_ids: [
{id: "playback_uid"}
],
static_renditions: {
files: [{name: "high.mp4"}]
}
},
stream_notification: {
let(:active_status) { { type: "video.live_stream.active", object: { id: "mux_stream" } } }
let(:disconnected_status) { { type: "video.live_stream.disconnected", object: { id: "mux_stream" } } }
let(:idle_status) { { type: "video.live_stream.idle", object: { id: "mux_stream" } } }
let(:idle_status_for_unknown_broadcast) { { type: "video.live_stream.idle", object: { id: "unknown-id" } } }
let(:asset_ready) do
{
type: "video.asset.static_renditions.ready",
object: { id: "asset_uid" },
data: {
live_stream_id: "mux_stream"
playback_ids: [
{ id: "playback_uid" }
],
static_renditions: {
files: [{ name: "high.mp4" }]
}
},
stream_notification: {
data: {
live_stream_id: "mux_stream"
}
}
}
} }
end
let(:full_live_stream_ready) do
{
type: "video.asset.ready",
object: { id: "active_asset_uid" },
data: {
playback_ids: [
{ id: "full_live_stream_playback_uid" }
]
},
stream_notification: {
data: {
live_stream_id: "mux_stream"
}
}
}
end
describe "#create" do
before do
@@ -54,13 +72,20 @@ RSpec.describe StreamNotificationsController, type: :controller do
end
it "creates a broadcast recording when static_renditions.ready is received in notification" do
expect {
expect do
post :create, params: asset_ready
}.to change(BroadcastRecording, :count).by(1)
end.to change(BroadcastRecording, :count).by(1)
expect(BroadcastsChannel).to have_received(:stream_recording_ready)
end
it "stores full livestream playback uid and updates the broadcast" do
post :create, params: full_live_stream_ready
expect(Broadcast.last.full_live_stream_playback_uid).to eq "full_live_stream_playback_uid"
expect(BroadcastsChannel).to have_received(:broadcast_stream_updates).with(be_kind_of(Broadcast))
end
it "returns OK response even for non-existing broadcast" do
post :create, params: idle_status_for_unknown_broadcast

View File

@@ -11,6 +11,7 @@ FactoryBot.define do
stream_uid "mux_stream"
stream_key "mux_key"
stream_playback_uid "mux_playback_id"
full_live_stream_playback_uid "full_live_stream_playback_uid"
status "created"
streamer_status "idle"
end