obs websocket vendor event, cant get the detail of an event if it's an array #378

Open
opened 2022-10-02 15:50:01 -05:00 by Grummfy · 2 comments
Grummfy commented 2022-10-02 15:50:01 -05:00 (Migrated from github.com)

Operating System Info

Ubuntu 22.04

Other OS

No response

OBS Studio Version

Other

OBS Studio Version (Other)

27.2.4

OBS Studio Log URL

https://gist.github.com/Grummfy/847649e31535add040f7d84b24d7b96a

OBS Studio Crash Log URL

No response

Expected Behavior

receiving event.detail with the data send.

Current Behavior

if the data is an array, the event.detail is not correctly setted.

Steps to Reproduce

From a client send a vendor request in obs to the vendor (with CallVendorRequest to vendorName obs-browser) with data as array or object (in js type) and you have the reproduction.

In the log, we can see the message I have send.

In one the event_data is

 {
  "Henry": {
    "is_chat": true,
    "point": 4,
    "pseudo": "Henry"
  },
  "Wally": {
    "is_chat": false,
    "point": 0,
    "pseudo": "Wally"
  }
}

this succeed with event.detail containing the information.

[
  {
    "is_chat": true,
    "point": 4,
    "pseudo": "Henry"
  },
  {
    "is_chat": false,
    "point": 0,
    "pseudo": "Wally"
  }
]

this fail with event.detail empty.

Anything else we should know?

No response

### Operating System Info Ubuntu 22.04 ### Other OS _No response_ ### OBS Studio Version Other ### OBS Studio Version (Other) 27.2.4 ### OBS Studio Log URL https://gist.github.com/Grummfy/847649e31535add040f7d84b24d7b96a ### OBS Studio Crash Log URL _No response_ ### Expected Behavior receiving event.detail with the data send. ### Current Behavior if the data is an array, the event.detail is not correctly setted. ### Steps to Reproduce From a client send a vendor request in obs to the vendor (with CallVendorRequest to vendorName obs-browser) with data as array or object (in js type) and you have the reproduction. In the log, we can see the message I have send. In one the event_data is ``` { "Henry": { "is_chat": true, "point": 4, "pseudo": "Henry" }, "Wally": { "is_chat": false, "point": 0, "pseudo": "Wally" } } ``` this succeed with event.detail containing the information. ``` [ { "is_chat": true, "point": 4, "pseudo": "Henry" }, { "is_chat": false, "point": 0, "pseudo": "Wally" } ] ``` this fail with event.detail empty. ### Anything else we should know? _No response_
NWPlayer123 commented 2025-06-23 00:10:01 -05:00 (Migrated from github.com)

Can confirm this is still happening, any kind of array just shows up with zero elements which sucks

Can confirm this is still happening, any kind of array just shows up with zero elements which sucks
NWPlayer123 commented 2025-06-23 00:24:01 -05:00 (Migrated from github.com)

@tt2468 do you have any insight into this issue? You seem to be the original author of the WebSocket integration re: #340. I'm unsure what @Grummfy was using, I'm using obws and Rust, but it should all still boil down to json. Using the test HTML page and this Rust script, using the default "values" input from serde_json:

<!DOCTYPE html>

<script type="text/javascript">
  window.addEventListener('obs-websocket-test-event', function(event) {
    console.log(event.detail)
  })
</script>
use anyhow::Result;
use obws::{Client, requests::general::CallVendorRequest};
use serde_json::{Value, json};

#[tokio::main]
async fn main() -> Result<()> {
    // Connect to the OBS instance through obs-websocket.
    let client = Client::connect("localhost", 4455, Some("password")).await?;

    let value = json!({
        "code": 200,
        "success": true,
        "payload": {
            "features": [
                "serde",
                "json"
            ],
            "homepage": null
        }
    });
    println!("{:?}", value);

    let response = client
        .general()
        .call_vendor_request::<_, Value>(CallVendorRequest {
            vendor_name: "obs-browser",
            request_type: "emit_event",
            request_data: &json!({
                    "event_name": "obs-websocket-test-event",
                    "event_data": value,
            }),
        })
        .await?;
    println!("{response:?}");

    Ok(())
}
[package]
name = "obws-test"
version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1"
obws = "0.14"
serde_json = "1"
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }

We can see using Chromium's Inspect Element that it does print to the console, but features has nothing in it. This also happens with vec![].

Image

As well as it prints out our values on the Rust end:

Object {"code": Number(200), "payload": Object {"features": Array [String("serde"), String("json")], "homepage": Null}, "success": Bool(true)}
VendorResponse { vendor_name: "obs-browser", request_type: "emit_event", response_data: Object {} }
@tt2468 do you have any insight into this issue? You seem to be the original author of the WebSocket integration re: #340. I'm unsure what @Grummfy was using, I'm using `obws` and Rust, but it should all still boil down to json. Using the test HTML page and this Rust script, using the default "values" input from serde_json: ```html <!DOCTYPE html> <script type="text/javascript"> window.addEventListener('obs-websocket-test-event', function(event) { console.log(event.detail) }) </script> ``` ```rs use anyhow::Result; use obws::{Client, requests::general::CallVendorRequest}; use serde_json::{Value, json}; #[tokio::main] async fn main() -> Result<()> { // Connect to the OBS instance through obs-websocket. let client = Client::connect("localhost", 4455, Some("password")).await?; let value = json!({ "code": 200, "success": true, "payload": { "features": [ "serde", "json" ], "homepage": null } }); println!("{:?}", value); let response = client .general() .call_vendor_request::<_, Value>(CallVendorRequest { vendor_name: "obs-browser", request_type: "emit_event", request_data: &json!({ "event_name": "obs-websocket-test-event", "event_data": value, }), }) .await?; println!("{response:?}"); Ok(()) } ``` ```toml [package] name = "obws-test" version = "0.1.0" edition = "2024" [dependencies] anyhow = "1" obws = "0.14" serde_json = "1" tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] } ``` We can see using Chromium's Inspect Element that it does print to the console, but features has nothing in it. This also happens with vec![]. ![Image](https://github.com/user-attachments/assets/2a9025d5-4725-4c02-b10f-676ecd9d7bf3) As well as it prints out our values on the Rust end: ```rs Object {"code": Number(200), "payload": Object {"features": Array [String("serde"), String("json")], "homepage": Null}, "success": Bool(true)} VendorResponse { vendor_name: "obs-browser", request_type: "emit_event", response_data: Object {} } ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-obsproject/obs-browser#378
No description provided.