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 bff269f
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 49 deletions.
80 changes: 41 additions & 39 deletions __tests__/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,55 +230,57 @@ describe('call API', () => {
expect(response.recordings).toBeDefined();
});

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

expect(response.call.settings.backstage.enabled).toBe(true);
},
});

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

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

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);
});

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('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', async () => {
const response = await call.delete({ hard: true });

expect(response.call.cid).toBe(call.cid);
});
});
});
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 bff269f

Please sign in to comment.