1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-24 10:23:28 +00:00

Listen for websockets

This commit is contained in:
2020-03-29 17:52:28 +02:00
parent a58452af3e
commit 70a5c910d2
3 changed files with 48 additions and 7 deletions

View File

@ -16,6 +16,9 @@ import { CommentsController } from "./CommentsController";
import { LikesController } from "./LikesController";
import { SurveyController } from "./SurveyController";
import { SettingsController } from "./SettingsController";
import { Request } from "express";
import * as ws from 'ws';
import { UserWS } from "./UserWebSocketController";
/**
* Controllers routes
@ -25,7 +28,8 @@ import { SettingsController } from "./SettingsController";
export enum RouteType {
POST, // Default
GET
GET,
WS, // Special: WebSockets
}
export interface Route {
@ -33,10 +37,16 @@ export interface Route {
path: string,
cb: (req : RequestHandler) => Promise<void> | void,
needLogin ?: boolean, // Default = true
// Specific for websockets
wsCallback ?: (req: Request, ws: ws) => Promise<void> | void
}
export const Routes : Route[] = [
// Main user websocket
{type: RouteType.WS, path: "/ws", cb: () => {throw Error()}, wsCallback: UserWS },
// Welcome controller
{type: RouteType.GET, path: "/", cb: WelcomeController.HomeMessage, needLogin: false},

View File

@ -0,0 +1,11 @@
/**
* User websocket controller
*
* @author Pierre Hubert
*/
import * as ws from 'ws';
import { Request } from 'express';
export async function UserWS(req: Request, ws: ws) {
}