jdev - 2021-02-15

  1. Daniel

    Does anyone know how I can set a timeout for the tcp socket in xmpp.js?

  2. Daniel

    whatever the default timeout for connection establishment is seems to be too low for my usecase

  3. Sam Whited

    Does xmpp.js have literally no documentation except a readme with an example or two in some of the repos?

  4. Sam Whited

    Daniel: this.Transport seems to have a Socket in it that I assume is a net.Socket which you can call setTimeout on https://nodejs.org/docs/latest-v15.x/api/net.html#net_socket_settimeout_timeout_callback

  5. Sam Whited

    No idea if that's ever exposed in an easier way though, I couldn't find a timeout option or anything

  6. Sam Whited

    The reconnect stuff has a timeout too, but again, no docs on how to set it that I can find.

  7. Daniel

    yes xmpp.js isn’t exaclty well documented. but from a quick research it is the only java script xmpp library that can do tcp

  8. Daniel

    yes i've started to suspect that the problem i ran into was actually the reconnect timeout. not the socket time out

  9. flow

    sonny, ↑

  10. Sam Whited

    What's a good name for a package that's only purpose is to be used internally by devs to create other packages. Eg. lots of packages have something that sends and IQ, unmarshals the response into a value, etc. so this package would have the generic "SendIQ" logic that does all that, handles errors, etc. so that you don't have to rewrite it every time.

  11. Sam Whited

    But I can't for the life of me think of a package name that conveys "internal functions for contributors to make implementing XEPs easier"

  12. jonas’

    to me, sendIQ sounds like something which shouldn’t be a separate package but just part of the core api

  13. Sam Whited

    The core API does have that it just doesn't do all this extra stuff.

  14. defanor

    I think those usually go into something like "util" or "common", if it has to be generic.

  15. Sam Whited

    defanor: those don't really convey the intent, I generally think if you've created a package called "util" it's code smell and is just going to become an unmanageable dumping ground for random functions that should have been put somewhere else.

  16. Sam Whited

    Then again, maybe that's what that specific example function is.

  17. Sam Whited

    Yah, maybe if I'm having such trouble thinking of a name and defining what this package is for it's the same thing and I should think of somewhere else for this shared logic to go. I dunno, I'm struggling with this.

  18. Sam Whited

    Or maybe this particular example really should be core functionality even though it's sort of higher level than everything else. I just hate to add more IQ related methods to the session type which already has the confusingly named EncodeIQ, EncodeIQElement, SendIQ, and SendIQElement (which all do more or less the same thing with minor differences)

  19. Sam Whited

    jonas’: thinking about it more, you're absolutely right. This will be useful to more than just package authors and should be on the core session stuff.

  20. Sam Whited

    So I guess the question becomes "What should those methods be called?" I can never think what conveys the intent. "MarshalIQ" maybe? "MarshalAndDecodeIQ" is a bit long. I dunno.

  21. Sam Whited


  22. Zash

    What does it do? Send an iq and return the response?

  23. Sam Whited

    More or less (as opposed to the existing SendIQ and EncodeIQ functions which just return the XML stream, this returns an actual concrete type that the user specified or an error representing the IQ error)

  24. Zash

    I think this is called SendIQ or similar in all libraries I've seen.

  25. sonny

    Daniel, setting a TCP timeout is not exposed publicaly but I'd be happy to implement that for you - meanwhile I can give you a workaround if you like

  26. Sam Whited

    Zash: SendIQ is already a thing, unfortunately. This is "HigherLevelSendIQ" :)

  27. Zash

    Naming things!

  28. Zash

    `await QueryResponse(SendIQ(···))` 🤷

  29. Sam Whited

    Maybe this is too high level for the main library. Eg. the http library doesn't unmarshal JSON for you, it just returns the body and you get to interpret it how you want. But then I'm back to not knowing where to put this.

  30. sonny

    Daniel, the documentation for reconnect is here https://github.com/xmppjs/xmpp.js/tree/master/packages/reconnect

  31. Daniel

    just so i understand. delay != timeout?

  32. Daniel

    so if i'm seeing a timeout error on connect it's probably the socket?

  33. sonny

    can you share the exact error?

  34. sonny

    (sounds like it yes)

  35. sonny

    not sure what the problem exactly is but you could try changing client.timeout - the default is 2000 (ms) which is probably too low

  36. Daniel

    sonny, what's that timeout being used for?

  37. sonny

    if you get a TimeoutError on `.start()` then that's the culprit

  38. sonny

    if you get a `TimeoutError` on `.start()` then that's the culprit

  39. sonny

    please open an issue with more details - it will be easier to figure out what the issue is and find out what needs to be documented

  40. sonny

    please open an issue with more details - it will be easier to figure out what the issue is and find out what needs to be documented or changed

  41. Sam Whited

    Mocked it up and called it "MarshalIQ, MarshalIQElement, IterIQ, and IterIQElement"… that's a lot of new methods and it still feels wrong and confusingly named somehow (the extra "Iter" methods don't matter, I just realized that I'd need them too because a few things like roster fetches work differently and iterate over the children instead of just returning them all in one go like most IQs do)

  42. Sam Whited

    Organization is hard.