Skip to content

Commit

Permalink
feat(messaging): disable nats messaging method for Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Harasz committed Nov 26, 2021
1 parent 0712343 commit febabd2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
Expand Up @@ -7,23 +7,9 @@
### Enumeration members

- [Nats](modules_messaging_messaging_types.MessagingMethod.md#nats)
- [SmartContractStorage](modules_messaging_messaging_types.MessagingMethod.md#smartcontractstorage)
- [WebRTC](modules_messaging_messaging_types.MessagingMethod.md#webrtc)

## Enumeration members

### Nats

**Nats** = `"nats"`

___

### SmartContractStorage

**SmartContractStorage** = `"smartContractStorage"`

___

### WebRTC

**WebRTC** = `"webRTC"`
Expand Up @@ -13,7 +13,7 @@

### messagingMethod

**messagingMethod**: [`MessagingMethod`](../enums/modules_messaging_messaging_types.MessagingMethod.md)
**messagingMethod**: [`Nats`](../enums/modules_messaging_messaging_types.MessagingMethod.md#nats)

___

Expand Down
8 changes: 7 additions & 1 deletion src/modules/messaging/messaging.service.ts
Expand Up @@ -2,6 +2,7 @@ import { Codec, connect, JSONCodec, NatsConnection, Subscription } from "nats.ws
import { getMessagingConfig } from "../../config/messaging.config";
import { IMessage, MessagingMethod, NATS_EXCHANGE_TOPIC } from "./messaging.types";
import { SignerService } from "../signer/signer.service";
import { executionEnvironment, ExecutionEnvironment } from "../../utils/detectEnvironment";

export class MessagingService {
private _jsonCodec: Codec<any>;
Expand All @@ -19,6 +20,11 @@ export class MessagingService {
}

async init() {
// Currently there is no supported messaging method for node.js
if (executionEnvironment() === ExecutionEnvironment.NODE) {
return;
}

const { messagingMethod, natsServerUrl } = getMessagingConfig()[this._signerService.chainId];
if (natsServerUrl && messagingMethod === MessagingMethod.Nats) {
this._jsonCodec = JSONCodec();
Expand Down Expand Up @@ -78,6 +84,6 @@ export class MessagingService {
}

async publish(subject: string, data: Uint8Array) {
this._natsConnection.publish(subject, data);
this._natsConnection?.publish(subject, data);
}
}
5 changes: 3 additions & 2 deletions src/modules/messaging/messaging.types.ts
@@ -1,7 +1,8 @@
export enum MessagingMethod {
Nats = "nats",
WebRTC = "webRTC",
SmartContractStorage = "smartContractStorage",
// Not implemented yet
// WebRTC = "webRTC",
// SmartContractStorage = "smartContractStorage",
}

export interface IMessage {
Expand Down

0 comments on commit febabd2

Please sign in to comment.