diff --git a/sdk/communication/communication-rooms/CHANGELOG.md b/sdk/communication/communication-rooms/CHANGELOG.md index 0b6468b674fe..68f53f7c1e43 100644 --- a/sdk/communication/communication-rooms/CHANGELOG.md +++ b/sdk/communication/communication-rooms/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.1.1 (2024-11-22) + +### Bugs Fixed + +- Bug fix for 'addOrUpdateParticipants' and 'removeParticipants' methods to wait for the operation to complete before returning + ## 1.1.0 (2024-04-15) ### Other Changes diff --git a/sdk/communication/communication-rooms/package.json b/sdk/communication/communication-rooms/package.json index a1cad04e0b0c..b5d1b21148b6 100644 --- a/sdk/communication/communication-rooms/package.json +++ b/sdk/communication/communication-rooms/package.json @@ -3,7 +3,7 @@ "sdk-type": "client", "author": "Microsoft Corporation", "description": "Azure client library for Azure Communication Rooms services", - "version": "1.1.0", + "version": "1.1.1", "engines": { "node": ">=18.0.0" }, diff --git a/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts b/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts index 9c70122cdaf0..7831dbdff454 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts @@ -7,20 +7,24 @@ */ import { tracingClient } from "../tracing.js"; +import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; +import { setContinuationToken } from "../pagingHelper.js"; import { Participants } from "../operationsInterfaces/index.js"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers.js"; import * as Parameters from "../models/parameters.js"; import { RoomsRestClient } from "../roomsRestClient.js"; import { + RoomParticipant, + ParticipantsListNextOptionalParams, ParticipantsListOptionalParams, ParticipantsListResponse, ParticipantsUpdateOptionalParams, ParticipantsUpdateResponse, - ParticipantsListNextOptionalParams, - ParticipantsListNextResponse + ParticipantsListNextResponse, } from "../models/index.js"; +/// /** Class containing Participants operations. */ export class ParticipantsImpl implements Participants { private readonly client: RoomsRestClient; @@ -38,19 +42,77 @@ export class ParticipantsImpl implements Participants { * @param roomId The id of the room to get participants from. * @param options The options parameters. */ - async list( + public list( roomId: string, - options?: ParticipantsListOptionalParams + options?: ParticipantsListOptionalParams, + ): PagedAsyncIterableIterator { + const iter = this.listPagingAll(roomId, options); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: (settings?: PageSettings) => { + if (settings?.maxPageSize) { + throw new Error("maxPageSize is not supported by this operation."); + } + return this.listPagingPage(roomId, options, settings); + }, + }; + } + + private async *listPagingPage( + roomId: string, + options?: ParticipantsListOptionalParams, + settings?: PageSettings, + ): AsyncIterableIterator { + let result: ParticipantsListResponse; + let continuationToken = settings?.continuationToken; + if (!continuationToken) { + result = await this._list(roomId, options); + let page = result.value || []; + continuationToken = result.nextLink; + setContinuationToken(page, continuationToken); + yield page; + } + while (continuationToken) { + result = await this._listNext(roomId, continuationToken, options); + continuationToken = result.nextLink; + let page = result.value || []; + setContinuationToken(page, continuationToken); + yield page; + } + } + + private async *listPagingAll( + roomId: string, + options?: ParticipantsListOptionalParams, + ): AsyncIterableIterator { + for await (const page of this.listPagingPage(roomId, options)) { + yield* page; + } + } + + /** + * Get participants in a room. + * @param roomId The id of the room to get participants from. + * @param options The options parameters. + */ + private async _list( + roomId: string, + options?: ParticipantsListOptionalParams, ): Promise { return tracingClient.withSpan( - "RoomsRestClient.list", + "RoomsRestClient._list", options ?? {}, async (options) => { return this.client.sendOperationRequest( { roomId, options }, - listOperationSpec + listOperationSpec, ) as Promise; - } + }, ); } @@ -61,7 +123,7 @@ export class ParticipantsImpl implements Participants { */ async update( roomId: string, - options?: ParticipantsUpdateOptionalParams + options?: ParticipantsUpdateOptionalParams, ): Promise { return tracingClient.withSpan( "RoomsRestClient.update", @@ -69,9 +131,9 @@ export class ParticipantsImpl implements Participants { async (options) => { return this.client.sendOperationRequest( { roomId, options }, - updateOperationSpec + updateOperationSpec, ) as Promise; - } + }, ); } @@ -81,20 +143,20 @@ export class ParticipantsImpl implements Participants { * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ - async listNext( + private async _listNext( roomId: string, nextLink: string, - options?: ParticipantsListNextOptionalParams + options?: ParticipantsListNextOptionalParams, ): Promise { return tracingClient.withSpan( - "RoomsRestClient.listNext", + "RoomsRestClient._listNext", options ?? {}, async (options) => { return this.client.sendOperationRequest( { roomId, nextLink, options }, - listNextOperationSpec + listNextOperationSpec, ) as Promise; - } + }, ); } } @@ -106,17 +168,17 @@ const listOperationSpec: coreClient.OperationSpec = { httpMethod: "GET", responses: { 200: { - bodyMapper: Mappers.ParticipantsCollection + bodyMapper: Mappers.ParticipantsCollection, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.ParticipantsListExceptionHeaders - } + headersMapper: Mappers.ParticipantsListExceptionHeaders, + }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint, Parameters.roomId], headerParameters: [Parameters.accept], - serializer + serializer, }; const updateOperationSpec: coreClient.OperationSpec = { path: "/rooms/{roomId}/participants", @@ -124,37 +186,37 @@ const updateOperationSpec: coreClient.OperationSpec = { responses: { 200: { bodyMapper: { - type: { name: "Dictionary", value: { type: { name: "any" } } } - } + type: { name: "Dictionary", value: { type: { name: "any" } } }, + }, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.ParticipantsUpdateExceptionHeaders - } + headersMapper: Mappers.ParticipantsUpdateExceptionHeaders, + }, }, requestBody: { parameterPath: { participants: ["options", "participants"] }, - mapper: { ...Mappers.UpdateParticipantsRequest, required: true } + mapper: { ...Mappers.UpdateParticipantsRequest, required: true }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint, Parameters.roomId], headerParameters: [Parameters.accept, Parameters.contentType1], mediaType: "json", - serializer + serializer, }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { - bodyMapper: Mappers.ParticipantsCollection + bodyMapper: Mappers.ParticipantsCollection, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.ParticipantsListNextExceptionHeaders - } + headersMapper: Mappers.ParticipantsListNextExceptionHeaders, + }, }, urlParameters: [Parameters.endpoint, Parameters.roomId, Parameters.nextLink], headerParameters: [Parameters.accept], - serializer + serializer, }; diff --git a/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts b/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts index 30593f9c7663..6e05e4d943ce 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts @@ -7,25 +7,29 @@ */ import { tracingClient } from "../tracing.js"; +import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; +import { setContinuationToken } from "../pagingHelper.js"; import { Rooms } from "../operationsInterfaces/index.js"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers.js"; import * as Parameters from "../models/parameters.js"; import { RoomsRestClient } from "../roomsRestClient.js"; import { - RoomsCreateOptionalParams, - RoomsCreateResponse, + RoomModel, + RoomsListNextOptionalParams, RoomsListOptionalParams, RoomsListResponse, + RoomsCreateOptionalParams, + RoomsCreateResponse, RoomsGetOptionalParams, RoomsGetResponse, RoomsUpdateOptionalParams, RoomsUpdateResponse, RoomsDeleteOptionalParams, - RoomsListNextOptionalParams, - RoomsListNextResponse + RoomsListNextResponse, } from "../models/index.js"; +/// /** Class containing Rooms operations. */ export class RoomsImpl implements Rooms { private readonly client: RoomsRestClient; @@ -38,12 +42,66 @@ export class RoomsImpl implements Rooms { this.client = client; } + /** + * Retrieves all created rooms. + * @param options The options parameters. + */ + public list( + options?: RoomsListOptionalParams, + ): PagedAsyncIterableIterator { + const iter = this.listPagingAll(options); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: (settings?: PageSettings) => { + if (settings?.maxPageSize) { + throw new Error("maxPageSize is not supported by this operation."); + } + return this.listPagingPage(options, settings); + }, + }; + } + + private async *listPagingPage( + options?: RoomsListOptionalParams, + settings?: PageSettings, + ): AsyncIterableIterator { + let result: RoomsListResponse; + let continuationToken = settings?.continuationToken; + if (!continuationToken) { + result = await this._list(options); + let page = result.value || []; + continuationToken = result.nextLink; + setContinuationToken(page, continuationToken); + yield page; + } + while (continuationToken) { + result = await this._listNext(continuationToken, options); + continuationToken = result.nextLink; + let page = result.value || []; + setContinuationToken(page, continuationToken); + yield page; + } + } + + private async *listPagingAll( + options?: RoomsListOptionalParams, + ): AsyncIterableIterator { + for await (const page of this.listPagingPage(options)) { + yield* page; + } + } + /** * Creates a new room. * @param options The options parameters. */ async create( - options?: RoomsCreateOptionalParams + options?: RoomsCreateOptionalParams, ): Promise { return tracingClient.withSpan( "RoomsRestClient.create", @@ -51,9 +109,9 @@ export class RoomsImpl implements Rooms { async (options) => { return this.client.sendOperationRequest( { options }, - createOperationSpec + createOperationSpec, ) as Promise; - } + }, ); } @@ -61,16 +119,18 @@ export class RoomsImpl implements Rooms { * Retrieves all created rooms. * @param options The options parameters. */ - async list(options?: RoomsListOptionalParams): Promise { + private async _list( + options?: RoomsListOptionalParams, + ): Promise { return tracingClient.withSpan( - "RoomsRestClient.list", + "RoomsRestClient._list", options ?? {}, async (options) => { return this.client.sendOperationRequest( { options }, - listOperationSpec + listOperationSpec, ) as Promise; - } + }, ); } @@ -81,7 +141,7 @@ export class RoomsImpl implements Rooms { */ async get( roomId: string, - options?: RoomsGetOptionalParams + options?: RoomsGetOptionalParams, ): Promise { return tracingClient.withSpan( "RoomsRestClient.get", @@ -89,9 +149,9 @@ export class RoomsImpl implements Rooms { async (options) => { return this.client.sendOperationRequest( { roomId, options }, - getOperationSpec + getOperationSpec, ) as Promise; - } + }, ); } @@ -102,7 +162,7 @@ export class RoomsImpl implements Rooms { */ async update( roomId: string, - options?: RoomsUpdateOptionalParams + options?: RoomsUpdateOptionalParams, ): Promise { return tracingClient.withSpan( "RoomsRestClient.update", @@ -110,9 +170,9 @@ export class RoomsImpl implements Rooms { async (options) => { return this.client.sendOperationRequest( { roomId, options }, - updateOperationSpec + updateOperationSpec, ) as Promise; - } + }, ); } @@ -123,7 +183,7 @@ export class RoomsImpl implements Rooms { */ async delete( roomId: string, - options?: RoomsDeleteOptionalParams + options?: RoomsDeleteOptionalParams, ): Promise { return tracingClient.withSpan( "RoomsRestClient.delete", @@ -131,9 +191,9 @@ export class RoomsImpl implements Rooms { async (options) => { return this.client.sendOperationRequest( { roomId, options }, - deleteOperationSpec + deleteOperationSpec, ) as Promise; - } + }, ); } @@ -142,19 +202,19 @@ export class RoomsImpl implements Rooms { * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ - async listNext( + private async _listNext( nextLink: string, - options?: RoomsListNextOptionalParams + options?: RoomsListNextOptionalParams, ): Promise { return tracingClient.withSpan( - "RoomsRestClient.listNext", + "RoomsRestClient._listNext", options ?? {}, async (options) => { return this.client.sendOperationRequest( { nextLink, options }, - listNextOperationSpec + listNextOperationSpec, ) as Promise; - } + }, ); } } @@ -166,21 +226,21 @@ const createOperationSpec: coreClient.OperationSpec = { httpMethod: "POST", responses: { 201: { - bodyMapper: Mappers.RoomModel + bodyMapper: Mappers.RoomModel, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.RoomsCreateExceptionHeaders - } + headersMapper: Mappers.RoomsCreateExceptionHeaders, + }, }, requestBody: { parameterPath: { validFrom: ["options", "validFrom"], validUntil: ["options", "validUntil"], pstnDialOutEnabled: ["options", "pstnDialOutEnabled"], - participants: ["options", "participants"] + participants: ["options", "participants"], }, - mapper: { ...Mappers.CreateRoomRequest, required: true } + mapper: { ...Mappers.CreateRoomRequest, required: true }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint], @@ -188,70 +248,70 @@ const createOperationSpec: coreClient.OperationSpec = { Parameters.contentType, Parameters.accept, Parameters.repeatabilityRequestID, - Parameters.repeatabilityFirstSent + Parameters.repeatabilityFirstSent, ], mediaType: "json", - serializer + serializer, }; const listOperationSpec: coreClient.OperationSpec = { path: "/rooms", httpMethod: "GET", responses: { 200: { - bodyMapper: Mappers.RoomsCollection + bodyMapper: Mappers.RoomsCollection, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.RoomsListExceptionHeaders - } + headersMapper: Mappers.RoomsListExceptionHeaders, + }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint], headerParameters: [Parameters.accept], - serializer + serializer, }; const getOperationSpec: coreClient.OperationSpec = { path: "/rooms/{roomId}", httpMethod: "GET", responses: { 200: { - bodyMapper: Mappers.RoomModel + bodyMapper: Mappers.RoomModel, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.RoomsGetExceptionHeaders - } + headersMapper: Mappers.RoomsGetExceptionHeaders, + }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint, Parameters.roomId], headerParameters: [Parameters.accept], - serializer + serializer, }; const updateOperationSpec: coreClient.OperationSpec = { path: "/rooms/{roomId}", httpMethod: "PATCH", responses: { 200: { - bodyMapper: Mappers.RoomModel + bodyMapper: Mappers.RoomModel, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.RoomsUpdateExceptionHeaders - } + headersMapper: Mappers.RoomsUpdateExceptionHeaders, + }, }, requestBody: { parameterPath: { validFrom: ["options", "validFrom"], validUntil: ["options", "validUntil"], - pstnDialOutEnabled: ["options", "pstnDialOutEnabled"] + pstnDialOutEnabled: ["options", "pstnDialOutEnabled"], }, - mapper: { ...Mappers.UpdateRoomRequest, required: true } + mapper: { ...Mappers.UpdateRoomRequest, required: true }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint, Parameters.roomId], headerParameters: [Parameters.accept, Parameters.contentType1], mediaType: "json", - serializer + serializer, }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/rooms/{roomId}", @@ -260,27 +320,27 @@ const deleteOperationSpec: coreClient.OperationSpec = { 204: {}, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.RoomsDeleteExceptionHeaders - } + headersMapper: Mappers.RoomsDeleteExceptionHeaders, + }, }, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint, Parameters.roomId], headerParameters: [Parameters.accept], - serializer + serializer, }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { - bodyMapper: Mappers.RoomsCollection + bodyMapper: Mappers.RoomsCollection, }, default: { bodyMapper: Mappers.CommunicationErrorResponse, - headersMapper: Mappers.RoomsListNextExceptionHeaders - } + headersMapper: Mappers.RoomsListNextExceptionHeaders, + }, }, urlParameters: [Parameters.endpoint, Parameters.nextLink], headerParameters: [Parameters.accept], - serializer + serializer, }; diff --git a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts index 7e04d0709ccb..3b8bd345151e 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts @@ -6,15 +6,15 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ +import { PagedAsyncIterableIterator } from "@azure/core-paging"; import { + RoomParticipant, ParticipantsListOptionalParams, - ParticipantsListResponse, ParticipantsUpdateOptionalParams, ParticipantsUpdateResponse, - ParticipantsListNextOptionalParams, - ParticipantsListNextResponse } from "../models/index.js"; +/// /** Interface representing a Participants. */ export interface Participants { /** @@ -24,8 +24,8 @@ export interface Participants { */ list( roomId: string, - options?: ParticipantsListOptionalParams - ): Promise; + options?: ParticipantsListOptionalParams, + ): PagedAsyncIterableIterator; /** * Update participants in a room. * @param roomId The id of the room to update the participants in. @@ -33,17 +33,6 @@ export interface Participants { */ update( roomId: string, - options?: ParticipantsUpdateOptionalParams + options?: ParticipantsUpdateOptionalParams, ): Promise; - /** - * ListNext - * @param roomId The id of the room to get participants from. - * @param nextLink The nextLink from the previous successful call to the List method. - * @param options The options parameters. - */ - listNext( - roomId: string, - nextLink: string, - options?: ParticipantsListNextOptionalParams - ): Promise; } diff --git a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts index 5a5b60809e1c..c914f39e0d37 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts @@ -6,32 +6,34 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ +import { PagedAsyncIterableIterator } from "@azure/core-paging"; import { + RoomModel, + RoomsListOptionalParams, RoomsCreateOptionalParams, RoomsCreateResponse, - RoomsListOptionalParams, - RoomsListResponse, RoomsGetOptionalParams, RoomsGetResponse, RoomsUpdateOptionalParams, RoomsUpdateResponse, RoomsDeleteOptionalParams, - RoomsListNextOptionalParams, - RoomsListNextResponse } from "../models/index.js"; +/// /** Interface representing a Rooms. */ export interface Rooms { /** - * Creates a new room. + * Retrieves all created rooms. * @param options The options parameters. */ - create(options?: RoomsCreateOptionalParams): Promise; + list( + options?: RoomsListOptionalParams, + ): PagedAsyncIterableIterator; /** - * Retrieves all created rooms. + * Creates a new room. * @param options The options parameters. */ - list(options?: RoomsListOptionalParams): Promise; + create(options?: RoomsCreateOptionalParams): Promise; /** * Retrieves an existing room by id. * @param roomId The id of the room requested. @@ -39,7 +41,7 @@ export interface Rooms { */ get( roomId: string, - options?: RoomsGetOptionalParams + options?: RoomsGetOptionalParams, ): Promise; /** * Update a room with given changes. @@ -48,7 +50,7 @@ export interface Rooms { */ update( roomId: string, - options?: RoomsUpdateOptionalParams + options?: RoomsUpdateOptionalParams, ): Promise; /** * Delete a room. @@ -56,13 +58,4 @@ export interface Rooms { * @param options The options parameters. */ delete(roomId: string, options?: RoomsDeleteOptionalParams): Promise; - /** - * ListNext - * @param nextLink The nextLink from the previous successful call to the List method. - * @param options The options parameters. - */ - listNext( - nextLink: string, - options?: RoomsListNextOptionalParams - ): Promise; } diff --git a/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts b/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts index 74c7c216fd72..373e21d50e39 100644 --- a/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts +++ b/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts @@ -38,7 +38,7 @@ export class RoomsRestClient extends coreClient.ServiceClient { requestContentType: "application/json; charset=utf-8", }; - const packageDetails = `azsdk-js-communication-rooms/1.1.0`; + const packageDetails = `azsdk-js-communication-rooms/1.1.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` diff --git a/sdk/communication/communication-rooms/src/roomsClient.ts b/sdk/communication/communication-rooms/src/roomsClient.ts index 7eff38998e80..51a9cc28aaef 100644 --- a/sdk/communication/communication-rooms/src/roomsClient.ts +++ b/sdk/communication/communication-rooms/src/roomsClient.ts @@ -157,25 +157,10 @@ export class RoomsClient { pageSettings: ListPageSettings, options: ListRoomOptions = {}, ): AsyncIterableIterator { - if (!pageSettings.continuationToken) { - const currentSetResponse = await this.client.rooms.list(options); - pageSettings.continuationToken = currentSetResponse.nextLink; - if (currentSetResponse.value) { - yield currentSetResponse.value.map((room) => mapCommunicationRoomToSDKModel(room)); - } - } - - while (pageSettings.continuationToken) { - const currentSetResponse = await this.client.rooms.listNext( - pageSettings.continuationToken, - options, - ); - pageSettings.continuationToken = currentSetResponse.nextLink; - if (currentSetResponse.value) { - yield currentSetResponse.value.map((room) => mapCommunicationRoomToSDKModel(room)); - } else { - break; - } + const currentSetResponse = await this.client.rooms.list(options); + const paged = currentSetResponse.byPage(pageSettings); + for await (const page of paged) { + yield page.map((room) => mapCommunicationRoomToSDKModel(room)); } } @@ -234,26 +219,10 @@ export class RoomsClient { pageSettings: ListPageSettings, options: ListParticipantsOptions = {}, ): AsyncIterableIterator { - if (!pageSettings.continuationToken) { - const currentSetResponse = await this.client.participants.list(roomId, options); - pageSettings.continuationToken = currentSetResponse.nextLink; - if (currentSetResponse.value) { - yield currentSetResponse.value.map(mapToRoomParticipantSDKModel, this); - } - } - - while (pageSettings.continuationToken) { - const currentSetResponse = await this.client.participants.listNext( - roomId, - pageSettings.continuationToken, - options, - ); - pageSettings.continuationToken = currentSetResponse.nextLink; - if (currentSetResponse.value) { - yield currentSetResponse.value.map(mapToRoomParticipantSDKModel, this); - } else { - break; - } + const currentSetResponse = await this.client.participants.list(roomId, options); + const paged = currentSetResponse.byPage(pageSettings); + for await (const page of paged) { + yield page.map(mapToRoomParticipantSDKModel, this); } } @@ -320,8 +289,8 @@ export class RoomsClient { return tracingClient.withSpan( "RoomsClient-AddOrUpdateParticipants", options, - (updatedOptions) => { - this.client.participants.update(roomId, { + async (updatedOptions): Promise => { + await this.client.participants.update(roomId, { ...updatedOptions, participants: mapRoomParticipantToRawId(participants), }); @@ -341,11 +310,15 @@ export class RoomsClient { participantIdentifiers: CommunicationIdentifier[], options: RemoveParticipantsOptions = {}, ): Promise { - return tracingClient.withSpan("RoomsClient-RemoveParticipants", options, (updatedOptions) => { - this.client.participants.update(roomId, { - ...updatedOptions, - participants: mapRoomParticipantForRemoval(participantIdentifiers), - }); - }); + return tracingClient.withSpan( + "RoomsClient-RemoveParticipants", + options, + async (updatedOptions): Promise => { + await this.client.participants.update(roomId, { + ...updatedOptions, + participants: mapRoomParticipantForRemoval(participantIdentifiers), + }); + }, + ); } } diff --git a/sdk/communication/communication-rooms/swagger/README.md b/sdk/communication/communication-rooms/swagger/README.md index 0b920e96726e..2f4381055e23 100644 --- a/sdk/communication/communication-rooms/swagger/README.md +++ b/sdk/communication/communication-rooms/swagger/README.md @@ -8,10 +8,10 @@ package-name: "@azure/communication-rooms" override-client-name: RoomsRestClient description: Communication Rooms client -package-version: 1.1.0 +package-version: 1.1.1 license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../src/generated -tag: package-rooms-2024-04-15 +tag: package-rooms-2024-11-22 require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/91813ca7a287fe944262e992413ce4d51d987276/specification/communication/data-plane/Rooms/readme.md model-date-time-as-string: false optional-response-headers: true diff --git a/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts b/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts index cdf60b29052d..98f39070ef24 100644 --- a/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts +++ b/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts @@ -7,7 +7,11 @@ import { createRecordedRoomsClient, createTestUser } from "./utils/recordedClien import type { RoomsClient } from "../../src/roomsClient.js"; import type { CommunicationUserIdentifier } from "@azure/communication-common"; import type { CreateRoomOptions, UpdateRoomOptions } from "../../src/models/options.js"; -import type { CommunicationRoom, RoomParticipantPatch } from "../../src/models/models.js"; +import type { + CommunicationRoom, + RoomParticipantPatch, + RoomParticipant, +} from "../../src/models/models.js"; import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; describe("RoomsClient", () => { @@ -59,7 +63,7 @@ describe("RoomsClient", () => { const createRoomResult = await client.createRoom(options); verifyRoomsAttributes(createRoomResult, options); roomId = createRoomResult.id; - const addParticipantsResult = await client.listParticipants(roomId); + const addParticipantsResult = await listParticipants(roomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); }); @@ -100,7 +104,7 @@ describe("RoomsClient", () => { verifyRoomsAttributes(createRoomResult, options); roomId = createRoomResult.id; - const addParticipantsResult = await client.listParticipants(roomId); + const addParticipantsResult = await listParticipants(roomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 0, 0, 0, 0); }); @@ -156,7 +160,7 @@ describe("RoomsClient", () => { verifyRoomsAttributes(createRoomResult, options); roomId = createRoomResult.id; - const addParticipantsResult = await client.listParticipants(roomId); + const addParticipantsResult = await listParticipants(roomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 0, 0, 0, 0); }); @@ -179,7 +183,7 @@ describe("RoomsClient", () => { verifyRoomsAttributes(createRoomResult, options); roomId = createRoomResult.id; - const addParticipantsResult = await client.listParticipants(roomId); + const addParticipantsResult = await listParticipants(roomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 0, 0, 0, 0); }); @@ -207,7 +211,7 @@ describe("RoomsClient", () => { verifyRoomsAttributes(createRoomResult, options); roomId = createRoomResult.id; - const addParticipantsResult = await client.listParticipants(roomId); + const addParticipantsResult = await listParticipants(roomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); }); @@ -229,7 +233,7 @@ describe("RoomsClient", () => { const createRoomResult = await client.createRoom(options); verifyRoomsAttributes(createRoomResult, options); roomId = createRoomResult.id; - const addParticipantsResult = await client.listParticipants(roomId); + const addParticipantsResult = await listParticipants(roomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); }); @@ -469,7 +473,6 @@ describe("Participants Operations", () => { let client: RoomsClient; let testUser1: CommunicationUserIdentifier; let roomId = ""; - const delayInMs = 1000; beforeEach(async (ctx) => { ({ client, recorder } = await createRecordedRoomsClient(ctx)); @@ -501,12 +504,10 @@ describe("Participants Operations", () => { assert.isDefined(createRoomResult); const curRoomId = createRoomResult.id; - await pause(delayInMs); // Patch participants await client.addOrUpdateParticipants(curRoomId, participants); - await pause(delayInMs); - const addParticipantsResult = await client.listParticipants(curRoomId); + const addParticipantsResult = await listParticipants(curRoomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); roomId = curRoomId; @@ -526,12 +527,10 @@ describe("Participants Operations", () => { assert.isDefined(createRoomResult); const curRoomId = createRoomResult.id; - await pause(delayInMs); // Patch Participants await client.addOrUpdateParticipants(curRoomId, participants as any); - await pause(delayInMs); - const addParticipantsResult = await client.listParticipants(curRoomId); + const addParticipantsResult = await listParticipants(curRoomId, client); verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 0, 1, 0); roomId = curRoomId; @@ -551,13 +550,10 @@ describe("Participants Operations", () => { assert.isDefined(createRoomResult); const curRoomId = createRoomResult.id; - await pause(delayInMs); - // Patch Participants await client.addOrUpdateParticipants(curRoomId, participants); - await pause(delayInMs); - const allParticipants = await client.listParticipants(curRoomId); + const allParticipants = await listParticipants(curRoomId, client); verifyRoomsParticipantsAttributes(allParticipants, 1, 0, 1, 0); roomId = curRoomId; @@ -571,14 +567,11 @@ describe("Participants Operations", () => { assert.isDefined(createRoomResult); const curRoomId = createRoomResult.id; - await pause(delayInMs); // Remove participants const participantIdentifiers = [testUser1]; await client.removeParticipants(curRoomId, participantIdentifiers); - await pause(delayInMs); - - const participants = await client.listParticipants(curRoomId); + const participants = await listParticipants(curRoomId, client); verifyRoomsParticipantsAttributes(participants, 0, 0, 0, 0); roomId = curRoomId; @@ -601,24 +594,24 @@ describe("Participants Operations", () => { assert.isDefined(createRoomResult); const curRoomId = createRoomResult.id; - await pause(delayInMs); - // Remove participants const removeParticipants = [testUser1]; await client.removeParticipants(curRoomId, removeParticipants); - await pause(delayInMs); - const participants = await client.listParticipants(curRoomId); + const participants = await listParticipants(curRoomId, client); verifyRoomsParticipantsAttributes(participants, 0, 0, 0, 0); roomId = curRoomId; }); }); -async function pause(time: number): Promise { - if (!isPlaybackMode()) { - await new Promise((resolve) => setTimeout(resolve, time)); +async function listParticipants(roomId: string, client: RoomsClient): Promise { + const roomParticipants = []; + const participantsList = await client.listParticipants(roomId); + for await (const participant of participantsList) { + roomParticipants.push(participant); } + return roomParticipants; } function verifyRoomsAttributes( @@ -652,7 +645,6 @@ async function verifyRoomsParticipantsAttributes( ): Promise { // Assert assert.isDefined(actualRoomParticipant); - assert.isNotEmpty(actualRoomParticipant); let count = 0; let presenterCount = 0;