Skip to content

Instantly share code, notes, and snippets.

@jakobrs
Created March 13, 2023 18:08
Show Gist options
  • Save jakobrs/2071e2d3bff25d772483700099949c98 to your computer and use it in GitHub Desktop.
Save jakobrs/2071e2d3bff25d772483700099949c98 to your computer and use it in GitHub Desktop.
#!/usr/bin/env wpexec
om = ObjectManager {
Interest {
type = "node",
Constraint { "media.class", "=", "Video/Source" },
},
Interest {
type = "node",
Constraint { "media.class", "=", "Audio/Source" },
},
}
running_sources = 0
function state_change(node, old_state, new_state)
Log.debug("State changed: " .. node.properties["object.id"] .. ": " .. old_state .. " -> " .. new_state)
if old_state == "running" then
running_sources = running_sources - 1
if running_sources == 0 then
print()
end
elseif new_state == "running" then
if running_sources == 0 then
print("●")
end
running_sources = running_sources + 1
end
end
om:connect("object-added", function(_, node)
Log.debug("New source: " .. node.properties["object.id"] .. " " .. tostring(node.properties["node.name"]))
Log.debug(node.properties["media.class"])
node:connect("state-changed", state_change)
state_change(node, "nonexistent", node.state)
end)
om:connect("object-removed", function(_, node)
Log.debug("Source removed: " .. node.properties["object.id"] .. " " .. tostring(node.properties["node.name"]))
state_change(node, node.state, "nonexistent")
end)
om:activate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment