Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The promise you get from callBatch() remains pending indefinitely if you use an invalid executionType (which causes a disconnect) #358

Open
eedefeed opened this issue Oct 10, 2024 · 0 comments

Comments

@eedefeed
Copy link

eedefeed commented Oct 10, 2024

Description

callBatch() returns a promise that should reject if an error occurs.

If you submit an invalid execution type, this causes a disconnect (presumably from OBS's side)
This library does not then settle the promise and it remains stuck in pending indefinitely.
Re-connecting does not result in the promise becoming settled.

The issue is reproducible using the 2 scripts provided. The first script uses setInterval() to show that the promise remains in pending and that neither the .then() and .catch() branches are not executed following the disconnect. The second scripts illustrates that re-connecting to OBS does not alleviate the problem.

Using the scripts:

  1. Change the url and pw parameters
  2. Create a media source called 'test track' in OBS.

If you need to match my configuration exactly, my media source is configured as follows:

loop: false
restart playback...: false
use hardware dec...: true
show nothing...: true
close file when...: true
speed: 100%
YUV colour range: Auto
apply alpha in lin....: false
FFmpeg Options: 

Versions

OBS version: 30.2.3
(from npm list) [email protected]
node version: v20.9.0

Script 1

import { OBSWebSocket } from 'obs-websocket-js';

let url = 'ws://';
let pw = '';
let idParams = {rpcVersion: 1}

let inputName = "test track";


let obs = new OBSWebSocket();

// Connect
try {
    let conInfo = await obs.connect(url, pw, idParams);
    console.log(`Connected to OBS websockets ${conInfo.obsWebSocketVersion} (using RPC ${conInfo.negotiatedRpcVersion})`);
} catch (error) {
    console.error("[Error] Failed to connect to OBS websockets", error.code, error.message);
}

// Put error message in console when connection closed
obs.on("ConnectionClosed", (error) => {
    console.log("[Error] OBS connection closed event.", error);
});

try {
    let thePromise = obs.callBatch(
        [
            {
                requestType: "SetMediaInputCursor",
                requestData: {
                    inputName: inputName,
                    mediaCursor: 1000
                }
            },

            {
                requestType: "SetInputVolume",
                requestData: {
                    inputName: inputName,
                    inputVolumeDb: 80
                }
            }
        ],
        {
            haltOnFailure: true,
            executionType: 'RequestBatchExecutionType::SerialRealtime' //This is invalid and it's what causes websocket disconnect
        }
    );

    // show promise state in console
    setInterval((a)=>console.log(a), 1500, thePromise);

    const response = await thePromise;

    console.log("We never get here");
    console.log(response);

} catch (error) {
    
    console.log("we never get here either");
    console.log(error);

}

console.log("end");

Script 2 (reconnection)

import { OBSWebSocket } from 'obs-websocket-js';

let url = 'ws://';
let pw = '';
let idParams = {rpcVersion: 1}

let inputName = "test track";


let obs = new OBSWebSocket();

// Connect

async function connect(url, pw, idParams) {
    try {
        let conInfo = await obs.connect(url, pw, idParams);
        console.log(`Connected to OBS websockets ${conInfo.obsWebSocketVersion} (using RPC ${conInfo.negotiatedRpcVersion})`);
    } catch (error) {
        console.error('Failed to connect to OBS websockets', error.code, error.message);
    }
}

await connect(url, pw, idParams);

// Put error message in console when connection closed
obs.on("ConnectionClosed", (error) => {
    console.log("[Error] OBS connection closed event, re-attempting connection.", error);
    connect(url, pw, idParams);
});

try {
    let thePromise = obs.callBatch(
        [
            {
                requestType: "SetMediaInputCursor",
                requestData: {
                    inputName: inputName,
                    mediaCursor: 1000
                }
            },

            {
                requestType: "SetInputVolume",
                requestData: {
                    inputName: inputName,
                    inputVolumeDb: 80
                }
            }
        ],
        {
            haltOnFailure: true,
            executionType: 'RequestBatchExecutionType::SerialRealtime' //This is invalid and it's what causes websocket disconnect
        }
    );

    // show promise state in console
    setInterval((a)=>console.log(a), 1500, thePromise);

    const response = await thePromise;

    console.log("We never get here");
    console.log(response);

} catch (error) {
    
    console.log("we never get here either");
    console.log(error);

}

console.log("end");
@eedefeed eedefeed changed the title The promise you get from callBatch() remains pending indefinitely if you use an invalid executionType promise (which causes a disconnect) The promise you get from callBatch() remains pending indefinitely if you use an invalid executionType (which causes a disconnect) Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant