module Mediamtx # Telefono connesso al path RTMP (non solo slate alwaysAvailable). module PublisherOnline module_function def active?(session) return true if rtmp_publisher?(session) active_path?(path_info(session)) end def path_info(session) Client.for_session(session).list_paths.find { |i| i["name"] == session.mediamtx_path_name } end # MediaMTX <=1.19: online + source.type=rtmpConn. # MediaMTX 1.20+: online/source spesso null anche con publisher; usare rtmpconns. def active_path?(info) return false unless info return true if info["online"] == true && rtmp_source?(info.dig("source", "type")) false end def rtmp_publisher?(session) path = session.mediamtx_path_name.to_s return false if path.blank? Client.for_session(session).list_rtmp_conns.any? do |conn| conn_path = conn["path"].to_s.sub(%r{\A/}, "") next false unless conn_path == path state = conn["state"].to_s state.empty? || state == "publish" || state == "idle" end rescue StandardError false end def h264_video?(info) return false unless info (info["tracks2"] || []).any? do |track| track["codec"] == "H264" && track.dig("codecProps", "width").to_i.positive? end end def video_publishing?(session) return false unless active?(session) info = path_info(session) h264_video?(info) end def rtmp_source?(type) type.to_s.match?(/\Artmps?Conn\z/) end end end