Skip to content
Snippets Groups Projects
Unverified Commit 8055e2ba authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

fix: replace socket.io with web socket

parent ba81f724
No related branches found
No related tags found
No related merge requests found
Pipeline #64433 passed with stages
in 13 minutes and 16 seconds
......@@ -21,7 +21,6 @@ NATS_SUBJECTS="connections.*,proofs.*,credentials.*,credentials.definition.*,cre
GATEWAY_HTTP_PORT=8081
GATEWAY_TCP_PORT=8881
GATEWAY_SOCKET_EVENT_NAME=message
GATEWAY_MESSAGE_PATTERN=webhook
GATEWAY_HOST=0.0.0.0
......
......@@ -126,9 +126,9 @@ Example:
## Usage via Postman
1. Import postman collection from the repo
2. Connect to Socket.io on the gateway address, to listen for responses with [postman](https://learning.postman.com/docs/sending-requests/websocket/websocket) event is "message"
2. Connect to Web Socket on the gateway address, to listen for responses
3. Make a request
4. Response will be sent to the Socket.io
4. Response will be sent to the Web Socket
## Send Didcomm messages between two OCMs
......
......@@ -26,7 +26,8 @@ export class AppController {
2,
)}`,
);
this.eventsGateway.server.emit(this.gatewayConfig.socketEventName, dto);
this.eventsGateway.sentEvent(dto);
return "ok";
}
}
import { WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
import { Server } from "socket.io";
import { Server, WebSocket } from "ws";
import { CloudEventDto } from "@ocm-engine/dtos";
@WebSocketGateway()
export class EventsGateway {
@WebSocketServer()
server: Server;
sentEvent<T>(dto: CloudEventDto<T>) {
this.server.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(dto));
}
});
}
}
......@@ -12,10 +12,12 @@ import { MicroserviceOptions, Transport } from "@nestjs/microservices";
import { ConfigService } from "@nestjs/config";
import { IGateway } from "@ocm-engine/config";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { WsAdapter } from "@nestjs/platform-ws";
import * as fs from "fs";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useWebSocketAdapter(new WsAdapter(app));
const configService = app.get(ConfigService);
const gatewayConfig = configService.get<IGateway>("gateway")!;
......@@ -24,7 +26,7 @@ async function bootstrap() {
app.setGlobalPrefix(globalPrefix);
app.enableShutdownHooks();
const microservice = app.connectMicroservice<MicroserviceOptions>({
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.TCP,
options: {
host: gatewayConfig.host,
......
......@@ -20,7 +20,6 @@ NATS_SUBJECTS="connections.*,proofs.*,credentials.*,schemas.*,messages.*"
GATEWAY_HTTP_PORT=8081
GATEWAY_TCP_PORT=8881
GATEWAY_SOCKET_EVENT_NAME=message
GATEWAY_MESSAGE_PATTERN=webhook
GATEWAY_HOST=gateway-holder
......
......@@ -20,7 +20,6 @@ NATS_SUBJECTS="connections.*,proofs.*,credentials.*,schemas.*"
GATEWAY_HTTP_PORT=8081
GATEWAY_TCP_PORT=8881
GATEWAY_SOCKET_EVENT_NAME=message
GATEWAY_MESSAGE_PATTERN=webhook
GATEWAY_HOST=gateway-holder
......
......@@ -20,7 +20,6 @@ NATS_SUBJECTS="connections.*,proofs.*,credentials.*,credentials.definition.*,cre
GATEWAY_HTTP_PORT=8081
GATEWAY_TCP_PORT=8881
GATEWAY_SOCKET_EVENT_NAME=message
GATEWAY_MESSAGE_PATTERN=webhook
GATEWAY_HOST=gateway-issuer
......
......@@ -20,7 +20,6 @@ NATS_SUBJECTS="connections.*,proofs.*,credentials.*,schemas.*"
GATEWAY_HTTP_PORT=8081
GATEWAY_TCP_PORT=8881
GATEWAY_SOCKET_EVENT_NAME=message
GATEWAY_MESSAGE_PATTERN=webhook
GATEWAY_HOST=gateway-issuer
......
......@@ -7,7 +7,6 @@ export const gatewayConfig = registerAs(
(): IGateway => ({
httpPort: parseInt(process.env["GATEWAY_HTTP_PORT"]!),
tcpPort: parseInt(process.env["GATEWAY_TCP_PORT"]!),
socketEventName: process.env["GATEWAY_SOCKET_EVENT_NAME"]!,
messagePattern: process.env["GATEWAY_MESSAGE_PATTERN"]!,
host: process.env["GATEWAY_HOST"]!,
}),
......
export interface IGateway {
httpPort: number;
tcpPort: number;
socketEventName: string;
messagePattern: string;
host: string;
}
......@@ -3,7 +3,6 @@ import Joi from "joi";
export const gatewaySchema = Joi.object({
GATEWAY_HTTP_PORT: Joi.string().required(),
GATEWAY_TCP_PORT: Joi.string().required(),
GATEWAY_SOCKET_EVENT_NAME: Joi.string().required(),
GATEWAY_MESSAGE_PATTERN: Joi.string().required(),
GATEWAY_HOST: Joi.string().required(),
});
......@@ -14,24 +14,21 @@
"build:pm:production": "nx run proof-manager:build:production",
"build:gw": "nx run gateway:build:development --parallel=3",
"build:gw:production": "nx run gateway:build:production",
"serve:all": "concurrently \"yarn serve:agent\" \"yarn serve:cm\" \"yarn serve:am\" \"yarn serve:pm\" \"yarn serve:gw\"",
"serve:agent": "nx run agent:serve:development",
"serve:cm": "nx run connection-manager:serve:development",
"serve:am": "nx run attestation-manager:serve:development",
"serve:pm": "nx run proof-manager:serve:development",
"serve:gw": "nx run gateway:serve:development",
"infra": "cd compose && docker-compose --profile issuer --profile holder up -d --build",
"infra:down": "cd compose && docker-compose --profile issuer --profile holder down",
"infra:status" : "cd compose && docker-compose ps -a",
"infra:status": "cd compose && docker-compose ps -a",
"infra:issuer": "cd compose && docker-compose --profile issuer up -d --build",
"infra:holder": "cd compose && docker-compose --profile holder up -d --build",
"infra:issuer:stop": "cd compose && docker-compose --profile issuer stop",
"infra:holder:stop": "cd compose && docker-compose --profile holder stop",
"infra:local": "cd compose && docker-compose -f=docker-compose.infra.yml up -d",
"infra:local:stop": "cd compose && docker-compose -f=docker-compose.infra.yml stop",
"infra:simple": "cd compose && docker-compose -f docker-compose.simple.yml up -d"
},
"private": true,
......@@ -45,7 +42,7 @@
"@nestjs/core": "^9.0.0",
"@nestjs/microservices": "^9.4.2",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/platform-socket.io": "^9.4.2",
"@nestjs/platform-ws": "^10.1.3",
"@nestjs/websockets": "^9.4.2",
"async-retry": "^1.3.3",
"axios": "^1.0.0",
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment