obs-websocket-community-projects / obs-websocket-js

Consumes https://github.com/obsproject/obs-websocket
MIT License
657 stars 95 forks source link

Support "sourceName" for easier coding? #303

Closed rodrigograca31 closed 1 year ago

rodrigograca31 commented 1 year ago

Hi!

I expected SetSceneItemEnabled to receive "sourceName" (or "sceneItemName") but we need to use sceneItemId: 11 which is a "random" number that is not human friendly and theres no way to know it.

previously we used:

obs.send("SetSceneItemProperties", {
    "scene-name": "browsers",
    item: "warning",
    visible: true,
});

this was self explanatory, on the scene browsers set the item warning as visible. now with OBS 28 and obs-websocket-js 5:

obs.call("SetSceneItemEnabled", {
    sceneName: "browsers",
    sceneItemId: 11,
    sceneItemEnabled: true,
});

which works perfectly well but sceneItemId is unknown to us "users".... are we supposed to guess it? I had to use obs.on("SceneItemSelected", (data) => callback(data)); to find out it was 11 and then figured out theres code to get that ID programatically... one could do:

obs.call("GetSceneItemId", {
    sceneName: "browsers",
    sourceName: "warning",
})
.then((data) => {
    console.log(data.sceneItemId);
    obs.call("SetSceneItemEnabled", {
        sceneName: "browsers",
        sceneItemId: data.sceneItemId,
        sceneItemEnabled: true,
    });
});

but this makes the code way bigger compared with the original... also a bit repetitive... because first we find an ID then we set that ID enabled to true

what about supporting something like sceneItemName that way we could address a given item by a human readable name instead of a "random" ID. Something like:

obs.call("SetSceneItemEnabled", {
    sceneName: "browsers",
    sceneItemName: "warning",
    sceneItemEnabled: true,
});

I'm not even sure where that ID comes from and I'm guessing it might even change over time... (if the user removes/adds items) P.S. Not sure if this is a problem with the JS version or with the protocol it self....? Should I open an issue on OBS GitHub?

Versions Used (if applicable):

t2t2 commented 1 year ago

Yes protocol issues should be opened with obs-websocket instead

request: GetSceneItemList, format of response