Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@truffle/dashboard-message-bus-client
Advanced tools
Readme
@truffle/dashboard-message-bus-client
This library is used for connecting with the message bus that powers the Truffle dashboard.
import { DashboardMessageBusClient } from "@truffle/dashboard-message-bus-client";
const client = new DashboardMessageBusClient({ port, host });
const message = {
type: "helloWorld",
id: new DateTime().getTime(),
payload: {
hello: "world"
}
};
const messageLifecycle = await client.publish(message);
Publishing a message creates a lifecycle for that message. The lifecycle is tracked by the publisher as an object of type PublishedMessageLifecycle<MessageType, ResponseType>
.
Publish message lifecycles terminate in one of three ways:
To enable request/response messaging (e.g. proxied JSON-RPC messages), publish lifecycles contain a promise that resolves when a response to the originally published message is received.
const response = await publishLifecycle.response;
To allow for fire-and-forget messages (e.g. event data), simply call the
abandon
method on the lifecycle object.
Important: If the abandon
method of the publish lifecycle is not called,
the process will hang forever on exit, as it will forever be waiting for a
response that will never arive.
await messageLifecycle.abandon();
The consumer of a published message often will need to perform some longer
running operation as a result of that message. To cancel that work, or to
communicate to the consumer that the message is no longer valid, simply call
cancel
on the publish lifecycle.
await messageLifecycle.invalidate();
Messages can be consumed by calling the subscribe
method of the client. The
subscribe
method returns a DashboardMessageSubscription
object. This object
emits message
events whenever messages are received that match the
subscription's filter.
Received messages are wrapped up in a lifecycle object similar to the one used for publishing messages, however there's only a single respond
method.
import { DashboardMessageBusClient } from "@truffle/dashboard-message-bus-client";
const client = new DashboardMessageBusClient({ port, host });
// omitting the type string in the options object will return a subscription
// for all messages
const subscription = client.subscribe({
type: "helloWorld"
});
subscription.on("message", receivedMessageLifecycle => {
const helloTarget = receivedMessageLifecycle.message.payload.hello;
if (helloTarget.toLowerCase() === "world") {
// respond by passing your response payload directly to the response
await receivedMessageLifecycle.respond({
someArbitraryResponse:
"Why hello there. Pleased to make your acquaintance"
});
} else {
await receivedMessageLifecycle.respond({
error: `I'm sorry, you have the wrong number. This is world, not "${helloTarget}"`
});
}
});
FAQs
Client library for accessing the truffle dashboard's message bus
The npm package @truffle/dashboard-message-bus-client receives a total of 7,999 weekly downloads. As such, @truffle/dashboard-message-bus-client popularity was classified as popular.
We found that @truffle/dashboard-message-bus-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.