@azure/communication-chat 1.6.0-alpha.20250901.2 → 1.6.0-alpha.20250930.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/browser/chatClient.js +45 -50
  2. package/dist/browser/chatClient.js.map +1 -1
  3. package/dist/browser/chatThreadClient.js +84 -120
  4. package/dist/browser/chatThreadClient.js.map +1 -1
  5. package/dist/browser/credential/communicationTokenCredentialPolicy.js +1 -1
  6. package/dist/browser/credential/communicationTokenCredentialPolicy.js.map +1 -1
  7. package/dist/browser/generated/src/chatApiClient.js +11 -3
  8. package/dist/browser/generated/src/chatApiClient.js.map +1 -1
  9. package/dist/browser/generated/src/models/mappers.js +8 -3
  10. package/dist/browser/generated/src/models/mappers.js.map +1 -1
  11. package/dist/browser/generated/src/operations/chat.js +5 -4
  12. package/dist/browser/generated/src/operations/chat.js.map +1 -1
  13. package/dist/browser/generated/src/operations/chatThread.js +17 -16
  14. package/dist/browser/generated/src/operations/chatThread.js.map +1 -1
  15. package/dist/browser/models/mappers.js +52 -28
  16. package/dist/browser/models/mappers.js.map +1 -1
  17. package/dist/browser/signaling/signalingClient-browser.mjs.map +1 -1
  18. package/dist/browser/signaling/signalingClient.js +4 -5
  19. package/dist/commonjs/chatClient.js +45 -50
  20. package/dist/commonjs/chatClient.js.map +1 -1
  21. package/dist/commonjs/chatThreadClient.js +84 -120
  22. package/dist/commonjs/chatThreadClient.js.map +1 -1
  23. package/dist/commonjs/credential/communicationTokenCredentialPolicy.js +1 -1
  24. package/dist/commonjs/credential/communicationTokenCredentialPolicy.js.map +1 -1
  25. package/dist/commonjs/generated/src/chatApiClient.js +11 -3
  26. package/dist/commonjs/generated/src/chatApiClient.js.map +1 -1
  27. package/dist/commonjs/generated/src/models/mappers.js +8 -3
  28. package/dist/commonjs/generated/src/models/mappers.js.map +1 -1
  29. package/dist/commonjs/generated/src/operations/chat.js +5 -4
  30. package/dist/commonjs/generated/src/operations/chat.js.map +1 -1
  31. package/dist/commonjs/generated/src/operations/chatThread.js +17 -16
  32. package/dist/commonjs/generated/src/operations/chatThread.js.map +1 -1
  33. package/dist/commonjs/models/mappers.js +52 -28
  34. package/dist/commonjs/models/mappers.js.map +1 -1
  35. package/dist/commonjs/tsdoc-metadata.json +11 -11
  36. package/dist/esm/chatClient.js +45 -50
  37. package/dist/esm/chatClient.js.map +1 -1
  38. package/dist/esm/chatThreadClient.js +84 -120
  39. package/dist/esm/chatThreadClient.js.map +1 -1
  40. package/dist/esm/credential/communicationTokenCredentialPolicy.js +1 -1
  41. package/dist/esm/credential/communicationTokenCredentialPolicy.js.map +1 -1
  42. package/dist/esm/generated/src/chatApiClient.js +11 -3
  43. package/dist/esm/generated/src/chatApiClient.js.map +1 -1
  44. package/dist/esm/generated/src/models/mappers.js +8 -3
  45. package/dist/esm/generated/src/models/mappers.js.map +1 -1
  46. package/dist/esm/generated/src/operations/chat.js +5 -4
  47. package/dist/esm/generated/src/operations/chat.js.map +1 -1
  48. package/dist/esm/generated/src/operations/chatThread.js +17 -16
  49. package/dist/esm/generated/src/operations/chatThread.js.map +1 -1
  50. package/dist/esm/models/mappers.js +52 -28
  51. package/dist/esm/models/mappers.js.map +1 -1
  52. package/dist/react-native/chatClient.js +45 -50
  53. package/dist/react-native/chatClient.js.map +1 -1
  54. package/dist/react-native/chatThreadClient.js +84 -120
  55. package/dist/react-native/chatThreadClient.js.map +1 -1
  56. package/dist/react-native/credential/communicationTokenCredentialPolicy.js +1 -1
  57. package/dist/react-native/credential/communicationTokenCredentialPolicy.js.map +1 -1
  58. package/dist/react-native/generated/src/chatApiClient.js +11 -3
  59. package/dist/react-native/generated/src/chatApiClient.js.map +1 -1
  60. package/dist/react-native/generated/src/models/mappers.js +8 -3
  61. package/dist/react-native/generated/src/models/mappers.js.map +1 -1
  62. package/dist/react-native/generated/src/operations/chat.js +5 -4
  63. package/dist/react-native/generated/src/operations/chat.js.map +1 -1
  64. package/dist/react-native/generated/src/operations/chatThread.js +17 -16
  65. package/dist/react-native/generated/src/operations/chatThread.js.map +1 -1
  66. package/dist/react-native/models/mappers.js +52 -28
  67. package/dist/react-native/models/mappers.js.map +1 -1
  68. package/dist/react-native/signaling/signalingClient-react-native.mjs.map +1 -1
  69. package/dist/react-native/signaling/signalingClient.js +4 -5
  70. package/package.json +41 -42
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
4
3
  import { ConnectionState } from "@azure/communication-signaling";
5
4
  import { mapToChatParticipantRestModel, mapToCreateChatThreadOptionsRestModel, mapToCreateChatThreadResultSdkModel, } from "./models/mappers.js";
6
5
  import { ChatApiClient } from "./generated/src/index.js";
@@ -15,6 +14,13 @@ import { tracingClient } from "./generated/src/tracing.js";
15
14
  * The client to do chat operations
16
15
  */
17
16
  export class ChatClient {
17
+ endpoint;
18
+ tokenCredential;
19
+ clientOptions;
20
+ client;
21
+ signalingClient = undefined;
22
+ emitter = new EventEmitter();
23
+ isRealtimeNotificationsStarted = false;
18
24
  /**
19
25
  * Creates an instance of the ChatClient for a given resource and user.
20
26
  *
@@ -24,20 +30,27 @@ export class ChatClient {
24
30
  */
25
31
  constructor(endpoint, credential, options = {}) {
26
32
  this.endpoint = endpoint;
27
- this.signalingClient = undefined;
28
- this.emitter = new EventEmitter();
29
- this.isRealtimeNotificationsStarted = false;
30
33
  this.tokenCredential = credential;
31
- const internalPipelineOptions = Object.assign(Object.assign({}, options), {
32
- loggingOptions: {
33
- logger: logger.info,
34
+ const internalPipelineOptions = {
35
+ ...options,
36
+ ...{
37
+ loggingOptions: {
38
+ logger: logger.info,
39
+ },
34
40
  },
41
+ };
42
+ this.client = new ChatApiClient(this.endpoint, {
43
+ endpoint: this.endpoint,
44
+ ...internalPipelineOptions,
35
45
  });
36
- this.client = new ChatApiClient(this.endpoint, Object.assign({ endpoint: this.endpoint }, internalPipelineOptions));
37
46
  const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential);
38
47
  this.client.pipeline.addPolicy(authPolicy);
39
- this.clientOptions = Object.assign({}, options);
40
- this.clientOptions.signalingClientOptions = Object.assign(Object.assign({}, this.clientOptions.signalingClientOptions), { resourceEndpoint: this.endpoint, gatewayApiVersion: this.client.apiVersion });
48
+ this.clientOptions = { ...options };
49
+ this.clientOptions.signalingClientOptions = {
50
+ ...this.clientOptions.signalingClientOptions,
51
+ resourceEndpoint: this.endpoint,
52
+ gatewayApiVersion: this.client.apiVersion,
53
+ };
41
54
  this.signalingClient = getSignalingClient(credential, logger, this.clientOptions.signalingClientOptions);
42
55
  }
43
56
  /**
@@ -55,59 +68,41 @@ export class ChatClient {
55
68
  */
56
69
  async createChatThread(request, options = {}) {
57
70
  return tracingClient.withSpan("ChatClient-CreateChatThread", options, async (updatedOptions) => {
58
- var _a, _b;
59
71
  // We generate an UUID if the user does not provide an idempotencyToken value
60
- updatedOptions.idempotencyToken = (_a = updatedOptions.idempotencyToken) !== null && _a !== void 0 ? _a : generateUuid();
72
+ updatedOptions.idempotencyToken = updatedOptions.idempotencyToken ?? generateUuid();
61
73
  const updatedRestModelOptions = mapToCreateChatThreadOptionsRestModel(updatedOptions);
62
74
  const result = await this.client.chat.createChatThread({
63
75
  topic: request.topic,
64
- participants: (_b = options.participants) === null || _b === void 0 ? void 0 : _b.map((participant) => mapToChatParticipantRestModel(participant)),
76
+ participants: options.participants?.map((participant) => mapToChatParticipantRestModel(participant)),
65
77
  metadata: options.metadata,
66
78
  retentionPolicy: options.retentionPolicy,
67
79
  }, updatedRestModelOptions);
68
80
  return mapToCreateChatThreadResultSdkModel(result);
69
81
  });
70
82
  }
71
- listChatThreadsPage(continuationState_1) {
72
- return __asyncGenerator(this, arguments, function* listChatThreadsPage_1(continuationState, options = {}) {
73
- if (!continuationState.continuationToken) {
74
- const currentSetResponse = yield __await(this.client.chat.listChatThreads(options));
75
- continuationState.continuationToken = currentSetResponse.nextLink;
76
- if (currentSetResponse.value) {
77
- yield yield __await(currentSetResponse.value);
78
- }
79
- }
80
- while (continuationState.continuationToken) {
81
- const currentSetResponse = yield __await(this.client.chat.listChatThreadsNext(continuationState.continuationToken, options));
82
- continuationState.continuationToken = currentSetResponse.nextLink;
83
- if (currentSetResponse.value) {
84
- yield yield __await(currentSetResponse.value);
85
- }
86
- else {
87
- break;
88
- }
83
+ async *listChatThreadsPage(continuationState, options = {}) {
84
+ if (!continuationState.continuationToken) {
85
+ const currentSetResponse = await this.client.chat.listChatThreads(options);
86
+ continuationState.continuationToken = currentSetResponse.nextLink;
87
+ if (currentSetResponse.value) {
88
+ yield currentSetResponse.value;
89
89
  }
90
- });
91
- }
92
- listChatThreadsAll(options) {
93
- return __asyncGenerator(this, arguments, function* listChatThreadsAll_1() {
94
- var _a, e_1, _b, _c;
95
- try {
96
- for (var _d = true, _e = __asyncValues(this.listChatThreadsPage({}, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
97
- _c = _f.value;
98
- _d = false;
99
- const page = _c;
100
- yield __await(yield* __asyncDelegator(__asyncValues(page)));
101
- }
90
+ }
91
+ while (continuationState.continuationToken) {
92
+ const currentSetResponse = await this.client.chat.listChatThreadsNext(continuationState.continuationToken, options);
93
+ continuationState.continuationToken = currentSetResponse.nextLink;
94
+ if (currentSetResponse.value) {
95
+ yield currentSetResponse.value;
102
96
  }
103
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
104
- finally {
105
- try {
106
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
107
- }
108
- finally { if (e_1) throw e_1.error; }
97
+ else {
98
+ break;
109
99
  }
110
- });
100
+ }
101
+ }
102
+ async *listChatThreadsAll(options) {
103
+ for await (const page of this.listChatThreadsPage({}, options)) {
104
+ yield* page;
105
+ }
111
106
  }
112
107
  /**
113
108
  * Gets the list of chat threads of a user.
@@ -1 +1 @@
1
- {"version":3,"file":"chatClient.js","sourceRoot":"","sources":["../../src/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,CAAC,OAAO,EAAE,EAAE;YACzD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,6BAA6B,EAAE,CAAC,OAAO,EAAE,EAAE;YACjE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,OAAO,EAAE,EAAE;YACzD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n ChatClientOptions,\n CreateChatThreadOptions,\n DeleteChatThreadOptions,\n ListChatThreadsOptions,\n} from \"./models/options.js\";\nimport type {\n ChatEventId,\n ChatMessageDeletedEvent,\n ChatMessageEditedEvent,\n ChatMessageReceivedEvent,\n ChatThreadCreatedEvent,\n ChatThreadDeletedEvent,\n ChatThreadPropertiesUpdatedEvent,\n ParticipantsAddedEvent,\n ParticipantsRemovedEvent,\n ReadReceiptReceivedEvent,\n TypingIndicatorReceivedEvent,\n} from \"./models/events.js\";\nimport type { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from \"./models/models.js\";\nimport type { SignalingClient, SignalingClientOptions } from \"@azure/communication-signaling\";\nimport { ConnectionState } from \"@azure/communication-signaling\";\nimport {\n mapToChatParticipantRestModel,\n mapToCreateChatThreadOptionsRestModel,\n mapToCreateChatThreadResultSdkModel,\n} from \"./models/mappers.js\";\nimport { ChatApiClient } from \"./generated/src/index.js\";\nimport { ChatThreadClient } from \"./chatThreadClient.js\";\nimport type { CommunicationTokenCredential } from \"@azure/communication-common\";\nimport type { CreateChatThreadRequest } from \"./models/requests.js\";\nimport { EventEmitter } from \"events\";\nimport type { InternalPipelineOptions } from \"@azure/core-rest-pipeline\";\nimport type { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport { createCommunicationTokenCredentialPolicy } from \"./credential/communicationTokenCredentialPolicy.js\";\nimport { generateUuid } from \"./models/uuid.js\";\nimport { getSignalingClient } from \"./signaling/signalingClient.js\";\nimport { logger } from \"./models/logger.js\";\nimport { tracingClient } from \"./generated/src/tracing.js\";\n\ndeclare interface InternalChatClientOptions extends ChatClientOptions {\n signalingClientOptions?: SignalingClientOptions;\n}\n\n/**\n * The client to do chat operations\n */\nexport class ChatClient {\n private readonly tokenCredential: CommunicationTokenCredential;\n private readonly clientOptions: InternalChatClientOptions;\n private readonly client: ChatApiClient;\n private readonly signalingClient: SignalingClient | undefined = undefined;\n private readonly emitter = new EventEmitter();\n private isRealtimeNotificationsStarted: boolean = false;\n\n /**\n * Creates an instance of the ChatClient for a given resource and user.\n *\n * @param endpoint - The url of the Communication Services resource.\n * @param credential - The token credential. Use AzureCommunicationTokenCredential from \\@azure/communication-common to create a credential.\n * @param options - Additional client options.\n */\n constructor(\n private readonly endpoint: string,\n credential: CommunicationTokenCredential,\n options: ChatClientOptions = {},\n ) {\n this.tokenCredential = credential;\n\n const internalPipelineOptions: InternalPipelineOptions = {\n ...options,\n ...{\n loggingOptions: {\n logger: logger.info,\n },\n },\n };\n\n this.client = new ChatApiClient(this.endpoint, {\n endpoint: this.endpoint,\n ...internalPipelineOptions,\n });\n\n const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential);\n this.client.pipeline.addPolicy(authPolicy);\n\n this.clientOptions = { ...options };\n this.clientOptions.signalingClientOptions = {\n ...this.clientOptions.signalingClientOptions,\n resourceEndpoint: this.endpoint,\n gatewayApiVersion: this.client.apiVersion,\n };\n\n this.signalingClient = getSignalingClient(\n credential,\n logger,\n this.clientOptions.signalingClientOptions,\n );\n }\n\n /**\n * Returns ChatThreadClient with the specific thread id.\n * @param threadId - Thread ID for the ChatThreadClient\n */\n public getChatThreadClient(threadId: string): ChatThreadClient {\n return new ChatThreadClient(this.endpoint, threadId, this.tokenCredential, this.clientOptions);\n }\n\n /**\n * Creates a chat thread.\n * Returns thread client with the id of the created thread.\n * @param request - Request for creating a chat thread.\n * @param options - Operation options.\n */\n public async createChatThread(\n request: CreateChatThreadRequest,\n options: CreateChatThreadOptions = {},\n ): Promise<CreateChatThreadResult> {\n return tracingClient.withSpan(\n \"ChatClient-CreateChatThread\",\n options,\n async (updatedOptions) => {\n // We generate an UUID if the user does not provide an idempotencyToken value\n updatedOptions.idempotencyToken = updatedOptions.idempotencyToken ?? generateUuid();\n const updatedRestModelOptions = mapToCreateChatThreadOptionsRestModel(updatedOptions);\n\n const result = await this.client.chat.createChatThread(\n {\n topic: request.topic,\n participants: options.participants?.map((participant) =>\n mapToChatParticipantRestModel(participant),\n ),\n metadata: options.metadata,\n retentionPolicy: options.retentionPolicy,\n },\n updatedRestModelOptions,\n );\n return mapToCreateChatThreadResultSdkModel(result);\n },\n );\n }\n\n private async *listChatThreadsPage(\n continuationState: ListPageSettings,\n options: ListChatThreadsOptions = {},\n ): AsyncIterableIterator<ChatThreadItem[]> {\n if (!continuationState.continuationToken) {\n const currentSetResponse = await this.client.chat.listChatThreads(options);\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value;\n }\n }\n\n while (continuationState.continuationToken) {\n const currentSetResponse = await this.client.chat.listChatThreadsNext(\n continuationState.continuationToken,\n options,\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value;\n } else {\n break;\n }\n }\n }\n\n private async *listChatThreadsAll(\n options: ListChatThreadsOptions,\n ): AsyncIterableIterator<ChatThreadItem> {\n for await (const page of this.listChatThreadsPage({}, options)) {\n yield* page;\n }\n }\n\n /**\n * Gets the list of chat threads of a user.\n * @param options - List chat threads options.\n */\n public listChatThreads(\n options: ListChatThreadsOptions = {},\n ): PagedAsyncIterableIterator<ChatThreadItem> {\n const { span, updatedOptions } = tracingClient.startSpan(\"ChatClient-ListChatThreads\", options);\n try {\n const iter = this.listChatThreadsAll(updatedOptions);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings: ListPageSettings = {}) => {\n return this.listChatThreadsPage(settings, updatedOptions);\n },\n };\n } catch (e: any) {\n span.setStatus({\n error: e,\n status: \"error\",\n });\n throw e;\n } finally {\n span.end();\n }\n }\n\n /**\n * Deletes a chat thread.\n * @param threadId - The ID of the thread to delete.\n * @param options - Operation options.\n */\n public async deleteChatThread(\n threadId: string,\n options: DeleteChatThreadOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"ChatClient-DeleteChatThread\",\n options,\n async (updatedOptions) => {\n await this.client.chat.deleteChatThread(threadId, updatedOptions);\n },\n );\n }\n\n /**\n * Start receiving realtime notifications.\n * Call this function before subscribing to any event.\n */\n public async startRealtimeNotifications(): Promise<void> {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are not supported in node js.\");\n }\n\n if (this.isRealtimeNotificationsStarted) {\n return;\n }\n\n this.isRealtimeNotificationsStarted = true;\n await this.signalingClient.start();\n this.subscribeToSignalingEvents();\n }\n\n /**\n * Stop receiving realtime notifications.\n * This function would unsubscribe to all events.\n */\n public async stopRealtimeNotifications(): Promise<void> {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are not supported in node js.\");\n }\n\n this.isRealtimeNotificationsStarted = false;\n await this.signalingClient.stop();\n this.emitter.removeAllListeners();\n }\n\n /**\n * Subscribe function for chatMessageReceived.\n * The initial sender will also receive this event.\n * You need to call startRealtimeNotifications before subscribing to any event.\n * @param event - The ChatMessageReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatMessageReceived\", listener: (e: ChatMessageReceivedEvent) => void): void;\n\n /**\n * Subscribe function for chatMessageEdited.\n * The initial sender will also receive this event.\n * @param event - The ChatMessageEditedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatMessageEdited\", listener: (e: ChatMessageEditedEvent) => void): void;\n\n /**\n * Subscribe function for chatMessageDeleted.\n * The initial sender will also receive this event.\n * @param event - The ChatMessageDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatMessageDeleted\", listener: (e: ChatMessageDeletedEvent) => void): void;\n\n /**\n * Subscribe function for typingIndicatorReceived.\n * The initial sender will also receive this event.\n * @param event - The TypingIndicatorReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(\n event: \"typingIndicatorReceived\",\n listener: (e: TypingIndicatorReceivedEvent) => void,\n ): void;\n\n /**\n * Subscribe function for readReceiptReceived.\n * @param event - The ReadReceiptReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"readReceiptReceived\", listener: (e: ReadReceiptReceivedEvent) => void): void;\n\n /**\n * Subscribe function for chatThreadCreated.\n * @param event - The ChatThreadCreatedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatThreadCreated\", listener: (e: ChatThreadCreatedEvent) => void): void;\n\n /**\n * Subscribe function for chatThreadDeleted.\n * @param event - The ChatThreadDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatThreadDeleted\", listener: (e: ChatThreadDeletedEvent) => void): void;\n\n /**\n * Subscribe function for chatThreadPropertiesUpdated.\n * @param event - The ChatThreadPropertiesUpdatedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(\n event: \"chatThreadPropertiesUpdated\",\n listener: (e: ChatThreadPropertiesUpdatedEvent) => void,\n ): void;\n\n /**\n * Subscribe function for participantsAdded.\n * @param event - The ParticipantsAddedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"participantsAdded\", listener: (e: ParticipantsAddedEvent) => void): void;\n\n /**\n * Subscribe function for participantsRemoved.\n * @param event - The ParticipantsRemovedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"participantsRemoved\", listener: (e: ParticipantsRemovedEvent) => void): void;\n\n /**\n * Subscribe function for realTimeNotificationConnected.\n * @param event - The realTimeNotificationConnected Event\n * @param listener - The listener to handle the event.\n */\n public on(event: \"realTimeNotificationConnected\", listener: () => void): void;\n\n /**\n * Subscribe function for realTimeNotificationDisconnected.\n * @param event - The realTimeNotificationDisconnected Event\n * @param listener - The listener to handle the event.\n */\n public on(event: \"realTimeNotificationDisconnected\", listener: () => void): void;\n\n public on(event: ChatEventId, listener: (e?: any) => void): void {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are only supported in the browser.\");\n }\n if (\n !this.isRealtimeNotificationsStarted &&\n event !== \"realTimeNotificationConnected\" &&\n event !== \"realTimeNotificationDisconnected\"\n ) {\n throw new Error(\n \"You must call startRealtimeNotifications before you can subscribe to events.\",\n );\n }\n\n this.emitter.on(event, listener);\n }\n\n /**\n * Unsubscribe from chatMessageReceived.\n * @param event - The ChatMessageReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatMessageReceived\", listener: (e: ChatMessageReceivedEvent) => void): void;\n\n /**\n * Unsubscribe from chatMessageEdited.\n * @param event - The ChatMessageEditedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatMessageEdited\", listener: (e: ChatMessageEditedEvent) => void): void;\n\n /**\n * Unsubscribe from chatMessageDeleted.\n * @param event - The ChatMessageDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatMessageDeleted\", listener: (e: ChatMessageDeletedEvent) => void): void;\n\n /**\n * Unsubscribe from typingIndicatorReceived.\n * @param event - The TypingIndicatorReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(\n event: \"typingIndicatorReceived\",\n listener: (e: TypingIndicatorReceivedEvent) => void,\n ): void;\n\n /**\n * Unsubscribe from readReceiptReceived.\n * @param event - The ReadReceiptReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"readReceiptReceived\", listener: (e: ReadReceiptReceivedEvent) => void): void;\n\n /**\n * Unsubscribe from chatThreadCreated.\n * @param event - The ChatThreadCreatedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatThreadCreated\", listener: (e: ChatThreadCreatedEvent) => void): void;\n\n /**\n * Unsubscribe from chatThreadDeleted.\n * @param event - The ChatThreadDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatThreadDeleted\", listener: (e: ChatThreadDeletedEvent) => void): void;\n\n /**\n * Unsubscribe from chatThreadPropertiesUpdated.\n * @param event - The ChatThreadPropertiesUpdatedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(\n event: \"chatThreadPropertiesUpdated\",\n listener: (e: ChatThreadPropertiesUpdatedEvent) => void,\n ): void;\n\n /**\n * Unsubscribe from participantsAdded.\n * @param event - The ParticipantsAddedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"participantsAdded\", listener: (e: ParticipantsAddedEvent) => void): void;\n\n /**\n * Unsubscribe from participantsRemoved.\n * @param event - The ParticipantsRemovedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"participantsRemoved\", listener: (e: ParticipantsRemovedEvent) => void): void;\n\n public off(event: ChatEventId, listener: (e: any) => void): void {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are only supported in the browser.\");\n }\n\n this.emitter.removeListener(event, listener);\n }\n\n private subscribeToSignalingEvents(): void {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are only supported in the browser.\");\n }\n\n this.signalingClient.on(\"connectionChanged\", (payload) => {\n if (payload === ConnectionState.Connected) {\n this.emitter.emit(\"realTimeNotificationConnected\");\n } else if (payload === ConnectionState.Disconnected) {\n this.emitter.emit(\"realTimeNotificationDisconnected\");\n }\n });\n\n this.signalingClient.on(\"chatMessageReceived\", (payload) => {\n this.emitter.emit(\"chatMessageReceived\", payload);\n });\n\n this.signalingClient.on(\"chatMessageEdited\", (payload) => {\n this.emitter.emit(\"chatMessageEdited\", payload);\n });\n\n this.signalingClient.on(\"chatMessageDeleted\", (payload) => {\n this.emitter.emit(\"chatMessageDeleted\", payload);\n });\n\n this.signalingClient.on(\"typingIndicatorReceived\", (payload) => {\n this.emitter.emit(\"typingIndicatorReceived\", payload);\n });\n\n this.signalingClient.on(\"readReceiptReceived\", (payload) => {\n this.emitter.emit(\"readReceiptReceived\", payload);\n });\n\n this.signalingClient.on(\"chatThreadCreated\", (payload) => {\n this.emitter.emit(\"chatThreadCreated\", payload);\n });\n\n this.signalingClient.on(\"chatThreadDeleted\", (payload) => {\n this.emitter.emit(\"chatThreadDeleted\", payload);\n });\n\n this.signalingClient.on(\"chatThreadPropertiesUpdated\", (payload) => {\n this.emitter.emit(\"chatThreadPropertiesUpdated\", payload);\n });\n\n this.signalingClient.on(\"participantsAdded\", (payload) => {\n this.emitter.emit(\"participantsAdded\", payload);\n });\n\n this.signalingClient.on(\"participantsRemoved\", (payload) => {\n this.emitter.emit(\"participantsRemoved\", payload);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"chatClient.js","sourceRoot":"","sources":["../../src/chatClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA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,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,6BAA6B,EAAE,CAAC,OAAO,EAAE,EAAE;YACjE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAC,OAAO,EAAE,EAAE;YACzD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n ChatClientOptions,\n CreateChatThreadOptions,\n DeleteChatThreadOptions,\n ListChatThreadsOptions,\n} from \"./models/options.js\";\nimport type {\n ChatEventId,\n ChatMessageDeletedEvent,\n ChatMessageEditedEvent,\n ChatMessageReceivedEvent,\n ChatThreadCreatedEvent,\n ChatThreadDeletedEvent,\n ChatThreadPropertiesUpdatedEvent,\n ParticipantsAddedEvent,\n ParticipantsRemovedEvent,\n ReadReceiptReceivedEvent,\n TypingIndicatorReceivedEvent,\n} from \"./models/events.js\";\nimport type { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from \"./models/models.js\";\nimport type { SignalingClient, SignalingClientOptions } from \"@azure/communication-signaling\";\nimport { ConnectionState } from \"@azure/communication-signaling\";\nimport {\n mapToChatParticipantRestModel,\n mapToCreateChatThreadOptionsRestModel,\n mapToCreateChatThreadResultSdkModel,\n} from \"./models/mappers.js\";\nimport { ChatApiClient } from \"./generated/src/index.js\";\nimport { ChatThreadClient } from \"./chatThreadClient.js\";\nimport type { CommunicationTokenCredential } from \"@azure/communication-common\";\nimport type { CreateChatThreadRequest } from \"./models/requests.js\";\nimport { EventEmitter } from \"events\";\nimport type { InternalPipelineOptions } from \"@azure/core-rest-pipeline\";\nimport type { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport { createCommunicationTokenCredentialPolicy } from \"./credential/communicationTokenCredentialPolicy.js\";\nimport { generateUuid } from \"./models/uuid.js\";\nimport { getSignalingClient } from \"./signaling/signalingClient.js\";\nimport { logger } from \"./models/logger.js\";\nimport { tracingClient } from \"./generated/src/tracing.js\";\n\ndeclare interface InternalChatClientOptions extends ChatClientOptions {\n signalingClientOptions?: SignalingClientOptions;\n}\n\n/**\n * The client to do chat operations\n */\nexport class ChatClient {\n private readonly tokenCredential: CommunicationTokenCredential;\n private readonly clientOptions: InternalChatClientOptions;\n private readonly client: ChatApiClient;\n private readonly signalingClient: SignalingClient | undefined = undefined;\n private readonly emitter = new EventEmitter();\n private isRealtimeNotificationsStarted: boolean = false;\n\n /**\n * Creates an instance of the ChatClient for a given resource and user.\n *\n * @param endpoint - The url of the Communication Services resource.\n * @param credential - The token credential. Use AzureCommunicationTokenCredential from \\@azure/communication-common to create a credential.\n * @param options - Additional client options.\n */\n constructor(\n private readonly endpoint: string,\n credential: CommunicationTokenCredential,\n options: ChatClientOptions = {},\n ) {\n this.tokenCredential = credential;\n\n const internalPipelineOptions: InternalPipelineOptions = {\n ...options,\n ...{\n loggingOptions: {\n logger: logger.info,\n },\n },\n };\n\n this.client = new ChatApiClient(this.endpoint, {\n endpoint: this.endpoint,\n ...internalPipelineOptions,\n });\n\n const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential);\n this.client.pipeline.addPolicy(authPolicy);\n\n this.clientOptions = { ...options };\n this.clientOptions.signalingClientOptions = {\n ...this.clientOptions.signalingClientOptions,\n resourceEndpoint: this.endpoint,\n gatewayApiVersion: this.client.apiVersion,\n };\n\n this.signalingClient = getSignalingClient(\n credential,\n logger,\n this.clientOptions.signalingClientOptions,\n );\n }\n\n /**\n * Returns ChatThreadClient with the specific thread id.\n * @param threadId - Thread ID for the ChatThreadClient\n */\n public getChatThreadClient(threadId: string): ChatThreadClient {\n return new ChatThreadClient(this.endpoint, threadId, this.tokenCredential, this.clientOptions);\n }\n\n /**\n * Creates a chat thread.\n * Returns thread client with the id of the created thread.\n * @param request - Request for creating a chat thread.\n * @param options - Operation options.\n */\n public async createChatThread(\n request: CreateChatThreadRequest,\n options: CreateChatThreadOptions = {},\n ): Promise<CreateChatThreadResult> {\n return tracingClient.withSpan(\n \"ChatClient-CreateChatThread\",\n options,\n async (updatedOptions) => {\n // We generate an UUID if the user does not provide an idempotencyToken value\n updatedOptions.idempotencyToken = updatedOptions.idempotencyToken ?? generateUuid();\n const updatedRestModelOptions = mapToCreateChatThreadOptionsRestModel(updatedOptions);\n\n const result = await this.client.chat.createChatThread(\n {\n topic: request.topic,\n participants: options.participants?.map((participant) =>\n mapToChatParticipantRestModel(participant),\n ),\n metadata: options.metadata,\n retentionPolicy: options.retentionPolicy,\n },\n updatedRestModelOptions,\n );\n return mapToCreateChatThreadResultSdkModel(result);\n },\n );\n }\n\n private async *listChatThreadsPage(\n continuationState: ListPageSettings,\n options: ListChatThreadsOptions = {},\n ): AsyncIterableIterator<ChatThreadItem[]> {\n if (!continuationState.continuationToken) {\n const currentSetResponse = await this.client.chat.listChatThreads(options);\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value;\n }\n }\n\n while (continuationState.continuationToken) {\n const currentSetResponse = await this.client.chat.listChatThreadsNext(\n continuationState.continuationToken,\n options,\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value;\n } else {\n break;\n }\n }\n }\n\n private async *listChatThreadsAll(\n options: ListChatThreadsOptions,\n ): AsyncIterableIterator<ChatThreadItem> {\n for await (const page of this.listChatThreadsPage({}, options)) {\n yield* page;\n }\n }\n\n /**\n * Gets the list of chat threads of a user.\n * @param options - List chat threads options.\n */\n public listChatThreads(\n options: ListChatThreadsOptions = {},\n ): PagedAsyncIterableIterator<ChatThreadItem> {\n const { span, updatedOptions } = tracingClient.startSpan(\"ChatClient-ListChatThreads\", options);\n try {\n const iter = this.listChatThreadsAll(updatedOptions);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings: ListPageSettings = {}) => {\n return this.listChatThreadsPage(settings, updatedOptions);\n },\n };\n } catch (e: any) {\n span.setStatus({\n error: e,\n status: \"error\",\n });\n throw e;\n } finally {\n span.end();\n }\n }\n\n /**\n * Deletes a chat thread.\n * @param threadId - The ID of the thread to delete.\n * @param options - Operation options.\n */\n public async deleteChatThread(\n threadId: string,\n options: DeleteChatThreadOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"ChatClient-DeleteChatThread\",\n options,\n async (updatedOptions) => {\n await this.client.chat.deleteChatThread(threadId, updatedOptions);\n },\n );\n }\n\n /**\n * Start receiving realtime notifications.\n * Call this function before subscribing to any event.\n */\n public async startRealtimeNotifications(): Promise<void> {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are not supported in node js.\");\n }\n\n if (this.isRealtimeNotificationsStarted) {\n return;\n }\n\n this.isRealtimeNotificationsStarted = true;\n await this.signalingClient.start();\n this.subscribeToSignalingEvents();\n }\n\n /**\n * Stop receiving realtime notifications.\n * This function would unsubscribe to all events.\n */\n public async stopRealtimeNotifications(): Promise<void> {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are not supported in node js.\");\n }\n\n this.isRealtimeNotificationsStarted = false;\n await this.signalingClient.stop();\n this.emitter.removeAllListeners();\n }\n\n /**\n * Subscribe function for chatMessageReceived.\n * The initial sender will also receive this event.\n * You need to call startRealtimeNotifications before subscribing to any event.\n * @param event - The ChatMessageReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatMessageReceived\", listener: (e: ChatMessageReceivedEvent) => void): void;\n\n /**\n * Subscribe function for chatMessageEdited.\n * The initial sender will also receive this event.\n * @param event - The ChatMessageEditedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatMessageEdited\", listener: (e: ChatMessageEditedEvent) => void): void;\n\n /**\n * Subscribe function for chatMessageDeleted.\n * The initial sender will also receive this event.\n * @param event - The ChatMessageDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatMessageDeleted\", listener: (e: ChatMessageDeletedEvent) => void): void;\n\n /**\n * Subscribe function for typingIndicatorReceived.\n * The initial sender will also receive this event.\n * @param event - The TypingIndicatorReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(\n event: \"typingIndicatorReceived\",\n listener: (e: TypingIndicatorReceivedEvent) => void,\n ): void;\n\n /**\n * Subscribe function for readReceiptReceived.\n * @param event - The ReadReceiptReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"readReceiptReceived\", listener: (e: ReadReceiptReceivedEvent) => void): void;\n\n /**\n * Subscribe function for chatThreadCreated.\n * @param event - The ChatThreadCreatedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatThreadCreated\", listener: (e: ChatThreadCreatedEvent) => void): void;\n\n /**\n * Subscribe function for chatThreadDeleted.\n * @param event - The ChatThreadDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"chatThreadDeleted\", listener: (e: ChatThreadDeletedEvent) => void): void;\n\n /**\n * Subscribe function for chatThreadPropertiesUpdated.\n * @param event - The ChatThreadPropertiesUpdatedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(\n event: \"chatThreadPropertiesUpdated\",\n listener: (e: ChatThreadPropertiesUpdatedEvent) => void,\n ): void;\n\n /**\n * Subscribe function for participantsAdded.\n * @param event - The ParticipantsAddedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"participantsAdded\", listener: (e: ParticipantsAddedEvent) => void): void;\n\n /**\n * Subscribe function for participantsRemoved.\n * @param event - The ParticipantsRemovedEvent.\n * @param listener - The listener to handle the event.\n */\n public on(event: \"participantsRemoved\", listener: (e: ParticipantsRemovedEvent) => void): void;\n\n /**\n * Subscribe function for realTimeNotificationConnected.\n * @param event - The realTimeNotificationConnected Event\n * @param listener - The listener to handle the event.\n */\n public on(event: \"realTimeNotificationConnected\", listener: () => void): void;\n\n /**\n * Subscribe function for realTimeNotificationDisconnected.\n * @param event - The realTimeNotificationDisconnected Event\n * @param listener - The listener to handle the event.\n */\n public on(event: \"realTimeNotificationDisconnected\", listener: () => void): void;\n\n public on(event: ChatEventId, listener: (e?: any) => void): void {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are only supported in the browser.\");\n }\n if (\n !this.isRealtimeNotificationsStarted &&\n event !== \"realTimeNotificationConnected\" &&\n event !== \"realTimeNotificationDisconnected\"\n ) {\n throw new Error(\n \"You must call startRealtimeNotifications before you can subscribe to events.\",\n );\n }\n\n this.emitter.on(event, listener);\n }\n\n /**\n * Unsubscribe from chatMessageReceived.\n * @param event - The ChatMessageReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatMessageReceived\", listener: (e: ChatMessageReceivedEvent) => void): void;\n\n /**\n * Unsubscribe from chatMessageEdited.\n * @param event - The ChatMessageEditedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatMessageEdited\", listener: (e: ChatMessageEditedEvent) => void): void;\n\n /**\n * Unsubscribe from chatMessageDeleted.\n * @param event - The ChatMessageDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatMessageDeleted\", listener: (e: ChatMessageDeletedEvent) => void): void;\n\n /**\n * Unsubscribe from typingIndicatorReceived.\n * @param event - The TypingIndicatorReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(\n event: \"typingIndicatorReceived\",\n listener: (e: TypingIndicatorReceivedEvent) => void,\n ): void;\n\n /**\n * Unsubscribe from readReceiptReceived.\n * @param event - The ReadReceiptReceivedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"readReceiptReceived\", listener: (e: ReadReceiptReceivedEvent) => void): void;\n\n /**\n * Unsubscribe from chatThreadCreated.\n * @param event - The ChatThreadCreatedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatThreadCreated\", listener: (e: ChatThreadCreatedEvent) => void): void;\n\n /**\n * Unsubscribe from chatThreadDeleted.\n * @param event - The ChatThreadDeletedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"chatThreadDeleted\", listener: (e: ChatThreadDeletedEvent) => void): void;\n\n /**\n * Unsubscribe from chatThreadPropertiesUpdated.\n * @param event - The ChatThreadPropertiesUpdatedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(\n event: \"chatThreadPropertiesUpdated\",\n listener: (e: ChatThreadPropertiesUpdatedEvent) => void,\n ): void;\n\n /**\n * Unsubscribe from participantsAdded.\n * @param event - The ParticipantsAddedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"participantsAdded\", listener: (e: ParticipantsAddedEvent) => void): void;\n\n /**\n * Unsubscribe from participantsRemoved.\n * @param event - The ParticipantsRemovedEvent.\n * @param listener - The listener to handle the event.\n */\n public off(event: \"participantsRemoved\", listener: (e: ParticipantsRemovedEvent) => void): void;\n\n public off(event: ChatEventId, listener: (e: any) => void): void {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are only supported in the browser.\");\n }\n\n this.emitter.removeListener(event, listener);\n }\n\n private subscribeToSignalingEvents(): void {\n if (this.signalingClient === undefined) {\n throw new Error(\"Realtime notifications are only supported in the browser.\");\n }\n\n this.signalingClient.on(\"connectionChanged\", (payload) => {\n if (payload === ConnectionState.Connected) {\n this.emitter.emit(\"realTimeNotificationConnected\");\n } else if (payload === ConnectionState.Disconnected) {\n this.emitter.emit(\"realTimeNotificationDisconnected\");\n }\n });\n\n this.signalingClient.on(\"chatMessageReceived\", (payload) => {\n this.emitter.emit(\"chatMessageReceived\", payload);\n });\n\n this.signalingClient.on(\"chatMessageEdited\", (payload) => {\n this.emitter.emit(\"chatMessageEdited\", payload);\n });\n\n this.signalingClient.on(\"chatMessageDeleted\", (payload) => {\n this.emitter.emit(\"chatMessageDeleted\", payload);\n });\n\n this.signalingClient.on(\"typingIndicatorReceived\", (payload) => {\n this.emitter.emit(\"typingIndicatorReceived\", payload);\n });\n\n this.signalingClient.on(\"readReceiptReceived\", (payload) => {\n this.emitter.emit(\"readReceiptReceived\", payload);\n });\n\n this.signalingClient.on(\"chatThreadCreated\", (payload) => {\n this.emitter.emit(\"chatThreadCreated\", payload);\n });\n\n this.signalingClient.on(\"chatThreadDeleted\", (payload) => {\n this.emitter.emit(\"chatThreadDeleted\", payload);\n });\n\n this.signalingClient.on(\"chatThreadPropertiesUpdated\", (payload) => {\n this.emitter.emit(\"chatThreadPropertiesUpdated\", payload);\n });\n\n this.signalingClient.on(\"participantsAdded\", (payload) => {\n this.emitter.emit(\"participantsAdded\", payload);\n });\n\n this.signalingClient.on(\"participantsRemoved\", (payload) => {\n this.emitter.emit(\"participantsRemoved\", payload);\n });\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __asyncDelegator, __asyncGenerator, __asyncValues, __await, __rest } from "tslib";
4
3
  import { logger } from "./models/logger.js";
5
4
  import { serializeCommunicationIdentifier } from "@azure/communication-common";
6
5
  import { mapToAddChatParticipantsRequestRestModel, mapToChatMessageSdkModel, mapToChatParticipantSdkModel, mapToChatThreadPropertiesSdkModel, mapToReadReceiptSdkModel, } from "./models/mappers.js";
@@ -12,17 +11,30 @@ const minimumTypingIntervalInMilliSeconds = 8000;
12
11
  * The client to do chat operations
13
12
  */
14
13
  export class ChatThreadClient {
14
+ endpoint;
15
+ /**
16
+ * Thread ID of the ChatThreadClient
17
+ */
18
+ threadId;
19
+ tokenCredential;
20
+ client;
21
+ timeOfLastTypingRequest = undefined;
15
22
  constructor(endpoint, threadId, credential, options = {}) {
16
23
  this.endpoint = endpoint;
17
- this.timeOfLastTypingRequest = undefined;
18
24
  this.threadId = threadId;
19
25
  this.tokenCredential = credential;
20
- const internalPipelineOptions = Object.assign(Object.assign({}, options), {
21
- loggingOptions: {
22
- logger: logger.info,
26
+ const internalPipelineOptions = {
27
+ ...options,
28
+ ...{
29
+ loggingOptions: {
30
+ logger: logger.info,
31
+ },
23
32
  },
33
+ };
34
+ this.client = new ChatApiClient(this.endpoint, {
35
+ endpoint: this.endpoint,
36
+ ...internalPipelineOptions,
24
37
  });
25
- this.client = new ChatApiClient(this.endpoint, Object.assign({ endpoint: this.endpoint }, internalPipelineOptions));
26
38
  const authPolicy = createCommunicationTokenCredentialPolicy(this.tokenCredential);
27
39
  this.client.pipeline.addPolicy(authPolicy);
28
40
  }
@@ -68,7 +80,7 @@ export class ChatThreadClient {
68
80
  return tracingClient.withSpan("ChatThreadClient-SendMessage", options, async (updatedOptions) => {
69
81
  // reset typing notification clock
70
82
  this.timeOfLastTypingRequest = undefined;
71
- const result = await this.client.chatThread.sendChatMessage(this.threadId, Object.assign(Object.assign({}, request), options), updatedOptions);
83
+ const result = await this.client.chatThread.sendChatMessage(this.threadId, { ...request, ...options }, updatedOptions);
72
84
  return result;
73
85
  });
74
86
  }
@@ -84,46 +96,29 @@ export class ChatThreadClient {
84
96
  return mapToChatMessageSdkModel(result);
85
97
  });
86
98
  }
87
- listMessagesPage(pageSettings_1) {
88
- return __asyncGenerator(this, arguments, function* listMessagesPage_1(pageSettings, options = {}) {
89
- if (!pageSettings.continuationToken) {
90
- const currentSetResponse = yield __await(this.client.chatThread.listChatMessages(this.threadId, options));
91
- pageSettings.continuationToken = currentSetResponse.nextLink;
92
- if (currentSetResponse.value) {
93
- yield yield __await(currentSetResponse.value.map(mapToChatMessageSdkModel, this));
94
- }
95
- }
96
- while (pageSettings.continuationToken) {
97
- const currentSetResponse = yield __await(this.client.chatThread.listChatMessagesNext(this.threadId, pageSettings.continuationToken, options));
98
- pageSettings.continuationToken = currentSetResponse.nextLink;
99
- if (currentSetResponse.value) {
100
- yield yield __await(currentSetResponse.value.map(mapToChatMessageSdkModel, this));
101
- }
102
- else {
103
- break;
104
- }
99
+ async *listMessagesPage(pageSettings, options = {}) {
100
+ if (!pageSettings.continuationToken) {
101
+ const currentSetResponse = await this.client.chatThread.listChatMessages(this.threadId, options);
102
+ pageSettings.continuationToken = currentSetResponse.nextLink;
103
+ if (currentSetResponse.value) {
104
+ yield currentSetResponse.value.map(mapToChatMessageSdkModel, this);
105
105
  }
106
- });
107
- }
108
- listMessagesAll(options) {
109
- return __asyncGenerator(this, arguments, function* listMessagesAll_1() {
110
- var _a, e_1, _b, _c;
111
- try {
112
- for (var _d = true, _e = __asyncValues(this.listMessagesPage({}, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
113
- _c = _f.value;
114
- _d = false;
115
- const page = _c;
116
- yield __await(yield* __asyncDelegator(__asyncValues(page)));
117
- }
106
+ }
107
+ while (pageSettings.continuationToken) {
108
+ const currentSetResponse = await this.client.chatThread.listChatMessagesNext(this.threadId, pageSettings.continuationToken, options);
109
+ pageSettings.continuationToken = currentSetResponse.nextLink;
110
+ if (currentSetResponse.value) {
111
+ yield currentSetResponse.value.map(mapToChatMessageSdkModel, this);
118
112
  }
119
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
120
- finally {
121
- try {
122
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
123
- }
124
- finally { if (e_1) throw e_1.error; }
113
+ else {
114
+ break;
125
115
  }
126
- });
116
+ }
117
+ }
118
+ async *listMessagesAll(options) {
119
+ for await (const page of this.listMessagesPage({}, options)) {
120
+ yield* page;
121
+ }
127
122
  }
128
123
  /**
129
124
  * Gets a list of message from a thread identified by threadId.
@@ -188,46 +183,29 @@ export class ChatThreadClient {
188
183
  return result;
189
184
  });
190
185
  }
191
- listParticipantsPage(continuationState_1) {
192
- return __asyncGenerator(this, arguments, function* listParticipantsPage_1(continuationState, options = {}) {
193
- if (!continuationState.continuationToken) {
194
- const currentSetResponse = yield __await(this.client.chatThread.listChatParticipants(this.threadId, options));
195
- continuationState.continuationToken = currentSetResponse.nextLink;
196
- if (currentSetResponse.value) {
197
- yield yield __await(currentSetResponse.value.map(mapToChatParticipantSdkModel, this));
198
- }
186
+ async *listParticipantsPage(continuationState, options = {}) {
187
+ if (!continuationState.continuationToken) {
188
+ const currentSetResponse = await this.client.chatThread.listChatParticipants(this.threadId, options);
189
+ continuationState.continuationToken = currentSetResponse.nextLink;
190
+ if (currentSetResponse.value) {
191
+ yield currentSetResponse.value.map(mapToChatParticipantSdkModel, this);
199
192
  }
200
- while (continuationState.continuationToken) {
201
- const currentSetResponse = yield __await(this.client.chatThread.listChatParticipantsNext(this.threadId, continuationState.continuationToken, options));
202
- continuationState.continuationToken = currentSetResponse.nextLink;
203
- if (currentSetResponse.value) {
204
- yield yield __await(currentSetResponse.value.map(mapToChatParticipantSdkModel, this));
205
- }
206
- else {
207
- break;
208
- }
209
- }
210
- });
211
- }
212
- listParticipantsAll(options) {
213
- return __asyncGenerator(this, arguments, function* listParticipantsAll_1() {
214
- var _a, e_2, _b, _c;
215
- try {
216
- for (var _d = true, _e = __asyncValues(this.listParticipantsPage({}, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
217
- _c = _f.value;
218
- _d = false;
219
- const page = _c;
220
- yield __await(yield* __asyncDelegator(__asyncValues(page)));
221
- }
193
+ }
194
+ while (continuationState.continuationToken) {
195
+ const currentSetResponse = await this.client.chatThread.listChatParticipantsNext(this.threadId, continuationState.continuationToken, options);
196
+ continuationState.continuationToken = currentSetResponse.nextLink;
197
+ if (currentSetResponse.value) {
198
+ yield currentSetResponse.value.map(mapToChatParticipantSdkModel, this);
222
199
  }
223
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
224
- finally {
225
- try {
226
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
227
- }
228
- finally { if (e_2) throw e_2.error; }
200
+ else {
201
+ break;
229
202
  }
230
- });
203
+ }
204
+ }
205
+ async *listParticipantsAll(options) {
206
+ for await (const page of this.listParticipantsPage({}, options)) {
207
+ yield* page;
208
+ }
231
209
  }
232
210
  /**
233
211
  * Gets the participants of the thread identified by threadId.
@@ -280,10 +258,13 @@ export class ChatThreadClient {
280
258
  async sendTypingNotification(options = {}) {
281
259
  return tracingClient.withSpan("ChatThreadClient-SendTypingNotification", options, async (updatedOptions) => {
282
260
  const dateNow = new Date();
283
- const { senderDisplayName } = updatedOptions, restOptions = __rest(updatedOptions, ["senderDisplayName"]);
261
+ const { senderDisplayName, ...restOptions } = updatedOptions;
284
262
  if (this.canPostTypingNotification(dateNow)) {
285
263
  this.timeOfLastTypingRequest = dateNow;
286
- await this.client.chatThread.sendTypingNotification(this.threadId, Object.assign({ sendTypingNotificationRequest: { senderDisplayName: senderDisplayName } }, restOptions));
264
+ await this.client.chatThread.sendTypingNotification(this.threadId, {
265
+ sendTypingNotificationRequest: { senderDisplayName: senderDisplayName },
266
+ ...restOptions,
267
+ });
287
268
  return true;
288
269
  }
289
270
  logger.info(`Typing Notification NOT Send. [thread_id=${this.threadId}]`);
@@ -300,46 +281,29 @@ export class ChatThreadClient {
300
281
  await this.client.chatThread.sendChatReadReceipt(this.threadId, request, updatedOptions);
301
282
  });
302
283
  }
303
- listReadReceiptsPage(continuationState_1) {
304
- return __asyncGenerator(this, arguments, function* listReadReceiptsPage_1(continuationState, options = {}) {
305
- if (!continuationState.continuationToken) {
306
- const currentSetResponse = yield __await(this.client.chatThread.listChatReadReceipts(this.threadId, options));
307
- continuationState.continuationToken = currentSetResponse.nextLink;
308
- if (currentSetResponse.value) {
309
- yield yield __await(currentSetResponse.value.map(mapToReadReceiptSdkModel, this));
310
- }
311
- }
312
- while (continuationState.continuationToken) {
313
- const currentSetResponse = yield __await(this.client.chatThread.listChatReadReceiptsNext(this.threadId, continuationState.continuationToken, options));
314
- continuationState.continuationToken = currentSetResponse.nextLink;
315
- if (currentSetResponse.value) {
316
- yield yield __await(currentSetResponse.value.map(mapToReadReceiptSdkModel, this));
317
- }
318
- else {
319
- break;
320
- }
284
+ async *listReadReceiptsPage(continuationState, options = {}) {
285
+ if (!continuationState.continuationToken) {
286
+ const currentSetResponse = await this.client.chatThread.listChatReadReceipts(this.threadId, options);
287
+ continuationState.continuationToken = currentSetResponse.nextLink;
288
+ if (currentSetResponse.value) {
289
+ yield currentSetResponse.value.map(mapToReadReceiptSdkModel, this);
321
290
  }
322
- });
323
- }
324
- listReadReceiptsAll(options) {
325
- return __asyncGenerator(this, arguments, function* listReadReceiptsAll_1() {
326
- var _a, e_3, _b, _c;
327
- try {
328
- for (var _d = true, _e = __asyncValues(this.listReadReceiptsPage({}, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
329
- _c = _f.value;
330
- _d = false;
331
- const page = _c;
332
- yield __await(yield* __asyncDelegator(__asyncValues(page)));
333
- }
291
+ }
292
+ while (continuationState.continuationToken) {
293
+ const currentSetResponse = await this.client.chatThread.listChatReadReceiptsNext(this.threadId, continuationState.continuationToken, options);
294
+ continuationState.continuationToken = currentSetResponse.nextLink;
295
+ if (currentSetResponse.value) {
296
+ yield currentSetResponse.value.map(mapToReadReceiptSdkModel, this);
334
297
  }
335
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
336
- finally {
337
- try {
338
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
339
- }
340
- finally { if (e_3) throw e_3.error; }
298
+ else {
299
+ break;
341
300
  }
342
- });
301
+ }
302
+ }
303
+ async *listReadReceiptsAll(options) {
304
+ for await (const page of this.listReadReceiptsPage({}, options)) {
305
+ yield* page;
306
+ }
343
307
  }
344
308
  /**
345
309
  * Gets a list of read receipt from a thread identified by threadId.