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

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

Args are not optional when using a Callback. #131

Closed BarryCarlyon closed 5 years ago

BarryCarlyon commented 5 years ago

Description:

This does not work

obs.send('GetSpecialSources', function(e, d) {
    if (e) {
        console.log(e);
    } else {
        console.log('Special', d);
    }
})

This does work

obs.send('GetSpecialSources', {}, function(e, d) {
    if (e) {
        console.log(e);
    } else {
        console.log('Special', d);
    }
})

I added some weird logging™ to OBSWebSocket.js

And observed that the callback function was attempted to be stringified and passed to OBS over the socket…

You cannot have a callback, and have the arguments be optional.

Versions Used (if applicable):

haganbmj commented 5 years ago

Sure that's how multiple params work. I suppose I could look at the 2nd param type and make some determination on that. You should be fine to pass undefined if you really don't want to compose an empty object.

BarryCarlyon commented 5 years ago

Usually in nodeJS/javascript you can do

function(callback() {});
function(args, callback() {});

or

function(foo, args, callback() {});

or

function(foo, callback() {});

And function checks whats passed to it to determine if whats passed is what it expects. So if args is optional, then I just do

function(thing, callback() {});

It's not a problem just the docs are wrong as if I should pass undefined then it's not optional, as I'm passing undefined

BarryCarlyon commented 5 years ago

I'd have to check my code and see what I'm using.

I believe I'm primarily using callbacks so it would be a breaking change for me.

Not a problem but it does reduce user choice/flexibility.

BarryCarlyon commented 5 years ago

Seems good to me!