Skip to content

Commit

Permalink
chore: update fastify webscocket
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypa committed Apr 23, 2024
1 parent 0fb85ab commit f018fb9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 22 deletions.
111 changes: 94 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"dependencies": {
"@aicore/libcommonutils": "1.0.20",
"@aicore/libmysql": "1.0.41",
"@fastify/websocket": "8.3.1",
"@fastify/websocket": "10.0.1",
"ajv": "8.12.0",
"fastify": "4.26.2",
"uuid": "9.0.1"
Expand Down
8 changes: 4 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import fastify from "fastify";
import websocket from "@fastify/websocket";
import * as websocket from "@fastify/websocket";
import {getConfigs} from "./utils/configs.js";
import LibMySql from "@aicore/libmysql";
import {createTable, getCreatTableSchema} from './api/createTable.js';
Expand Down Expand Up @@ -46,10 +46,10 @@ server.register(websocket, {

/* Registering a websocket handler. */
server.register(async function (fastify) {
fastify.get('/ws/', {websocket: true}, (connection /* SocketStream */, _req /* FastifyRequest */) => {
connection.socket.on('message', async message => {
fastify.get('/ws/', {websocket: true}, (socket /* SocketStream */, _req /* FastifyRequest */) => {
socket.on('message', async message => {
const response = await processesMessage(JSON.parse(message));
connection.socket.send(JSON.stringify(response));
socket.send(JSON.stringify(response));
});
});
});
Expand Down

0 comments on commit f018fb9

Please sign in to comment.