andreykaipov / goobs

Go client library for OBS Studio
Apache License 2.0
137 stars 22 forks source link

InputVolumeMeters report no values #61

Closed normen closed 11 months ago

normen commented 1 year ago

Hi,

for the InputVolumeMeters messages I do manage to enable them but the resulting event doesn't seem to contain any info about the actual meters, only the name and type of the channel?

Bildschirmfoto 2023-11-22 um 11 14 54

Am I missing something?

Thanks for any hints and especially for the library!

andreykaipov commented 11 months ago

Oh this is a bug in the generation code :(

The right type for inputs on this event is Array<Object>:

https://github.com/obsproject/obs-websocket/blob/cb6f0b8986292aad640928aee8416ab7a14935c3/docs/generated/protocol.json#L5150

This should translate to []map[string]interface{}, but it's currently a []*typedef.Input:

https://github.com/andreykaipov/goobs/blob/b67ee5891aa019a67d163dd675222b46f705c000/api/events/xx_generated.inputs.inputvolumemeters.go#L13

This is a result of some wonky logic here:

https://github.com/andreykaipov/goobs/blob/b67ee5891aa019a67d163dd675222b46f705c000/internal/generate/protocol/generate.go#L440-L499 where I take a guess at what structs match what fields based on their name.

It's a remnant of the v4 protocol where it documented common typedefs that it then referred to in requests, but in v5 a lot of the request types are documented as just Object or Array<Object>.

At the risk of just using map[string]interface{} everywhere to avoid situations like this and at least expose the hidden values (mapstructure's remain decoding might come in handy here), it might just be time to migrate this library from generated code spaghetti into more maintainable code... 😅

normen commented 11 months ago

Already tested and incorporated your changes, seems to work nicely including meters and setting zero values. Thank you very much!

andreykaipov commented 11 months ago

Oh snap are you talking about #81? That's crazy thank you for testing it out already! I was hesitant to ping you here until I was ready to cut a release but this gives me more confidence in it!

normen commented 11 months ago

Yep, didn't use the new builder pattern but it works great in my bridge app: https://github.com/normen/obs-mcu

I basically just had to add a few &'s really to adapt my code, meters work great without much overhead.

andreykaipov commented 11 months ago

Thanks once again for testing this out 🙏 I released these changes in v1.0.0