From b75d6e6f7b8c37bee39ad77b46cc514e57741dd7 Mon Sep 17 00:00:00 2001 From: Karol Konkol Date: Mon, 4 Nov 2024 19:20:40 +0100 Subject: [PATCH] Add refresh peer token to FishjamClient API --- packages/fishjam-openapi/openapi.sh | 2 +- packages/fishjam-openapi/src/generated/api.ts | 108 +++++++++++++++++- .../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 +- packages/js-server-sdk/src/client.ts | 7 ++ 7 files changed, 119 insertions(+), 6 deletions(-) mode change 100644 => 100755 packages/fishjam-openapi/openapi.sh diff --git a/packages/fishjam-openapi/openapi.sh b/packages/fishjam-openapi/openapi.sh old mode 100644 new mode 100755 index 5333574..b9d1404 --- a/packages/fishjam-openapi/openapi.sh +++ b/packages/fishjam-openapi/openapi.sh @@ -19,6 +19,6 @@ echo "Generating code for $1...\n" cd $ROOTDIR \ && npx @openapitools/openapi-generator-cli generate \ - -i https://raw.githubusercontent.com/fishjam-cloud/fishjam/$1/openapi.yaml?token=$2 \ + -i https://raw.githubusercontent.com/fishjam-cloud/fishjam/refs/heads/$1/openapi.yaml?token=$2 \ -g typescript-axios \ -o ./src/generated diff --git a/packages/fishjam-openapi/src/generated/api.ts b/packages/fishjam-openapi/src/generated/api.ts index 1c3c9e5..4c66fdd 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.8.0 + * The version of the OpenAPI document: 0.9.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -743,6 +743,32 @@ export interface PeerOptionsWebRTC { */ 'metadata'?: { [key: string]: any; }; } +/** + * Response containing new peer token + * @export + * @interface PeerRefreshTokenResponse + */ +export interface PeerRefreshTokenResponse { + /** + * + * @type {PeerRefreshTokenResponseData} + * @memberof PeerRefreshTokenResponse + */ + 'data': PeerRefreshTokenResponseData; +} +/** + * + * @export + * @interface PeerRefreshTokenResponseData + */ +export interface PeerRefreshTokenResponseData { + /** + * Token for authorizing websocket connection + * @type {string} + * @memberof PeerRefreshTokenResponseData + */ + 'token': string; +} /** * Informs about the peer status * @export @@ -2085,6 +2111,48 @@ export const RoomApiAxiosParamCreator = function (configuration?: Configuration) + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Refresh peer token + * @param {string} roomId Room ID + * @param {string} id Peer id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + refreshToken: async (roomId: string, id: string, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'roomId' is not null or undefined + assertParamExists('refreshToken', 'roomId', roomId) + // verify required parameter 'id' is not null or undefined + assertParamExists('refreshToken', 'id', id) + const localVarPath = `/room/{room_id}/peer/{id}/refresh_token` + .replace(`{${"room_id"}}`, encodeURIComponent(String(roomId))) + .replace(`{${"id"}}`, encodeURIComponent(String(id))); + // 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}; @@ -2257,6 +2325,20 @@ export const RoomApiFp = function(configuration?: Configuration) { const localVarOperationServerBasePath = operationServerMap['RoomApi.getRoom']?.[localVarOperationServerIndex]?.url; return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, + /** + * + * @summary Refresh peer token + * @param {string} roomId Room ID + * @param {string} id Peer id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async refreshToken(roomId: string, id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.refreshToken(roomId, id, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['RoomApi.refreshToken']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, /** * * @summary Subscribe component to the tracks of peers or components @@ -2365,6 +2447,17 @@ export const RoomApiFactory = function (configuration?: Configuration, basePath? getRoom(roomId: string, options?: any): AxiosPromise { return localVarFp.getRoom(roomId, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary Refresh peer token + * @param {string} roomId Room ID + * @param {string} id Peer id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + refreshToken(roomId: string, id: string, options?: any): AxiosPromise { + return localVarFp.refreshToken(roomId, id, options).then((request) => request(axios, basePath)); + }, /** * * @summary Subscribe component to the tracks of peers or components @@ -2486,6 +2579,19 @@ export class RoomApi extends BaseAPI { return RoomApiFp(this.configuration).getRoom(roomId, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @summary Refresh peer token + * @param {string} roomId Room ID + * @param {string} id Peer id + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof RoomApi + */ + public refreshToken(roomId: string, id: string, options?: RawAxiosRequestConfig) { + return RoomApiFp(this.configuration).refreshToken(roomId, id, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @summary Subscribe component to the tracks of peers or components diff --git a/packages/fishjam-openapi/src/generated/base.ts b/packages/fishjam-openapi/src/generated/base.ts index bc8b77b..904a3c9 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.8.0 + * The version of the OpenAPI document: 0.9.0 * * * 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 880b525..a4a2369 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.8.0 + * The version of the OpenAPI document: 0.9.0 * * * 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 a4a9d85..57a9e1b 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.8.0 + * The version of the OpenAPI document: 0.9.0 * * * 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 c9e37fd..6051410 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.8.0 + * The version of the OpenAPI document: 0.9.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/packages/js-server-sdk/src/client.ts b/packages/js-server-sdk/src/client.ts index 1d2eef5..bdc92fe 100644 --- a/packages/js-server-sdk/src/client.ts +++ b/packages/js-server-sdk/src/client.ts @@ -63,4 +63,11 @@ export class FishjamClient { async deleteRoom(roomId: string): Promise { await this.roomApi.deleteRoom(roomId).catch((error) => raiseExceptions(error, 'room')); } + + async refreshPeerToken(roomId: string, peerId: string): Promise { + const refreshTokenResponse = await this.roomApi + .refreshToken(roomId, peerId) + .catch((error) => raiseExceptions(error, 'peer')); + return refreshTokenResponse.data.data.token; + } }