Fix registrazione replay in produzione via PublisherSync.

MediaMTX distroless non invoca i webhook wget: accendiamo record sul path quando il telefono pubblica RTMP e lo spegniamo in pausa/offline.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-09 09:00:43 +02:00
parent 4ed15bc235
commit 9177e9e5a2
4 changed files with 81 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
require "rails_helper"
RSpec.describe Mediamtx::PublisherSync do
let(:user) { User.create!(email: "sync@test.com", name: "Sync", password: "password123", role: "coach") }
let(:club) { Club.create!(name: "Sync Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
let(:team) { club.teams.create!(name: "Under 16", sport: "volleyball") }
let!(:match) { team.matches.create!(opponent_name: "Avversario") }
let!(:session) do
StreamSession.create!(
match: match, user: user, status: "connecting", platform: "matchlivetv",
publish_token: "tok", started_at: Time.current
)
end
let(:client) { instance_double(Mediamtx::Client) }
let(:redis) { instance_double(Redis, get: nil, set: true, incr: 1, expire: true, del: 1) }
before do
Billing::AssignPlan.call(club: club, plan_slug: "premium_full")
allow(Mediamtx::Client).to receive(:new).and_return(client)
allow(client).to receive_messages(list_paths: [ {
"name" => session.mediamtx_path_name, "online" => true, "source" => { "type" => "rtmpConn" }
} ])
allow(Mediamtx::PublisherOnline).to receive(:active_path?).and_return(true)
allow_any_instance_of(described_class).to receive(:redis).and_return(redis)
allow(client).to receive(:set_path_recording)
end
it "abilita la registrazione quando il publisher è online" do
described_class.new(session).call
expect(client).to have_received(:set_path_recording).with(session, enabled: true)
end
it "disabilita la registrazione in pausa" do
session.update!(status: "paused")
allow(Mediamtx::PublisherOnline).to receive(:active_path?).and_return(true)
described_class.new(session).call
expect(client).to have_received(:set_path_recording).with(session, enabled: false)
end
end