diff --git a/frontend/src/api/generated/apis/OpenapiOtherApi.ts b/frontend/src/api/generated/apis/OpenapiOtherApi.ts index fda4f60..2a44e6e 100644 --- a/frontend/src/api/generated/apis/OpenapiOtherApi.ts +++ b/frontend/src/api/generated/apis/OpenapiOtherApi.ts @@ -130,6 +130,43 @@ export interface SigninRequest { */ export class OpenapiOtherApi extends runtime.BaseAPI { + /** + */ + async apiChatSocketIoGetRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/api/chat/socket.io`; + + const response = await this.request({ + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }, initOverrides); + + // CHANGED: Handle all status codes defined in the OpenAPI spec, not just 2xx responses + // This allows typed access to error responses (4xx, 5xx) and other status codes. + // The code routes responses based on the actual HTTP status code and returns + // appropriately typed ApiResponse wrappers for each status code. + if (response.status === 200) { + // No body response for status 200 + return new runtime.VoidApiResponse(response); + } + // CHANGED: Throw error if status code is not handled by any of the defined responses + // This ensures all code paths return a value and provides clear error messages for unexpected status codes + // Only throw if responses were defined but none matched the actual status code + throw new runtime.ResponseError(response, `Unexpected status code: ${response.status}. Expected one of: 200`); + } + + /** + */ + async apiChatSocketIoGet(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + await this.apiChatSocketIoGetRaw(initOverrides); + } + /** */ async chatTestRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { diff --git a/frontend/src/chat/chat.css b/frontend/src/chat/chat.css index 4441176..549112b 100644 --- a/frontend/src/chat/chat.css +++ b/frontend/src/chat/chat.css @@ -74,6 +74,11 @@ text-center z-50; } +.mainboxDisplay button { + @apply + cursor-pointer; +} + p { @apply text-black diff --git a/frontend/src/pages/chat/chat.ts b/frontend/src/pages/chat/chat.ts index a83f478..ed68f34 100644 --- a/frontend/src/pages/chat/chat.ts +++ b/frontend/src/pages/chat/chat.ts @@ -8,23 +8,32 @@ import io from "socket.io-client"; // const socket = io("wss://localhost:8888"); -const socket = io("wss://local.maix.me:8888", { +const socket = io("wss://localhost:8888", { path: "/api/chat/socket.io/", - secure: true, + secure: false, transports: ["websocket"], }); // Listen for the 'connect' event socket.on("connect", async () => { - console.log("Connected to the server: ", socket.id); + console.log("I AM Connected to the server: ", socket.id); // Emit a custom event 'coucou' with some data socket.emit("coucou", { message: "Hello Nigel from coucou!" }); - console.log('sent coucou'); + console.log('sent console.log coucou'); // Send a message to the server socket.send("Hello from the client: " + `${socket.id}`); }); +// Listen for messages from the server +socket.on("MsgObjectServer", (data) => { + console.log("Message from server:", data); +}); + + + + + type Providers = { name: string, diff --git a/src/chat/openapi.json b/src/chat/openapi.json index bcebf94..d10eca0 100644 --- a/src/chat/openapi.json +++ b/src/chat/openapi.json @@ -8,6 +8,15 @@ "schemas": {} }, "paths": { + "/api/chat/socket.io": { + "get": { + "responses": { + "200": { + "description": "Default Response" + } + } + } + }, "/api/chat/test": { "get": { "operationId": "chatTest", diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 9591eef..1995e41 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -5,8 +5,8 @@ import * as db from '@shared/database'; import * as auth from '@shared/auth'; import * as swagger from '@shared/swagger'; import * as utils from '@shared/utils'; -import { Server } from 'socket.io'; import useSocketIo from 'fastify-socket.io'; +import { setupSocketIo } from "./socket"; declare const __SERVICE_NAME: string; @@ -15,17 +15,6 @@ const plugins = import.meta.glob('./plugins/**/*.ts', { eager: true }); // @ts-expect-error: import.meta.glob is a vite thing. Typescript doesn't know this... const routes = import.meta.glob('./routes/**/*.ts', { eager: true }); -// When using .decorate you have to specify added properties for Typescript -declare module 'fastify' { - interface FastifyInstance { - io: Server<{ - hello: (message: string) => string, - coucou: (data: { message: string }) => void, - message: (msg: string) => void, - }> - } -} - const app: FastifyPluginAsync = async (fastify, opts): Promise => { void opts; await fastify.register(utils.useMakeResponse); @@ -49,21 +38,9 @@ const app: FastifyPluginAsync = async (fastify, opts): Promise => { void fastify.register(fastifyMultipart, {}); fastify.get('/monitoring', () => 'Ok'); - fastify.ready((err) => { - if (err) throw err; - - fastify.io.on('connection', (socket) => { - console.info('Socket connected!', socket.id); - socket.on('hello', (value) => { - console.log(`GOT HELLO ${value}`); - return 'hi'; - }); - socket.on('message', (value) => console.log(`GOT MESSAGE ${value}`)); - socket.on('coucou', (value) => console.log(`GOT COUCOU ${value.message}`)); - }, - ); - - }); + // Setup Socket.io + setupSocketIo(fastify); + }; export default app; diff --git a/src/chat/src/routes/nginx-chat.ts b/src/chat/src/routes/nginx-chat.ts index 710385b..f660495 100644 --- a/src/chat/src/routes/nginx-chat.ts +++ b/src/chat/src/routes/nginx-chat.ts @@ -7,18 +7,12 @@ import { Socket } from 'socket.io'; import * as fsocketio from 'fastify-socket.io'; -const fastify = Fastify(); +// const fastify = Fastify(); -const io = new Server(fastify.server, { - path: '/app/chat/socket.io/', - cors: { origin: '*' }, -}); - - -io.on('connection', (socket: Socket) => { - console.log('testing'); - console.log(`Client connected: ${socket.id}`); -}); +// const io = new Server(fastify.server, { +// path: '/app/chat/socket.io/', +// cors: { origin: '*' }, +// }); export const ChatRes = { @@ -33,18 +27,17 @@ export const ChatRes = { export type ChatResType = MakeStaticResponse; const route: FastifyPluginAsync = async (fastify): Promise => { - /* await fastify.register(fsocketio.default); + await fastify.register(fsocketio.default); + + // fastify.get('/api/chat/socket.io', (req, reply) => { - fastify.get('/api/chat/socket.io', (req, reply) => { - console.log('GOT SOCKET ?!'); + // console.log('Socket.io endpoint hit'); + // reply.send({ status: 'ok' }); - const socket = (fastify as any).io; - socket.emit('hello'); - socket.on('message', (data: any) => console.log(data, `socketID: ${socket.id}`)); - socket.once('message', () => socket.send('connected succesfully')); - socket.once('coucou', (data: any) => console.log(data)); - }); - */ + // }); + + + fastify.get( diff --git a/src/chat/src/socket.ts b/src/chat/src/socket.ts new file mode 100644 index 0000000..b5bd25d --- /dev/null +++ b/src/chat/src/socket.ts @@ -0,0 +1,35 @@ +import { Server } from 'socket.io'; + +// When using .decorate you have to specify added properties for Typescript +declare module 'fastify' { + interface FastifyInstance { + io: Server<{ + hello: (message: string) => string, + MsgObjectServer: (data: { message: string }) => void, + message: (msg: string) => void, + }> + } +} + +export function setupSocketIo(fastify: import('fastify').FastifyInstance): void { + +fastify.ready((err) => { + if (err) throw err; + + fastify.io.on('connection', (socket) => { + console.info('Socket connected!', socket.id); + socket.on('hello', (value) => { + return 'hi'; + }); + socket.emit("MsgObjectServer", {message: `THIS IS A SERVER MESSAGE`}); + socket.on('message', (value) => console.log(`GOT MESssSAGE ${value}`)); + socket.on('MsgObjectServer', (value) => console.log(`GOT COUCOU ${value.message}`)); + },); + }); +}; + + + + + + diff --git a/src/openapi.json b/src/openapi.json index 4327973..45994b0 100644 --- a/src/openapi.json +++ b/src/openapi.json @@ -1190,6 +1190,18 @@ ] } }, + "/api/chat/socket.io": { + "get": { + "responses": { + "200": { + "description": "Default Response" + } + }, + "tags": [ + "openapi_other" + ] + } + }, "/api/chat/test": { "get": { "operationId": "chatTest",