Skip to content

Commit

Permalink
feat: implement external recording endpoints for video
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Feb 12, 2024
1 parent b3ba400 commit 6a9f49a
Show file tree
Hide file tree
Showing 11 changed files with 722 additions and 5 deletions.
48 changes: 48 additions & 0 deletions __tests__/external-recording-storage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { v4 as uuidv4 } from 'uuid';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';

describe('external storage CRUD API', () => {
let client: StreamClient;
const storageName = `streamnodetest${uuidv4()}`;

beforeAll(() => {
client = createTestClient();
});

it('create', async () => {
const response = await client.video.createExternalStorage({
name: storageName,
bucket: 'test',
storage_type: 'test',
});

expect(response).toBeDefined();
});

it('read', async () => {
const readResponse = await client.video.listExternalStorages();

expect(readResponse.external_storages).toBeDefined();
expect(readResponse.external_storages[storageName]).toBeDefined();
});

it('update', async () => {
const newBucket = 'new bucket';
const response = await client.video.updateExternalStorage(storageName, {
bucket: newBucket,
storage_type: 'test',
});

expect(response.bucket).toBe('new bucket');
});

it('delete', async () => {
const response = await client.video.deleteExternalStorage({
name: storageName,
});

expect(response).toBeDefined();
});
});
8 changes: 6 additions & 2 deletions src/StreamCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
VideoUpdateCallMembersRequest,
VideoUpdateUserPermissionsRequest,
VideoQueryMembersRequest,
VideoStartRecordingRequest,
} from './gen/video';
import { OmitTypeId } from './types';

Expand Down Expand Up @@ -93,8 +94,11 @@ export class StreamCall {
return this.apiClient.startHLSBroadcasting({ ...this.baseRequest });
};

startRecording = () => {
return this.apiClient.startRecording({ ...this.baseRequest });
startRecording = (request?: VideoStartRecordingRequest) => {
return this.apiClient.startRecording({
...this.baseRequest,
videoStartRecordingRequest: request || {},

Check failure on line 100 in src/StreamCall.ts

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
});
};

startTranscription = () => {
Expand Down
37 changes: 37 additions & 0 deletions src/StreamVideoClient.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { StreamCall } from './StreamCall';
import { StreamClient } from './StreamClient';
import {
CheckExternalStorageRequest,
DefaultApi,
DeleteCallTypeRequest,
DeleteExternalStorageRequest,
GetCallTypeRequest,
ServerSideApi,
SettingsApi,
VideoCreateCallTypeRequest,
VideoCreateExternalStorageRequest,
VideoQueryCallsRequest,
VideoUpdateCallTypeRequest,
VideoUpdateExternalStorageRequest,
} from './gen/video';

export class StreamVideoClient {
private readonly apiClient: DefaultApi;
private readonly videoServerSideApiClient: ServerSideApi;
private readonly settingsApi: SettingsApi;

constructor(private readonly streamClient: StreamClient) {
const configuration = this.streamClient.getConfiguration('video');
this.apiClient = new DefaultApi(configuration);
this.settingsApi = new SettingsApi(configuration);
this.videoServerSideApiClient = new ServerSideApi(configuration);
}

Expand Down Expand Up @@ -57,4 +64,34 @@ export class StreamVideoClient {
videoUpdateCallTypeRequest,
});
};

listExternalStorages = () => {
return this.settingsApi.listExternalStorage();
};

createExternalStorage = (
videoCreateExternalStorageRequest: VideoCreateExternalStorageRequest,
) => {
return this.settingsApi.createExternalStorage({
videoCreateExternalStorageRequest,
});
};

deleteExternalStorage = (request: DeleteExternalStorageRequest) => {
return this.settingsApi.deleteExternalStorage(request);
};

updateExternalStorage = (
name: string,
videoUpdateExternalStorageRequest: VideoUpdateExternalStorageRequest,
) => {
return this.videoServerSideApiClient.updateExternalStorage({
name,
videoUpdateExternalStorageRequest,
});
};

checkExternalStorage = (request: CheckExternalStorageRequest) => {
return this.videoServerSideApiClient.checkExternalStorage(request);
};
}
1 change: 1 addition & 0 deletions src/gen/video/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.openapi-generator-ignore
apis/DefaultApi.ts
apis/ServerSideApi.ts
apis/SettingsApi.ts
apis/index.ts
index.ts
models/index.ts
Expand Down
11 changes: 10 additions & 1 deletion src/gen/video/apis/DefaultApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Stream API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: v96.8.0-ingress-dbg.5
* The version of the OpenAPI document: v98.0.2-ingress-test.3
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -42,6 +42,7 @@ import type {
VideoSendEventRequest,
VideoSendEventResponse,
VideoStartHLSBroadcastingResponse,
VideoStartRecordingRequest,
VideoStartRecordingResponse,
VideoStartTranscriptionResponse,
VideoStopHLSBroadcastingResponse,
Expand Down Expand Up @@ -145,6 +146,7 @@ export interface StartHLSBroadcastingRequest {
export interface StartRecordingRequest {
type: string;
id: string;
videoStartRecordingRequest: VideoStartRecordingRequest | null;
}

export interface StartTranscriptionRequest {
Expand Down Expand Up @@ -1041,10 +1043,16 @@ export class DefaultApi extends runtime.BaseAPI {
throw new runtime.RequiredError('id','Required parameter requestParameters.id was null or undefined when calling startRecording.');
}

if (requestParameters.videoStartRecordingRequest === null || requestParameters.videoStartRecordingRequest === undefined) {
throw new runtime.RequiredError('videoStartRecordingRequest','Required parameter requestParameters.videoStartRecordingRequest was null or undefined when calling startRecording.');
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && this.configuration.apiKey) {
headerParameters["Stream-Auth-Type"] = this.configuration.apiKey("Stream-Auth-Type"); // stream-auth-type authentication
}
Expand All @@ -1062,6 +1070,7 @@ export class DefaultApi extends runtime.BaseAPI {
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: requestParameters.videoStartRecordingRequest,
}, initOverrides);

return new runtime.JSONApiResponse(response);
Expand Down
109 changes: 108 additions & 1 deletion src/gen/video/apis/ServerSideApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Stream API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: v96.8.0-ingress-dbg.5
* The version of the OpenAPI document: v98.0.2-ingress-test.3
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -16,15 +16,22 @@
import * as runtime from '../runtime';
import type {
VideoAPIError,
VideoCheckExternalStorageResponse,
VideoCreateCallTypeRequest,
VideoCreateCallTypeResponse,
VideoGetCallTypeResponse,
VideoListCallTypeResponse,
VideoResponse,
VideoUpdateCallTypeRequest,
VideoUpdateCallTypeResponse,
VideoUpdateExternalStorageRequest,
VideoUpdateExternalStorageResponse,
} from '../models';

export interface CheckExternalStorageRequest {
name: string;
}

export interface CreateCallTypeRequest {
videoCreateCallTypeRequest: VideoCreateCallTypeRequest | null;
}
Expand All @@ -42,11 +49,60 @@ export interface UpdateCallTypeRequest {
videoUpdateCallTypeRequest: VideoUpdateCallTypeRequest | null;
}

export interface UpdateExternalStorageRequest {
name: string;
videoUpdateExternalStorageRequest: VideoUpdateExternalStorageRequest | null;
}

/**
*
*/
export class ServerSideApi extends runtime.BaseAPI {

/**
*
* Check External Storage
*/
async checkExternalStorageRaw(requestParameters: CheckExternalStorageRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<VideoCheckExternalStorageResponse>> {
if (requestParameters.name === null || requestParameters.name === undefined) {
throw new runtime.RequiredError('name','Required parameter requestParameters.name was null or undefined when calling checkExternalStorage.');
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && this.configuration.apiKey) {
headerParameters["Stream-Auth-Type"] = this.configuration.apiKey("Stream-Auth-Type"); // stream-auth-type authentication
}

if (this.configuration && this.configuration.apiKey) {
queryParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
}

if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // JWT authentication
}

const response = await this.request({
path: `/video/external_storage/{name}/check`.replace(`{${"name"}}`, encodeURIComponent(String(requestParameters.name))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
*
* Check External Storage
*/
async checkExternalStorage(requestParameters: CheckExternalStorageRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<VideoCheckExternalStorageResponse> {
const response = await this.checkExternalStorageRaw(requestParameters, initOverrides);
return await response.value();
}

/**
*
* Create Call Type
Expand Down Expand Up @@ -273,4 +329,55 @@ export class ServerSideApi extends runtime.BaseAPI {
return await response.value();
}

/**
*
* Update External Storage
*/
async updateExternalStorageRaw(requestParameters: UpdateExternalStorageRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<VideoUpdateExternalStorageResponse>> {
if (requestParameters.name === null || requestParameters.name === undefined) {
throw new runtime.RequiredError('name','Required parameter requestParameters.name was null or undefined when calling updateExternalStorage.');
}

if (requestParameters.videoUpdateExternalStorageRequest === null || requestParameters.videoUpdateExternalStorageRequest === undefined) {
throw new runtime.RequiredError('videoUpdateExternalStorageRequest','Required parameter requestParameters.videoUpdateExternalStorageRequest was null or undefined when calling updateExternalStorage.');
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && this.configuration.apiKey) {
headerParameters["Stream-Auth-Type"] = this.configuration.apiKey("Stream-Auth-Type"); // stream-auth-type authentication
}

if (this.configuration && this.configuration.apiKey) {
queryParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
}

if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // JWT authentication
}

const response = await this.request({
path: `/video/external_storage/{name}`.replace(`{${"name"}}`, encodeURIComponent(String(requestParameters.name))),
method: 'PUT',
headers: headerParameters,
query: queryParameters,
body: requestParameters.videoUpdateExternalStorageRequest,
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
*
* Update External Storage
*/
async updateExternalStorage(requestParameters: UpdateExternalStorageRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<VideoUpdateExternalStorageResponse> {
const response = await this.updateExternalStorageRaw(requestParameters, initOverrides);
return await response.value();
}

}
Loading

0 comments on commit 6a9f49a

Please sign in to comment.