Skip to content

Only accessing inputs when listeners are connected? #2347

Answered by toots
xorbital asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! That's a cool setup!

You script is way too complicated! 😅 Here's an example of an on-demand harbor output coupled with a input.http:

stream = input.http(start = false, "https://wwoz-sc.streamguys1.com/wwoz-hi.mp3")

listeners_count = ref(0)

def on_connect(~headers, ~uri, ~protocol, _) =
  listeners_count := !listeners_count + 1
  if !listeners_count > 0 and not stream.is_started() then
    log("Starting input")
    stream.start()
  end
end

def on_disconnect(_) =
  listeners_count := !listeners_count - 1
  if !listeners_count == 0 and stream.is_started() then
    log("Stopping input")
    stream.stop()
  end
end

blank = single("/tmp/blank.mp3")

stream = fallback(track_sensitive=false,

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@xorbital
Comment options

@toots
Comment options

@xorbital
Comment options

Answer selected by xorbital
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants