didactek / obs-websocket-client

Swift libraries for communicating with OBS Studio. Supports both Codable serialization and an async/await calling pattern.
Apache License 2.0
2 stars 0 forks source link

Can't get Scenes #1

Closed Sjakelien closed 1 month ago

Sjakelien commented 1 month ago

Thank you so much for your project. It is really very useful, and should be helpful to many! While doing a quick PoC, I find that it is very easy to integrate your software in my project, but I'm struggling with

func getSceneList() async throws -> OBSResponse.GetSceneList

I get this error: jsonParseError(encapsulateError: Swift.DecodingError.valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "d", intValue: nil), ResponseKeys(stringValue: "responseData", intValue: nil), CodingKeys(stringValue: "currentPreviewSceneName", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead", underlyingError: nil)), source: "{\"d\":{\"requestId\":\"90FE6912-7ECB-4F5C-BA66-B54509917FFB\",\"requestStatus\":{\"code\":100,\"result\":true},\"requestType\":\"GetSceneList\",\"responseData\":{\"currentPreviewSceneName\":null,\"currentPreviewSceneUuid\":null,\"currentProgramSceneName\":\"Nog een scene\",\"currentProgramSceneUuid\":\"510907c8-5217-47c1-904e-c438f1c01ca0\",\"scenes\":[{\"sceneIndex\":0,\"sceneName\":\"Nog een scene\",\"sceneUuid\":\"510907c8-5217-47c1-904e-c438f1c01ca0\"},{\"sceneIndex\":1,\"sceneName\":\"Scène 2\",\"sceneUuid\":\"aeebe1ed-b454-4465-8caa-606ca32a99a5\"},{\"sceneIndex\":2,\"sceneName\":\"Scène\",\"sceneUuid\":\"249cb29d-b88a-4276-9582-9a007d0b09b4\"}]}},\"op\":7}")

This seems to be cause by

"responseData": { "currentPreviewSceneName": null, "currentPreviewSceneUuid": null, ...

  the null values not being handled properly 

  Would you know a workaround? I am not an OBS user, yet. So it might be that my OBS instance should have values for the preview scene. But apparently it can happen that they are null

  Kind regards

  Sjakelien
Sjakelien commented 1 month ago

I think this will help you. https://mega.co.nz/#!B31G2LaZ!uBBOCp9hLC7bq9kP8NC6s4DanQJJZuoFRr5FI_jkeic

you may need to install the c compiler

Are you a dangerous bot or are you serious?

kit-transue commented 1 month ago

This should be fixed on 'main' with commit 487b4cd3.

The generated API now adds Optional in a few more places, so this is a breaking API change. I will update to 2.0, but should use that opportunity to tidy a few issues identified by Swift 6. Hopefully this will land in the next few days.

Thanks for the amazing feedback! If you try out the code on main, please let me know your experience.

(leaving open until the version is tagged)

Sjakelien commented 1 month ago

thanks. I only now noticed this part of your documentation:

"Parse errors If the OBS response to a request can’t be parsed, the response JSON text is included in a APIError.jsonParseError(encapsulateError:source:) exception object. The implementor may catch this exception and parse the JSON on their own. This pattern gives the implementor a chance to soften any brittleness that comes with the strongly-typed API."

That happens exactly the workaround that I'm using right now.

I'll look into main later on and give feedback when appropriate.

kit-transue commented 1 month ago

Tagged as 2.0.0, You may have to unwrap some Optionals, but this should save you decoding JSON on your own.