Skip to content

Class: MessagingService

modules/messaging.MessagingService

Service responsible for handling the messaging via NATS.

const { messagingService } = await initWithPrivateKeySigner(privateKey, rpcUrl);
messagingService.subscribeTo(...);

Table of contents

Constructors

Methods

Constructors

constructor

new MessagingService(_signerService)

Parameters

Name Type
_signerService SignerService

Methods

init

init(): Promise<void>

Returns

Promise<void>


publish

publish(subject, data): void

Publish a message with data to the given subject.

messagingService.publish('*.*.did:ethr:volta:0x00..0.ewf-volta', Uint8Array.from('Hello World'));

Parameters

Name Type Description
subject string message subject
data Uint8Array message data

Returns

void


subscribeTo

subscribeTo(options): Promise<undefined | number>

Subscribe to messages on the given subject.

messagingService.subscribeTo({
    subject: '*.*.did:ethr:volta:0x00..0.ewf-volta',
    messageHandler: (data) => console.log(data),
});

Parameters

Name Type Description
options SubscribeToOptions object with options

Returns

Promise<undefined | number>

subscription id


unsubscribeFrom

unsubscribeFrom(subscriptionId): Promise<void>

Unsubscribe from the given subscription id.

messagingService.unsubscribeFrom(55);

Parameters

Name Type Description
subscriptionId number subscription id

Returns

Promise<void>


create

Static create(signerService): Promise<MessagingService>

Parameters

Name Type
signerService SignerService

Returns

Promise<MessagingService>