Skip to content

Commit

Permalink
Implement end call endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Jun 20, 2024
1 parent 25a34f6 commit d7009da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
8 changes: 7 additions & 1 deletion __tests__/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

describe('call API', () => {
let client: StreamClient;
const callId = `call${uuidv4()}`;
const callId = `callnodetest${uuidv4()}`;
let call: StreamCall;

beforeAll(async () => {
Expand Down Expand Up @@ -280,5 +280,11 @@ describe('call API', () => {
);
});
});

it('delete', async () => {
const response = await call.delete({ hard: true });

expect(response.call.cid).toBe(call.cid);
});
});
});
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,14 +29,18 @@ 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,
Expand All @@ -51,6 +56,13 @@ export class StreamCall {
return this.apiClient.getCall({ ...(request ?? {}), ...this.baseRequest });
};

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

Check failure on line 62 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
});
};

getOrCreate = (videoGetOrCreateCallRequest?: VideoGetOrCreateCallRequest) => {
return this.apiClient.getOrCreateCall({
...this.baseRequest,
Expand Down
14 changes: 14 additions & 0 deletions test-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ const cleanupBlockLists = async () => {
);
};

const cleanupCalls = async () => {
const calls = (await client.video.queryCalls()).calls;
const testCalls = Object.keys(calls).filter((t) =>
t.startsWith("callnodetest"),
);

await Promise.all(
testCalls.map((t) =>
client.video.call(t.call.type, t.call.id).delete({ hard: true }),
),
);
};

const cleanupCallTypes = async () => {
const callTypes = (await client.video.listCallTypes()).call_types;
const customCallTypes = Object.keys(callTypes).filter(
Expand Down Expand Up @@ -127,6 +140,7 @@ const cleanup = async () => {
await cleanUpRoles();
await cleanUpUsers();
await cleanupExternalStorage();
await cleanupCalls();
};

cleanup().then(() => {
Expand Down

0 comments on commit d7009da

Please sign in to comment.