Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <hello@internxt.com>",
"version": "1.15.4",
"version": "1.15.5",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/meet/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
import { basicHeaders, headersWithToken } from '../shared/headers';
import { HttpClient } from '../shared/http/client';
import { CreateCallResponse, JoinCallPayload, JoinCallResponse, UsersInCallResponse } from './types';
import { CreateCallResponse, JoinCallPayload, JoinCallResponse, LeaveCallPayload, UsersInCallResponse } from './types';

export class Meet {
private readonly client: HttpClient;
Expand All @@ -28,10 +28,10 @@ export class Meet {
return this.client.post<JoinCallResponse>(`call/${callId}/users/join`, { ...payload }, headers);
}

async leaveCall(callId: string): Promise<void> {
async leaveCall(callId: string, payload?: LeaveCallPayload): Promise<void> {
const headers = this.apiSecurity?.token ? this.headersWithToken() : this.basicHeaders();

return this.client.post<void>(`call/${callId}/users/leave`, {}, headers);
return this.client.post<void>(`call/${callId}/users/leave`, payload ? { ...payload } : {}, headers);
}

async getCurrentUsersInCall(callId: string): Promise<UsersInCallResponse[]> {
Expand Down
4 changes: 4 additions & 0 deletions src/meet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface JoinCallResponse {
appId: string;
}

export interface LeaveCallPayload {
userId: string;
}

export interface UsersInCallResponse {
userId: string;
name: string;
Expand Down
32 changes: 29 additions & 3 deletions test/drive/meet/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { ApiSecurity, AppDetails } from '../../../src/shared';
import { basicHeaders, headersWithToken } from '../../../src/shared/headers';
import { HttpClient } from '../../../src/shared/http/client';
import { Meet } from '../../../src/meet/index';
import { CreateCallResponse, JoinCallPayload, JoinCallResponse, UsersInCallResponse } from '../../../src/meet/types';
import {
CreateCallResponse,
JoinCallPayload,
JoinCallResponse,
LeaveCallPayload,
UsersInCallResponse,
} from '../../../src/meet/types';

describe('Meet service tests', () => {
beforeEach(() => {
Expand Down Expand Up @@ -131,7 +137,7 @@ describe('Meet service tests', () => {
describe('leaveCall method', () => {
const callId = 'call-123';

it('should leave a call successfully with token', async () => {
it('should leave a call successfully with token and no payload', async () => {
// Arrange
const { client, headers } = clientAndHeadersWithToken();
const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined);
Expand All @@ -143,7 +149,7 @@ describe('Meet service tests', () => {
expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, {}, headers);
});

it('should leave a call successfully without token', async () => {
it('should leave a call successfully without token and no payload', async () => {
// Arrange
const { client, headers } = clientAndHeadersWithoutToken();
const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined);
Expand All @@ -154,6 +160,26 @@ describe('Meet service tests', () => {
// Assert
expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, {}, headers);
});

it('should send userId in body when anonymous user leaves with token', async () => {
const payload: LeaveCallPayload = { userId: 'anon-uuid-456' };
const { client, headers } = clientAndHeadersWithToken();
const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined);

await client.leaveCall(callId, payload);

expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, { userId: 'anon-uuid-456' }, headers);
});

it('should send userId in body when anonymous user leaves without token', async () => {
const payload: LeaveCallPayload = { userId: 'anon-uuid-789' };
const { client, headers } = clientAndHeadersWithoutToken();
const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined);

await client.leaveCall(callId, payload);

expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, { userId: 'anon-uuid-789' }, headers);
});
});
});

Expand Down
Loading