diff --git a/app/controllers/stream_notifications_controller.rb b/app/controllers/stream_notifications_controller.rb index 11cf20d..c68fbce 100644 --- a/app/controllers/stream_notifications_controller.rb +++ b/app/controllers/stream_notifications_controller.rb @@ -60,10 +60,16 @@ class StreamNotificationsController < ApplicationController def set_broadcast if notification_type == "video.asset.static_renditions.ready" 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 - @broadcast = Broadcast.find_by!(stream_uid: notification_object_id) + @broadcast = Broadcast.find_by(stream_uid: notification_object_id) end + + if @broadcast.nil? + logger.info "Ignoring broadcast from other environment. Type = #{notification_type}. Id = #{live_stream_id} / #{notification_object_id}" + head :ok + end + head :ok if @broadcast.nil? end def notify_users diff --git a/spec/controllers/stream_notifications_controller_spec.rb b/spec/controllers/stream_notifications_controller_spec.rb index 66f948e..8a9211f 100644 --- a/spec/controllers/stream_notifications_controller_spec.rb +++ b/spec/controllers/stream_notifications_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe StreamNotificationsController, type: :controller do 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" }, @@ -59,6 +60,12 @@ RSpec.describe StreamNotificationsController, type: :controller do expect(BroadcastsChannel).to have_received(:stream_recording_ready) end + + it "returns OK response even for non-existing broadcast" do + post :create, params: idle_status_for_unknown_broadcast + + expect(response).to be_successful + end end after do