xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.18k stars 372 forks source link

Please add methods to retrieve connection options. #888

Closed voger closed 2 years ago

voger commented 3 years ago

Is your feature request related to a problem? Please describe. It would be nice if the connection object could have some methods to retrieve connection details such as the address or domain. They are indeed values provided by the user during connection initialization but may be useful later in the application runtime.

They could be saved by the application somewhere but retrieving them directly from the connection object would offer a central place of storing them, instead of having them stored twice, one copy in the connection object and another in some application data structure. That would probably require additional code to ensure that both copies are in sync.

Also, the domain option is optional and can be derived from service. It would be nice to retrieve that derived domain instead of having to rewrite the logic to extract the domain from the service.

Describe the solution you'd like As per package`s client example


const { client, xml } = require("@xmpp/client");
const debug = require("@xmpp/debug");

const xmpp = client({
  service: "ws://localhost:5280/xmpp-websocket",
  domain: "localhost",
  resource: "example",
  username: "username",
  password: "password",
});

// returns "ws://localhost:5280/xmpp-websocket"
xmpp.getService()

// returns "localhost"
xmpp.getDomain()

// returns "example"
xmpp.getResource()

// returns "username"
xmpp.getUsername()

// Not sure about this one
// returns "password"
xmpp.getPassword()
sonnyp commented 3 years ago

Can you share a use case for this?