DanielDoes anyone know how I can set a timeout for the tcp socket in xmpp.js?
Danielwhatever the default timeout for connection establishment is seems to be too low for my usecase
Sam WhitedDoes xmpp.js have literally no documentation except a readme with an example or two in some of the repos?
Sam WhitedDaniel: 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
Sam WhitedNo idea if that's ever exposed in an easier way though, I couldn't find a timeout option or anything
Sam WhitedThe reconnect stuff has a timeout too, but again, no docs on how to set it that I can find.
Danielyes xmpp.js isn’t exaclty well documented. but from a quick research it is the only java script xmpp library that can do tcp
Danielyes i've started to suspect that the problem i ran into was actually the reconnect timeout. not the socket time out
Sam WhitedWhat'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.
Sam WhitedBut I can't for the life of me think of a package name that conveys "internal functions for contributors to make implementing XEPs easier"
jonas’to me, sendIQ sounds like something which shouldn’t be a separate package but just part of the core api
Sam WhitedThe core API does have that it just doesn't do all this extra stuff.
defanorI think those usually go into something like "util" or "common", if it has to be generic.
Sam Whiteddefanor: 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.
Sam WhitedThen again, maybe that's what that specific example function is.
Sam WhitedYah, 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.
Sam WhitedOr 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)
Sam Whitedjonas’: 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.
Sam WhitedSo 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.
ZashWhat does it do? Send an iq and return the response?
Sam WhitedMore 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)
ZashI think this is called SendIQ or similar in all libraries I've seen.
sonnyDaniel, 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
Sam WhitedZash: SendIQ is already a thing, unfortunately. This is "HigherLevelSendIQ" :)
Zash`await QueryResponse(SendIQ(···))` 🤷
Sam WhitedMaybe 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.
sonnyDaniel, the documentation for reconnect is here https://github.com/xmppjs/xmpp.js/tree/master/packages/reconnect
Danieljust so i understand. delay != timeout?
Danielso if i'm seeing a timeout error on connect it's probably the socket?
sonnycan you share the exact error?
sonny(sounds like it yes)
sonnynot sure what the problem exactly is but you could try changing client.timeout - the default is 2000 (ms) which is probably too low
Danielsonny, what's that timeout being used for?
sonnyif you get a TimeoutError on `.start()` then that's the culprit
sonnyif you get a `TimeoutError` on `.start()` then that's the culprit
sonnyplease 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
sonnyplease 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
Sam WhitedMocked 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)