Compare commits
6 Commits
API-can-fe
...
allow-seek
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3747f51fc | ||
|
|
7089bef0d3 | ||
|
|
209da288dc | ||
|
|
1a2b6c8be3 | ||
|
|
48a25e266d | ||
|
|
2568383352 |
@@ -26,7 +26,7 @@ $(document).on "turbolinks:load", ->
|
|||||||
$("#broadcast_video").html data.video_content
|
$("#broadcast_video").html data.video_content
|
||||||
new (Clappr.Player)(
|
new (Clappr.Player)(
|
||||||
parentId: '#broadcast_video'
|
parentId: '#broadcast_video'
|
||||||
source: data.playback_url
|
source: data.full_live_stream_playback_url
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
mute: true,
|
mute: true,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class BroadcastsChannel < ApplicationCable::Channel
|
|||||||
event: :broadcast_stream_update,
|
event: :broadcast_stream_update,
|
||||||
status: broadcast.status,
|
status: broadcast.status,
|
||||||
playback_url: broadcast.stream_playback_url,
|
playback_url: broadcast.stream_playback_url,
|
||||||
|
full_live_stream_playback_url: broadcast.full_live_stream_playback_url,
|
||||||
video_content: video_content,
|
video_content: video_content,
|
||||||
status_content: status_content,
|
status_content: status_content,
|
||||||
streamer_status: broadcast.streamer_status
|
streamer_status: broadcast.streamer_status
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ class StreamNotificationsController < ApplicationController
|
|||||||
when "video.live_stream.recording"
|
when "video.live_stream.recording"
|
||||||
@broadcast.streamer_recording!
|
@broadcast.streamer_recording!
|
||||||
notify_users
|
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"
|
when "video.live_stream.active"
|
||||||
@broadcast.active!
|
@broadcast.active!
|
||||||
notify_users
|
notify_users
|
||||||
@@ -59,7 +63,8 @@ class StreamNotificationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_broadcast
|
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)
|
live_stream_id = notification.dig(:stream_notification, :data, :live_stream_id)
|
||||||
@broadcast = Broadcast.find_by(stream_uid: live_stream_id)
|
@broadcast = Broadcast.find_by(stream_uid: live_stream_id)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ class Broadcast < ApplicationRecord
|
|||||||
"https://stream.mux.com/#{stream_playback_uid}.m3u8"
|
"https://stream.mux.com/#{stream_playback_uid}.m3u8"
|
||||||
end
|
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
|
def stream_server_url
|
||||||
ENV['MUX_BROADCAST_SERVER_URL']
|
ENV['MUX_BROADCAST_SERVER_URL']
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddFullLiveStreamPlaybackUrlToBroadcasts < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :broadcasts, :full_live_stream_playback_uid, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -9,20 +9,6 @@ SET xmloption = content;
|
|||||||
SET client_min_messages = warning;
|
SET client_min_messages = warning;
|
||||||
SET row_security = off;
|
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: -
|
-- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: -
|
||||||
--
|
--
|
||||||
@@ -554,7 +540,8 @@ CREATE TABLE public.broadcasts (
|
|||||||
stream_playback_uid character varying,
|
stream_playback_uid character varying,
|
||||||
token character varying,
|
token character varying,
|
||||||
streamer_status integer DEFAULT 0,
|
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'),
|
('20200716094927'),
|
||||||
('20200716103525'),
|
('20200716103525'),
|
||||||
('20200716105723'),
|
('20200716105723'),
|
||||||
('20200720051634');
|
('20200720051634'),
|
||||||
|
('20200720131309');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ RSpec.describe BroadcastsChannel, type: :channel do
|
|||||||
event: "broadcast_stream_update",
|
event: "broadcast_stream_update",
|
||||||
status: broadcast.status,
|
status: broadcast.status,
|
||||||
playback_url: broadcast.stream_playback_url,
|
playback_url: broadcast.stream_playback_url,
|
||||||
|
full_live_stream_playback_url: broadcast.full_live_stream_playback_url,
|
||||||
status_content: status_content,
|
status_content: status_content,
|
||||||
video_content: video_content,
|
video_content: video_content,
|
||||||
streamer_status: broadcast.streamer_status
|
streamer_status: broadcast.streamer_status
|
||||||
|
|||||||
@@ -4,27 +4,45 @@ RSpec.describe StreamNotificationsController, type: :controller do
|
|||||||
render_views
|
render_views
|
||||||
|
|
||||||
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, name: "Live Stream") }
|
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(:active_status) { { type: "video.live_stream.active", object: { id: "mux_stream" } } }
|
||||||
let(:disconnected_status) { {type: "video.live_stream.disconnected", 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) { { 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(:idle_status_for_unknown_broadcast) { { type: "video.live_stream.idle", object: { id: "unknown-id" } } }
|
||||||
let(:asset_ready) { {
|
let(:asset_ready) do
|
||||||
type: "video.asset.static_renditions.ready",
|
{
|
||||||
object: { id: "asset_uid" },
|
type: "video.asset.static_renditions.ready",
|
||||||
data: {
|
object: { id: "asset_uid" },
|
||||||
playback_ids: [
|
|
||||||
{id: "playback_uid"}
|
|
||||||
],
|
|
||||||
static_renditions: {
|
|
||||||
files: [{name: "high.mp4"}]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
stream_notification: {
|
|
||||||
data: {
|
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
|
describe "#create" do
|
||||||
before do
|
before do
|
||||||
@@ -54,13 +72,20 @@ RSpec.describe StreamNotificationsController, type: :controller do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "creates a broadcast recording when static_renditions.ready is received in notification" do
|
it "creates a broadcast recording when static_renditions.ready is received in notification" do
|
||||||
expect {
|
expect do
|
||||||
post :create, params: asset_ready
|
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)
|
expect(BroadcastsChannel).to have_received(:stream_recording_ready)
|
||||||
end
|
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
|
it "returns OK response even for non-existing broadcast" do
|
||||||
post :create, params: idle_status_for_unknown_broadcast
|
post :create, params: idle_status_for_unknown_broadcast
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ FactoryBot.define do
|
|||||||
stream_uid "mux_stream"
|
stream_uid "mux_stream"
|
||||||
stream_key "mux_key"
|
stream_key "mux_key"
|
||||||
stream_playback_uid "mux_playback_id"
|
stream_playback_uid "mux_playback_id"
|
||||||
|
full_live_stream_playback_uid "full_live_stream_playback_uid"
|
||||||
status "created"
|
status "created"
|
||||||
streamer_status "idle"
|
streamer_status "idle"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user