Skip to content

Commit

Permalink
Allow for urls with the slash at the end (#39)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
Karolk99 authored Sep 6, 2024
1 parent 1009852 commit 3350c50
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/room-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '*' });
Expand Down
2 changes: 1 addition & 1 deletion examples/room-manager/src/room_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
46 changes: 21 additions & 25 deletions examples/room-manager/src/rooms.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
}
205 changes: 204 additions & 1 deletion packages/fishjam-openapi/src/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<RequestArgs> => {
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<RequestArgs> => {
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<void>> {
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<ShutdownStatusResponse>> {
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<void> {
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<ShutdownStatusResponse> {
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
Expand Down
2 changes: 1 addition & 1 deletion packages/fishjam-openapi/src/generated/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion packages/fishjam-openapi/src/generated/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion packages/fishjam-openapi/src/generated/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion packages/fishjam-openapi/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 3350c50

Please sign in to comment.