|
1 |
| -import type { SocketStream } from "@fastify/websocket"; |
2 | 1 | import { type Static, Type } from "@sinclair/typebox";
|
3 | 2 | import type { FastifyInstance } from "fastify";
|
4 | 3 | import { StatusCodes } from "http-status-codes";
|
5 | 4 | import { TransactionDB } from "../../../shared/db/transactions/db";
|
6 |
| -import { logger } from "../../../shared/utils/logger"; |
7 | 5 | import { createCustomError } from "../../middleware/error";
|
8 | 6 | import { standardResponseSchema } from "../../schemas/shared-api-schemas";
|
9 | 7 | import {
|
10 | 8 | TransactionSchema,
|
11 | 9 | toTransactionSchema,
|
12 | 10 | } from "../../schemas/transaction";
|
13 |
| -import { |
14 |
| - findOrAddWSConnectionInSharedState, |
15 |
| - formatSocketMessage, |
16 |
| - getStatusMessageAndConnectionStatus, |
17 |
| - onClose, |
18 |
| - onError, |
19 |
| - onMessage, |
20 |
| -} from "../../utils/websocket"; |
21 | 11 |
|
22 | 12 | // INPUT
|
23 | 13 | const requestSchema = Type.Object({
|
@@ -96,43 +86,6 @@ export async function getTransactionStatusRoute(fastify: FastifyInstance) {
|
96 | 86 | result: toTransactionSchema(transaction),
|
97 | 87 | });
|
98 | 88 | },
|
99 |
| - wsHandler: async (connection: SocketStream, request) => { |
100 |
| - const { queueId } = request.params; |
101 |
| - |
102 |
| - findOrAddWSConnectionInSharedState(connection, queueId, request); |
103 |
| - |
104 |
| - const transaction = await TransactionDB.get(queueId); |
105 |
| - const returnData = transaction ? toTransactionSchema(transaction) : null; |
106 |
| - |
107 |
| - const { message, closeConnection } = |
108 |
| - await getStatusMessageAndConnectionStatus(returnData); |
109 |
| - |
110 |
| - connection.socket.send(await formatSocketMessage(returnData, message)); |
111 |
| - |
112 |
| - if (closeConnection) { |
113 |
| - connection.socket.close(); |
114 |
| - return; |
115 |
| - } |
116 |
| - |
117 |
| - connection.socket.on("error", (error) => { |
118 |
| - logger({ |
119 |
| - service: "websocket", |
120 |
| - level: "error", |
121 |
| - message: "Websocket error", |
122 |
| - error, |
123 |
| - }); |
124 |
| - |
125 |
| - onError(error, connection, request); |
126 |
| - }); |
127 |
| - |
128 |
| - connection.socket.on("message", async (_message, _isBinary) => { |
129 |
| - onMessage(connection, request); |
130 |
| - }); |
131 |
| - |
132 |
| - connection.socket.on("close", () => { |
133 |
| - onClose(connection, request); |
134 |
| - }); |
135 |
| - }, |
136 | 89 | });
|
137 | 90 | }
|
138 | 91 |
|
|
0 commit comments