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

Args are not optional when using a Callback. #131

Closed
BarryCarlyon opened this issue Jan 8, 2019 · 6 comments
Closed

Args are not optional when using a Callback. #131

BarryCarlyon opened this issue Jan 8, 2019 · 6 comments

Comments

@BarryCarlyon
Copy link

BarryCarlyon commented Jan 8, 2019

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):

  • obs-websocket-js version: 2.0.1
  • obs-websocket plugin version: 4.4.0 (and tested with 4.5.0
  • obs-studio version: 22.0.2
  • node version: 10.14.2
@BarryCarlyon BarryCarlyon changed the title Args are not optional? Args are not optional when using a Callback. Jan 8, 2019
@haganbmj
Copy link
Collaborator

haganbmj commented Jan 9, 2019

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
Copy link
Author

BarryCarlyon commented Jan 9, 2019

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
Copy link
Author

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
Copy link
Author

Seems good to me!

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

3 participants
@BarryCarlyon @haganbmj and others