From 3350c500b0622171a9c1f8121608bab4cf9ba20d Mon Sep 17 00:00:00 2001 From: Karol Konkol <56369082+Karolk99@users.noreply.github.com> Date: Fri, 6 Sep 2024 10:33:15 +0200 Subject: [PATCH] Allow for urls with the slash at the end (#39) ## Description Describe your changes in detail. ## Motivation and Context Why is this change required? What problem does it solve? If it fixes an open issue, please link to the issue here. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) --- examples/room-manager/src/index.ts | 2 +- examples/room-manager/src/room_service.ts | 2 +- examples/room-manager/src/rooms.ts | 46 ++-- packages/fishjam-openapi/src/generated/api.ts | 205 +++++++++++++++++- .../fishjam-openapi/src/generated/base.ts | 2 +- .../fishjam-openapi/src/generated/common.ts | 2 +- .../src/generated/configuration.ts | 2 +- .../fishjam-openapi/src/generated/index.ts | 2 +- 8 files changed, 231 insertions(+), 32 deletions(-) diff --git a/examples/room-manager/src/index.ts b/examples/room-manager/src/index.ts index 92ff29a..57eb486 100644 --- a/examples/room-manager/src/index.ts +++ b/examples/room-manager/src/index.ts @@ -22,7 +22,7 @@ const envToLogger = { test: false, }; -export const fastify = Fastify({ logger: envToLogger.development }); +export const fastify = Fastify({ logger: envToLogger.development, ignoreTrailingSlash: true }); async function setupServer() { await fastify.register(cors, { origin: '*' }); diff --git a/examples/room-manager/src/room_service.ts b/examples/room-manager/src/room_service.ts index e2e8452..0f77356 100644 --- a/examples/room-manager/src/room_service.ts +++ b/examples/room-manager/src/room_service.ts @@ -95,7 +95,7 @@ export class RoomService { if (!roomId) throw new RoomManagerError('Room not found'); const { peer, token } = await this.fishjamClient.createPeer(roomId, { - enableSimulcast: fastify.config.ENABLE_SIMULCAST, + enableSimulcast: fastify.config.ENABLE_SIMULCAST, metadata: { username } }); const user = { diff --git a/examples/room-manager/src/rooms.ts b/examples/room-manager/src/rooms.ts index 5fad912..fec16b5 100644 --- a/examples/room-manager/src/rooms.ts +++ b/examples/room-manager/src/rooms.ts @@ -1,4 +1,4 @@ -import { FastifyInstance } from 'fastify'; +import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; import { RoomService } from './room_service'; import { ServerMessage } from '@fishjam-cloud/js-server-sdk/proto'; import { peerEndpointSchema, QueryParams, startRecordingSchema } from './schema'; @@ -23,33 +23,29 @@ export async function roomsEndpoints(fastify: FastifyInstance) { const websocketUrl = removeTrailingSlash(url); const roomService = new RoomService(fastify.config.FISHJAM_URL, fastify.config.FISHJAM_SERVER_TOKEN); - fastify.get<{ Params: QueryParams }>( - '/:roomName/users/:username', - { schema: peerEndpointSchema }, - async (req, res) => { - const { - params: { roomName, username }, - } = req; - try { - const user = await roomService.findOrCreateUser(roomName, username); - return { ...user, url: websocketUrl }; - } catch (error: unknown) { - const [parsedError, errorCode] = parseError(error); - return res.status(errorCode).send(parsedError.detail); - } + const getUserHandler = async (req: FastifyRequest<{ Params: QueryParams }>, res: FastifyReply) => { + const { + params: { roomName, username }, + } = req; + try { + const user = await roomService.findOrCreateUser(roomName, username); + return { ...user, url: websocketUrl }; + } catch (error: unknown) { + const [parsedError, errorCode] = parseError(error); + return res.status(errorCode).send(parsedError.detail); } - ); + } - fastify.post<{ Params: { roomName: string } }>( - '/:roomName/start-recording', - { schema: startRecordingSchema }, - async (req, res) => { - throw new Error('Not yet implemented'); - } - ); + const startRecordingHandler = async (req: FastifyRequest<{ Params: { roomName: string } }>, res: FastifyReply) => { + throw new Error('Not yet implemented'); + }; - fastify.post<{ Body: ServerMessage }>('/webhook', async (req, res) => { + const webhookHandler = async (req: FastifyRequest<{ Body: ServerMessage }>, res: FastifyReply) => { await roomService.handleJellyfishMessage(req.body); return res.status(200).send(); - }); + }; + + fastify.get<{ Params: QueryParams }>('/:roomName/users/:username', { schema: peerEndpointSchema }, getUserHandler); + fastify.post<{ Params: { roomName: string } }>('/:roomName/start-recording', { schema: startRecordingSchema }, startRecordingHandler); + fastify.post<{ Body: ServerMessage }>('/webhook', webhookHandler); } diff --git a/packages/fishjam-openapi/src/generated/api.ts b/packages/fishjam-openapi/src/generated/api.ts index ed4bab0..1ccbcf5 100644 --- a/packages/fishjam-openapi/src/generated/api.ts +++ b/packages/fishjam-openapi/src/generated/api.ts @@ -4,7 +4,7 @@ * Fishjam Media Server * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * - * The version of the OpenAPI document: 0.6.3 + * The version of the OpenAPI document: 0.7.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -736,6 +736,12 @@ export interface PeerOptionsWebRTC { * @memberof PeerOptionsWebRTC */ 'enableSimulcast'?: boolean; + /** + * + * @type {{ [key: string]: any; }} + * @memberof PeerOptionsWebRTC + */ + 'metadata'?: { [key: string]: any; }; } /** * Informs about the peer status @@ -1016,6 +1022,32 @@ export interface SIPCredentials1 { */ 'username': string; } +/** + * Returns status information for the shutdown process of Fishjam. + * @export + * @interface ShutdownStatus + */ +export interface ShutdownStatus { + /** + * Informs if node is busy and cannot be shutdown + * @type {boolean} + * @memberof ShutdownStatus + */ + 'node_busy': boolean; +} +/** + * Returns status information for the shutdown process of Fishjam + * @export + * @interface ShutdownStatusResponse + */ +export interface ShutdownStatusResponse { + /** + * + * @type {ShutdownStatus} + * @memberof ShutdownStatusResponse + */ + 'data': ShutdownStatus; +} /** * Subscription config * @export @@ -1063,6 +1095,177 @@ export const TrackTypeEnum = { export type TrackTypeEnum = typeof TrackTypeEnum[keyof typeof TrackTypeEnum]; +/** + * DefaultApi - axios parameter creator + * @export + */ +export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * + * @summary Marks node as draining, making it the last in the load balancing order. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + drainNode: async (options: RawAxiosRequestConfig = {}): Promise => { + const localVarPath = `/shutdown/drain`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication authorization required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Returns status information for the shutdown process of Fishjam. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + shutdownStatus: async (options: RawAxiosRequestConfig = {}): Promise => { + const localVarPath = `/shutdown/status`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication authorization required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * DefaultApi - functional programming interface + * @export + */ +export const DefaultApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration) + return { + /** + * + * @summary Marks node as draining, making it the last in the load balancing order. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async drainNode(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.drainNode(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['DefaultApi.drainNode']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * + * @summary Returns status information for the shutdown process of Fishjam. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async shutdownStatus(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.shutdownStatus(options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['DefaultApi.shutdownStatus']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + } +}; + +/** + * DefaultApi - factory interface + * @export + */ +export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = DefaultApiFp(configuration) + return { + /** + * + * @summary Marks node as draining, making it the last in the load balancing order. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + drainNode(options?: any): AxiosPromise { + return localVarFp.drainNode(options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary Returns status information for the shutdown process of Fishjam. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + shutdownStatus(options?: any): AxiosPromise { + return localVarFp.shutdownStatus(options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * DefaultApi - object-oriented interface + * @export + * @class DefaultApi + * @extends {BaseAPI} + */ +export class DefaultApi extends BaseAPI { + /** + * + * @summary Marks node as draining, making it the last in the load balancing order. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public drainNode(options?: RawAxiosRequestConfig) { + return DefaultApiFp(this.configuration).drainNode(options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Returns status information for the shutdown process of Fishjam. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public shutdownStatus(options?: RawAxiosRequestConfig) { + return DefaultApiFp(this.configuration).shutdownStatus(options).then((request) => request(this.axios, this.basePath)); + } +} + + + /** * HealthApi - axios parameter creator * @export diff --git a/packages/fishjam-openapi/src/generated/base.ts b/packages/fishjam-openapi/src/generated/base.ts index 8983230..f3592aa 100644 --- a/packages/fishjam-openapi/src/generated/base.ts +++ b/packages/fishjam-openapi/src/generated/base.ts @@ -4,7 +4,7 @@ * Fishjam Media Server * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * - * The version of the OpenAPI document: 0.6.3 + * The version of the OpenAPI document: 0.7.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/packages/fishjam-openapi/src/generated/common.ts b/packages/fishjam-openapi/src/generated/common.ts index 10f5afc..4eab727 100644 --- a/packages/fishjam-openapi/src/generated/common.ts +++ b/packages/fishjam-openapi/src/generated/common.ts @@ -4,7 +4,7 @@ * Fishjam Media Server * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * - * The version of the OpenAPI document: 0.6.3 + * The version of the OpenAPI document: 0.7.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/packages/fishjam-openapi/src/generated/configuration.ts b/packages/fishjam-openapi/src/generated/configuration.ts index e57b3ac..8869fb0 100644 --- a/packages/fishjam-openapi/src/generated/configuration.ts +++ b/packages/fishjam-openapi/src/generated/configuration.ts @@ -4,7 +4,7 @@ * Fishjam Media Server * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * - * The version of the OpenAPI document: 0.6.3 + * The version of the OpenAPI document: 0.7.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/packages/fishjam-openapi/src/generated/index.ts b/packages/fishjam-openapi/src/generated/index.ts index 3abc424..2d6e456 100644 --- a/packages/fishjam-openapi/src/generated/index.ts +++ b/packages/fishjam-openapi/src/generated/index.ts @@ -4,7 +4,7 @@ * Fishjam Media Server * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * - * The version of the OpenAPI document: 0.6.3 + * The version of the OpenAPI document: 0.7.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).