![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@xmpp/component
Advanced tools
Much like a client, a component is an entity that connects to an XMPP server. However components are granted special permissions. If you'd like to extend an XMPP server with additional features a component is a good choice.
See XEP-0114: Jabber Component Protocol for details.
@xmpp/component
package includes a minimal set of features to connect /authenticate securely and reliably.
npm install @xmpp/component @xmpp/debug
const { component, xml, jid } = require("@xmpp/component");
const debug = require("@xmpp/debug");
const xmpp = component({
service: "xmpp://localhost:5347",
domain: "component.localhost",
password: "mysecretcomponentpassword",
});
debug(xmpp, true);
xmpp.on("error", (err) => {
console.error(err);
});
xmpp.on("offline", () => {
console.log("offline");
});
xmpp.on("stanza", async (stanza) => {
if (stanza.is("message")) {
await xmpp.stop();
}
});
xmpp.on("online", async (address) => {
console.log("online as", address.toString());
// Sends a chat message to itself
const message = xml(
"message",
{ type: "chat", to: address },
xml("body", {}, "hello world"),
);
await xmpp.send(message);
});
xmpp.start().catch(console.error);
See xml package
See jid package
options
<Object
>
service
<string>
The service to connect to, accepts an URI. eg. xmpp://localhost:5347
domain
<string>
Domain of the component. eg. component.localhost
password
<string>
Password to use to authenticate with the service.Returns an xmpp object.
xmpp
is an instance of EventEmitter.
online
indicates that xmpp
is authenticated and addressable. It is emitted every time there is a successfull (re)connection.
offline
indicates that xmpp
disconnected and no automatic attempt to reconnect will happen (after calling xmpp.stop()
).
Additional status:
connecting
: Socket is connectingconnect
: Socket is connectedopening
: Stream is openingopen
: Stream is openclosing
: Stream is closingclose
: Stream is closeddisconnecting
: Socket is disconnectingdisconnect
: Socket is disconnectedYou can read the current status using the status
property.
const isOnline = xmpp.status === "online";
You can listen for status change using the status
event.
status
Emitted when the status changes.
xmpp.on("status", (status) => {
console.debug(status);
});
error
Emitted when an error occurs. For connection errors, xmpp
will reconnect on its own using @xmpp/reconnect however a listener MUST be attached to avoid uncaught exceptions.
<Error>
xmpp.on("error", (error) => {
console.error(error);
});
stanza
Emitted when a stanza is received and parsed.
// Simple echo bot example
xmpp.on("stanza", (stanza) => {
console.log(stanza.toString());
if (!stanza.is("message")) return;
const { to, from } = stanza.attrs;
stanza.attrs.from = to;
stanza.attrs.to = from;
xmpp.send(stanza);
});
online
Emitted when connected, authenticated and ready to receive/send stanzas.
xmpp.on("online", (address) => {
console.log("online as", address.toString());
});
offline
Emitted when the connection is closed an no further attempt to reconnect will happen, usually after xmpp.stop().
xmpp.on("offline", () => {
console.log("offline");
});
Starts the connection. Attempts to reconnect will automatically happen if it cannot connect or gets disconnected.
xmpp.start().catch(console.error);
xmpp.on("online", (address) => {
console.log("online", address.toString());
});
Returns a promise that resolves if the first attempt succeed or rejects if the first attempt fails.
Stops the connection and prevent any further auto reconnect/retry.
xmpp.stop().catch(console.error);
xmpp.on("offline", () => {
console.log("offline");
});
Returns a promise that resolves once the stream closes and the socket disconnects.
Sends a stanza.
xmpp.send(xml("presence")).catch(console.error);
Returns a promise that resolves once the stanza is serialized and written to the socket or rejects if any of those fails.
Sends multiple stanzas.
Here is an example sending the same text message to multiple recipients.
const message = "Hello";
const recipients = ["romeo@example.com", "juliet@example.com"];
const stanzas = recipients.map((address) =>
xml("message", { to: address, type: "chat" }, xml("body", null, message)),
);
xmpp.sendMany(stanzas).catch(console.error);
Returns a promise that resolves once all the stanzas have been sent.
If you need to send a stanza to multiple recipients we recommend using Extended Stanza Addressing instead.
See @xmpp/reconnect.
FAQs
XMPP component for JavaScript
The npm package @xmpp/component receives a total of 131 weekly downloads. As such, @xmpp/component popularity was classified as not popular.
We found that @xmpp/component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.