Skip to content
Open
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
17 changes: 12 additions & 5 deletions packages/client/src/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import type {
RejectCallResponse,
RequestPermissionRequest,
RequestPermissionResponse,
RingCallRequest,
RingCallResponse,
SendCallEventRequest,
SendCallEventResponse,
SendReactionRequest,
Expand Down Expand Up @@ -731,12 +733,14 @@ export class Call {
* @param params.ring if set to true, a `call.ring` event will be sent to the call members.
* @param params.notify if set to true, a `call.notification` event will be sent to the call members.
* @param params.members_limit the total number of members to return as part of the response.
* @param params.video if set to true, in a ringing scenario, mobile SDKs will show "incoming video call", audio only otherwise.
*/
get = async (params?: {
ring?: boolean;
notify?: boolean;
members_limit?: number;
}) => {
video?: boolean;
}): Promise<GetCallResponse> => {
await this.setup();
const response = await this.streamClient.get<GetCallResponse>(
this.streamClientBasePath,
Expand Down Expand Up @@ -813,11 +817,14 @@ export class Call {
};

/**
* A shortcut for {@link Call.get} with `ring` parameter set to `true`.
* Will send a `call.ring` event to the call members.
* Sends a ring notification to the provided users who are not already in the call.
* All users should be members of the call.
*/
ring = async (): Promise<GetCallResponse> => {
return await this.get({ ring: true });
ring = async (data: RingCallRequest = {}): Promise<RingCallResponse> => {
return this.streamClient.post<RingCallResponse, RingCallRequest>(
`${this.streamClientBasePath}/ring`,
data,
);
};

/**
Expand Down
5 changes: 0 additions & 5 deletions packages/client/src/StreamVideoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ export class StreamVideoClient {
* @param e the event.
*/
private initCallFromEvent = async (e: CallCreatedEvent | CallRingEvent) => {
if (this.state.connectedUser?.id === e.call.created_by.id) {
this.logger.debug(`Ignoring ${e.type} event sent by the current user`);
return;
}

try {
const concurrencyTag = getCallInitConcurrencyTag(e.call_cid);
await withoutConcurrency(concurrencyTag, async () => {
Expand Down
24 changes: 5 additions & 19 deletions packages/client/src/__tests__/StreamVideoClient.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,20 @@ const secret = process.env.STREAM_SECRET!;

const serverClient = new StreamClient(apiKey, secret);

const tokenProvider = (userId: string) => {
return async () => {
return new Promise<string>((resolve) => {
setTimeout(() => {
const token = serverClient.createToken(
userId,
undefined,
Math.round(Date.now() / 1000 - 10),
);
resolve(token);
}, 100);
});
};
};

describe('StreamVideoClient - coordinator API', () => {
let client: StreamVideoClient;
const user = {
id: 'sara',
};

beforeAll(() => {
const user = { id: 'sara' };
client = new StreamVideoClient(apiKey, {
// tests run in node, so we have to fake being in browser env
browser: true,
timeout: 15000,
});
client.connectUser(user, tokenProvider(user.id));
client.connectUser(
user,
serverClient.generateUserToken({ user_id: user.id }),
);
});

it('query calls', { retry: 3, timeout: 20000 }, async () => {
Expand Down
50 changes: 50 additions & 0 deletions packages/client/src/__tests__/StreamVideoClient.ringing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,56 @@ describe('StreamVideoClient Ringing', () => {
});
});

describe('ringing individual members', () => {
it('should ring individual members', async () => {
const oliverCall = oliverClient.call('default', crypto.randomUUID());
await oliverCall.create({
ring: false, // don't ring all members by default
data: {
members: [
{ user_id: 'oliver' },
{ user_id: 'sacha' },
{ user_id: 'marcelo' },
],
},
});

// no one should get a ring event yet
const oliverRing = expectEvent(oliverClient, 'call.ring', 500);
const sachaRing = expectEvent(sachaClient, 'call.ring', 500);
const marceloRing = expectEvent(marceloClient, 'call.ring', 500);
await expect(
Promise.all([oliverRing, sachaRing, marceloRing]),
).rejects.toThrow();

// oliver is calling sacha. only sacha should get a ring event
const sachaIndividualRing = expectEvent(sachaClient, 'call.ring');
const marceloIndividualRing = expectEvent(marceloClient, 'call.ring');
await oliverCall.ring({ members_ids: ['sacha'] });
await expect(sachaIndividualRing).resolves.toHaveProperty(
'call.cid',
oliverCall.cid,
);
await expect(marceloIndividualRing).rejects.toThrow();

const sachaCall = await expectCall(sachaClient, oliverCall.cid);
expect(sachaCall).toBeDefined();

// sacha is calling marcelo. only marcelo should get a ring event
const oliverIndividualRing = expectEvent(oliverClient, 'call.ring');
const marceloIndividualRing2 = expectEvent(marceloClient, 'call.ring');
await sachaCall.ring({ members_ids: ['marcelo'] });
await expect(marceloIndividualRing2).resolves.toHaveProperty(
'call.cid',
sachaCall.cid,
);
await expect(oliverIndividualRing).rejects.toThrow();

const marceloCall = await expectCall(marceloClient, sachaCall.cid);
expect(marceloCall).toBeDefined();
});
});

describe('ringing concurrently', async () => {
it('dispatches `call.ring` before `call.created`', async () => {
oliverClient.streamClient.dispatchEvent(
Expand Down
Loading
Loading