Skip to content

Commit

Permalink
feat: implement delete call endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Jun 20, 2024
1 parent 2d81816 commit bfdccfa
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 108 deletions.
206 changes: 108 additions & 98 deletions __tests__/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createTestClient } from './create-test-client';
import { StreamCall } from '../src/StreamCall';
import { StreamClient } from '../src/StreamClient';
import {
VideoDeleteCallResponse,
VideoRecordSettingsRequestModeEnum,
VideoRecordSettingsRequestQualityEnum,
} from '../src/gen/video';
Expand Down Expand Up @@ -158,127 +159,136 @@ describe('call API', () => {
);
});

describe('recording', () => {
it('enable call recording', async () => {
let response = await call.update({
settings_override: {
recording: {
mode: VideoRecordSettingsRequestModeEnum.DISABLED,
audio_only: true,
},
it('enable call recording', async () => {
let response = await call.update({
settings_override: {
recording: {
mode: VideoRecordSettingsRequestModeEnum.DISABLED,
audio_only: true,
},
});
let settings = response.call.settings.recording;
},
});
let settings = response.call.settings.recording;

expect(settings.mode).toBe(VideoRecordSettingsRequestModeEnum.DISABLED);
expect(settings.mode).toBe(VideoRecordSettingsRequestModeEnum.DISABLED);

response = await call.update({
settings_override: {
recording: {
mode: VideoRecordSettingsRequestModeEnum.AVAILABLE,
},
response = await call.update({
settings_override: {
recording: {
mode: VideoRecordSettingsRequestModeEnum.AVAILABLE,
},
});
},
});

settings = response.call.settings.recording;
expect(settings.mode).toBe(VideoRecordSettingsRequestModeEnum.AVAILABLE);
settings = response.call.settings.recording;
expect(settings.mode).toBe(VideoRecordSettingsRequestModeEnum.AVAILABLE);

response = await call.update({
settings_override: {
recording: {
audio_only: false,
quality: VideoRecordSettingsRequestQualityEnum._1080P,
mode: VideoRecordSettingsRequestModeEnum.AUTO_ON,
},
response = await call.update({
settings_override: {
recording: {
audio_only: false,
quality: VideoRecordSettingsRequestQualityEnum._1080P,
mode: VideoRecordSettingsRequestModeEnum.AUTO_ON,
},
});

settings = response.call.settings.recording;
expect(settings.audio_only).toBe(false);
expect(settings.quality).toBe(
VideoRecordSettingsRequestQualityEnum._1080P,
);
},
});

it('start recording', async () => {
// somewhat dummy test, we should do a proper test in the future where we join a call and start recording
await expect(() => call.startRecording()).rejects.toThrowError(
'Stream error code 4: StartRecording failed with error: "cannot record inactive call"',
);
});
settings = response.call.settings.recording;
expect(settings.audio_only).toBe(false);
expect(settings.quality).toBe(VideoRecordSettingsRequestQualityEnum._1080P);
});

it('stop recording', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() => call.stopRecording()).rejects.toThrowError(
'Stream error code 4: StopRecording failed with error: "call is not being recorded"',
);
});
it('start recording', async () => {
// somewhat dummy test, we should do a proper test in the future where we join a call and start recording
await expect(() => call.startRecording()).rejects.toThrowError(
'Stream error code 4: StartRecording failed with error: "cannot record inactive call"',
);
});

it('delete recording', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() =>
call.deleteRecording({ session: 'test', filename: 'test' }),
).rejects.toThrowError(
`Stream error code 16: DeleteRecording failed with error: "recording doesn't exist"`,
);
});
it('stop recording', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() => call.stopRecording()).rejects.toThrowError(
'Stream error code 4: StopRecording failed with error: "call is not being recorded"',
);
});

it('query recordings', async () => {
// somewhat dummy test, we should do a proper test in the future
const response = await call.listRecordings();
it('delete recording', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() =>
call.deleteRecording({ session: 'test', filename: 'test' }),
).rejects.toThrowError(
`Stream error code 16: DeleteRecording failed with error: "recording doesn't exist"`,
);
});

expect(response.recordings).toBeDefined();
it('query recordings', async () => {
// somewhat dummy test, we should do a proper test in the future
const response = await call.listRecordings();

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

it('enable backstage mode', async () => {
const response = await call.update({
settings_override: {
backstage: {
enabled: true,
},
},
});

describe('streaming', () => {
it('enable backstage mode', async () => {
const response = await call.update({
settings_override: {
backstage: {
enabled: true,
},
},
});
expect(response.call.settings.backstage.enabled).toBe(true);
});

expect(response.call.settings.backstage.enabled).toBe(true);
});
it('go live', async () => {
const response = await call.goLive();

it('go live', async () => {
const response = await call.goLive();
expect(response.call.backstage).toBe(false);
});

expect(response.call.backstage).toBe(false);
});
it('stop live', async () => {
const response = await call.stopLive();

it('stop live', async () => {
const response = await call.stopLive();
expect(response.call.backstage).toBe(true);
});

expect(response.call.backstage).toBe(true);
});
});
it('start transcribing', async () => {
// somewhat dummy test, we should do a proper test in the future where we join a call and start recording
await expect(() => call.startTranscription()).rejects.toThrowError(
'Stream error code 4: StartTranscription failed with error: "cannot transcribe inactive call"',
);
});

describe('transcriptions', () => {
it('start transcribing', async () => {
// somewhat dummy test, we should do a proper test in the future where we join a call and start recording
await expect(() => call.startTranscription()).rejects.toThrowError(
'Stream error code 4: StartTranscription failed with error: "cannot transcribe inactive call"',
);
});
it('stop transcribing', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() => call.stopTranscription()).rejects.toThrowError(
'Stream error code 4: StopTranscription failed with error: "call is not being transcribed"',
);
});

it('stop transcribing', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() => call.stopTranscription()).rejects.toThrowError(
'Stream error code 4: StopTranscription failed with error: "call is not being transcribed"',
);
});
it('delete transcription', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() =>
call.deleteTranscription({ session: 'test', filename: 'test' }),
).rejects.toThrowError(
`Stream error code 16: DeleteTranscription failed with error: "transcription doesn't exist"`,
);
});

it('delete transcription', async () => {
// somewhat dummy test, we should do a proper test in the future
await expect(() =>
call.deleteTranscription({ session: 'test', filename: 'test' }),
).rejects.toThrowError(
`Stream error code 16: DeleteTranscription failed with error: "transcription doesn't exist"`,
);
it('delete call', async () => {
let response: VideoDeleteCallResponse;
try {
response = await call.delete({ hard: true });
} catch (e) {
// the first request fails on backend sometimes
// retry it
await new Promise<void>((resolve) => {
setTimeout(() => resolve(), 2000);
});
});

response = await call.delete({ hard: true });
}

expect(response.duration).toBeDefined();
});
});
4 changes: 2 additions & 2 deletions __tests__/external-recording-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('external storage CRUD API', () => {
const response = await client.video.createExternalStorage({
name: storageName,
bucket: 'test',
storage_type: 'test',
storage_type: 'abs',
});

expect(response).toBeDefined();
Expand All @@ -32,7 +32,7 @@ describe('external storage CRUD API', () => {
const newBucket = 'new bucket';
const response = await client.video.updateExternalStorage(storageName, {
bucket: newBucket,
storage_type: 'test',
storage_type: 'abs',
});

expect(response.bucket).toBe('new bucket');
Expand Down
16 changes: 14 additions & 2 deletions src/StreamCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
GetCallStatsRequest,
ProductvideoApi,
VideoBlockUserRequest,
VideoDeleteCallRequest,
VideoGetOrCreateCallRequest,
VideoGoLiveRequest,
VideoMuteUsersRequest,
Expand All @@ -28,21 +29,32 @@ export class StreamCall {

constructor(
private readonly streamClient: StreamClient,
private readonly type: string,
private readonly id: string,
public readonly type: string,
public readonly id: string,
) {
this.baseRequest = { id: this.id, type: this.type };
const configuration = this.streamClient.getConfiguration('video');
this.apiClient = new ProductvideoApi(configuration);
}

get cid() {
return `${this.type}:${this.id}`;
}

blockUser = (videoBlockUserRequest: VideoBlockUserRequest) => {
return this.apiClient.blockUser({
...this.baseRequest,
videoBlockUserRequest,
});
};

delete = (videoDeleteCallRequest?: VideoDeleteCallRequest) => {
return this.apiClient.deleteCall({
...this.baseRequest,
videoDeleteCallRequest: videoDeleteCallRequest ?? null,
});
};

endCall = () => {
return this.apiClient.endCall({ ...this.baseRequest });
};
Expand Down
65 changes: 64 additions & 1 deletion src/gen/video/apis/ProductvideoApi.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: v116.0.0
* The version of the OpenAPI document: v120.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -28,6 +28,8 @@ import type {
VideoCreateExternalStorageResponse,
VideoCreateGuestRequest,
VideoCreateGuestResponse,
VideoDeleteCallRequest,
VideoDeleteCallResponse,
VideoDeleteExternalStorageResponse,
VideoDeleteRecordingResponse,
VideoDeleteTranscriptionResponse,
Expand Down Expand Up @@ -116,6 +118,12 @@ export interface CreateGuestRequest {
videoCreateGuestRequest: VideoCreateGuestRequest | null;
}

export interface DeleteCallRequest {
type: string;
id: string;
videoDeleteCallRequest: VideoDeleteCallRequest | null;
}

export interface DeleteCallTypeRequest {
name: string;
}
Expand Down Expand Up @@ -650,6 +658,61 @@ export class ProductvideoApi extends runtime.BaseAPI {
return await response.value();
}

/**
* Sends events: - call.deleted Required permissions: - DeleteCall
* Delete Call
*/
async deleteCallRaw(requestParameters: DeleteCallRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<VideoDeleteCallResponse>> {
if (requestParameters.type === null || requestParameters.type === undefined) {
throw new runtime.RequiredError('type','Required parameter requestParameters.type was null or undefined when calling deleteCall.');
}

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

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

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/call/{type}/{id}/delete`.replace(`{${"type"}}`, encodeURIComponent(String(requestParameters.type))).replace(`{${"id"}}`, encodeURIComponent(String(requestParameters.id))),
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: requestParameters.videoDeleteCallRequest,
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
* Sends events: - call.deleted Required permissions: - DeleteCall
* Delete Call
*/
async deleteCall(requestParameters: DeleteCallRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<VideoDeleteCallResponse> {
const response = await this.deleteCallRaw(requestParameters, initOverrides);
return await response.value();
}

/**
*
* Delete Call Type
Expand Down
Loading

0 comments on commit bfdccfa

Please sign in to comment.