@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
@@ -3,7 +3,6 @@
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ChatClient = void 0;
6
- const tslib_1 = require("tslib");
7
6
  const communication_signaling_1 = require("@azure/communication-signaling");
8
7
  const mappers_js_1 = require("./models/mappers.js");
9
8
  const index_js_1 = require("./generated/src/index.js");
@@ -18,6 +17,13 @@ const tracing_js_1 = require("./generated/src/tracing.js");
18
17
  * The client to do chat operations
19
18
  */
20
19
  class ChatClient {
20
+ endpoint;
21
+ tokenCredential;
22
+ clientOptions;
23
+ client;
24
+ signalingClient = undefined;
25
+ emitter = new events_1.EventEmitter();
26
+ isRealtimeNotificationsStarted = false;
21
27
  /**
22
28
  * Creates an instance of the ChatClient for a given resource and user.
23
29
  *
@@ -27,20 +33,27 @@ class ChatClient {
27
33
  */
28
34
  constructor(endpoint, credential, options = {}) {
29
35
  this.endpoint = endpoint;
30
- this.signalingClient = undefined;
31
- this.emitter = new events_1.EventEmitter();
32
- this.isRealtimeNotificationsStarted = false;
33
36
  this.tokenCredential = credential;
34
- const internalPipelineOptions = Object.assign(Object.assign({}, options), {
35
- loggingOptions: {
36
- logger: logger_js_1.logger.info,
37
+ const internalPipelineOptions = {
38
+ ...options,
39
+ ...{
40
+ loggingOptions: {
41
+ logger: logger_js_1.logger.info,
42
+ },
37
43
  },
44
+ };
45
+ this.client = new index_js_1.ChatApiClient(this.endpoint, {
46
+ endpoint: this.endpoint,
47
+ ...internalPipelineOptions,
38
48
  });
39
- this.client = new index_js_1.ChatApiClient(this.endpoint, Object.assign({ endpoint: this.endpoint }, internalPipelineOptions));
40
49
  const authPolicy = (0, communicationTokenCredentialPolicy_js_1.createCommunicationTokenCredentialPolicy)(this.tokenCredential);
41
50
  this.client.pipeline.addPolicy(authPolicy);
42
- this.clientOptions = Object.assign({}, options);
43
- this.clientOptions.signalingClientOptions = Object.assign(Object.assign({}, this.clientOptions.signalingClientOptions), { resourceEndpoint: this.endpoint, gatewayApiVersion: this.client.apiVersion });
51
+ this.clientOptions = { ...options };
52
+ this.clientOptions.signalingClientOptions = {
53
+ ...this.clientOptions.signalingClientOptions,
54
+ resourceEndpoint: this.endpoint,
55
+ gatewayApiVersion: this.client.apiVersion,
56
+ };
44
57
  this.signalingClient = (0, signalingClient_js_1.getSignalingClient)(credential, logger_js_1.logger, this.clientOptions.signalingClientOptions);
45
58
  }
46
59
  /**
@@ -58,59 +71,41 @@ class ChatClient {
58
71
  */
59
72
  async createChatThread(request, options = {}) {
60
73
  return tracing_js_1.tracingClient.withSpan("ChatClient-CreateChatThread", options, async (updatedOptions) => {
61
- var _a, _b;
62
74
  // We generate an UUID if the user does not provide an idempotencyToken value
63
- updatedOptions.idempotencyToken = (_a = updatedOptions.idempotencyToken) !== null && _a !== void 0 ? _a : (0, uuid_js_1.generateUuid)();
75
+ updatedOptions.idempotencyToken = updatedOptions.idempotencyToken ?? (0, uuid_js_1.generateUuid)();
64
76
  const updatedRestModelOptions = (0, mappers_js_1.mapToCreateChatThreadOptionsRestModel)(updatedOptions);
65
77
  const result = await this.client.chat.createChatThread({
66
78
  topic: request.topic,
67
- participants: (_b = options.participants) === null || _b === void 0 ? void 0 : _b.map((participant) => (0, mappers_js_1.mapToChatParticipantRestModel)(participant)),
79
+ participants: options.participants?.map((participant) => (0, mappers_js_1.mapToChatParticipantRestModel)(participant)),
68
80
  metadata: options.metadata,
69
81
  retentionPolicy: options.retentionPolicy,
70
82
  }, updatedRestModelOptions);
71
83
  return (0, mappers_js_1.mapToCreateChatThreadResultSdkModel)(result);
72
84
  });
73
85
  }
74
- listChatThreadsPage(continuationState_1) {
75
- return tslib_1.__asyncGenerator(this, arguments, function* listChatThreadsPage_1(continuationState, options = {}) {
76
- if (!continuationState.continuationToken) {
77
- const currentSetResponse = yield tslib_1.__await(this.client.chat.listChatThreads(options));
78
- continuationState.continuationToken = currentSetResponse.nextLink;
79
- if (currentSetResponse.value) {
80
- yield yield tslib_1.__await(currentSetResponse.value);
81
- }
82
- }
83
- while (continuationState.continuationToken) {
84
- const currentSetResponse = yield tslib_1.__await(this.client.chat.listChatThreadsNext(continuationState.continuationToken, options));
85
- continuationState.continuationToken = currentSetResponse.nextLink;
86
- if (currentSetResponse.value) {
87
- yield yield tslib_1.__await(currentSetResponse.value);
88
- }
89
- else {
90
- break;
91
- }
86
+ async *listChatThreadsPage(continuationState, options = {}) {
87
+ if (!continuationState.continuationToken) {
88
+ const currentSetResponse = await this.client.chat.listChatThreads(options);
89
+ continuationState.continuationToken = currentSetResponse.nextLink;
90
+ if (currentSetResponse.value) {
91
+ yield currentSetResponse.value;
92
92
  }
93
- });
94
- }
95
- listChatThreadsAll(options) {
96
- return tslib_1.__asyncGenerator(this, arguments, function* listChatThreadsAll_1() {
97
- var _a, e_1, _b, _c;
98
- try {
99
- for (var _d = true, _e = tslib_1.__asyncValues(this.listChatThreadsPage({}, options)), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
100
- _c = _f.value;
101
- _d = false;
102
- const page = _c;
103
- yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(page)));
104
- }
93
+ }
94
+ while (continuationState.continuationToken) {
95
+ const currentSetResponse = await this.client.chat.listChatThreadsNext(continuationState.continuationToken, options);
96
+ continuationState.continuationToken = currentSetResponse.nextLink;
97
+ if (currentSetResponse.value) {
98
+ yield currentSetResponse.value;
105
99
  }
106
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
107
- finally {
108
- try {
109
- if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
110
- }
111
- finally { if (e_1) throw e_1.error; }
100
+ else {
101
+ break;
112
102
  }
113
- });
103
+ }
104
+ }
105
+ async *listChatThreadsAll(options) {
106
+ for await (const page of this.listChatThreadsPage({}, options)) {
107
+ yield* page;
108
+ }
114
109
  }
115
110
  /**
116
111
  * Gets the list of chat threads of a user.
@@ -1 +1 @@
1
- {"version":3,"file":"chatClient.js","sourceRoot":"","sources":["../../src/chatClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAuBlC,4EAAiE;AACjE,oDAI6B;AAC7B,uDAAyD;AACzD,+DAAyD;AAGzD,mCAAsC;AAGtC,8GAA8G;AAC9G,8CAAgD;AAChD,uEAAoE;AACpE,kDAA4C;AAC5C,2DAA2D;AAM3D;;GAEG;AACH,MAAa,UAAU;IAQrB;;;;;;OAMG;IACH,YACmB,QAAgB,EACjC,UAAwC,EACxC,UAA6B,EAAE;QAFd,aAAQ,GAAR,QAAQ,CAAQ;QAZlB,oBAAe,GAAgC,SAAS,CAAC;QACzD,YAAO,GAAG,IAAI,qBAAY,EAAE,CAAC;QACtC,mCAA8B,GAAY,KAAK,CAAC;QActD,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC;QAElC,MAAM,uBAAuB,mCACxB,OAAO,GACP;YACD,cAAc,EAAE;gBACd,MAAM,EAAE,kBAAM,CAAC,IAAI;aACpB;SACF,CACF,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,IAAI,wBAAa,CAAC,IAAI,CAAC,QAAQ,kBAC3C,QAAQ,EAAE,IAAI,CAAC,QAAQ,IACpB,uBAAuB,EAC1B,CAAC;QAEH,MAAM,UAAU,GAAG,IAAA,gFAAwC,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAE3C,IAAI,CAAC,aAAa,qBAAQ,OAAO,CAAE,CAAC;QACpC,IAAI,CAAC,aAAa,CAAC,sBAAsB,mCACpC,IAAI,CAAC,aAAa,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AEH,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;AA5cD,gCA4cC","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;;;AAuBlC,4EAAiE;AACjE,oDAI6B;AAC7B,uDAAyD;AACzD,+DAAyD;AAGzD,mCAAsC;AAGtC,8GAA8G;AAC9G,8CAAgD;A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,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;AA5cD,gCA4cC","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"]}
@@ -3,7 +3,6 @@
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ChatThreadClient = void 0;
6
- const tslib_1 = require("tslib");
7
6
  const logger_js_1 = require("./models/logger.js");
8
7
  const communication_common_1 = require("@azure/communication-common");
9
8
  const mappers_js_1 = require("./models/mappers.js");
@@ -15,17 +14,30 @@ const minimumTypingIntervalInMilliSeconds = 8000;
15
14
  * The client to do chat operations
16
15
  */
17
16
  class ChatThreadClient {
17
+ endpoint;
18
+ /**
19
+ * Thread ID of the ChatThreadClient
20
+ */
21
+ threadId;
22
+ tokenCredential;
23
+ client;
24
+ timeOfLastTypingRequest = undefined;
18
25
  constructor(endpoint, threadId, credential, options = {}) {
19
26
  this.endpoint = endpoint;
20
- this.timeOfLastTypingRequest = undefined;
21
27
  this.threadId = threadId;
22
28
  this.tokenCredential = credential;
23
- const internalPipelineOptions = Object.assign(Object.assign({}, options), {
24
- loggingOptions: {
25
- logger: logger_js_1.logger.info,
29
+ const internalPipelineOptions = {
30
+ ...options,
31
+ ...{
32
+ loggingOptions: {
33
+ logger: logger_js_1.logger.info,
34
+ },
26
35
  },
36
+ };
37
+ this.client = new index_js_1.ChatApiClient(this.endpoint, {
38
+ endpoint: this.endpoint,
39
+ ...internalPipelineOptions,
27
40
  });
28
- this.client = new index_js_1.ChatApiClient(this.endpoint, Object.assign({ endpoint: this.endpoint }, internalPipelineOptions));
29
41
  const authPolicy = (0, communicationTokenCredentialPolicy_js_1.createCommunicationTokenCredentialPolicy)(this.tokenCredential);
30
42
  this.client.pipeline.addPolicy(authPolicy);
31
43
  }
@@ -71,7 +83,7 @@ class ChatThreadClient {
71
83
  return tracing_js_1.tracingClient.withSpan("ChatThreadClient-SendMessage", options, async (updatedOptions) => {
72
84
  // reset typing notification clock
73
85
  this.timeOfLastTypingRequest = undefined;
74
- const result = await this.client.chatThread.sendChatMessage(this.threadId, Object.assign(Object.assign({}, request), options), updatedOptions);
86
+ const result = await this.client.chatThread.sendChatMessage(this.threadId, { ...request, ...options }, updatedOptions);
75
87
  return result;
76
88
  });
77
89
  }
@@ -87,46 +99,29 @@ class ChatThreadClient {
87
99
  return (0, mappers_js_1.mapToChatMessageSdkModel)(result);
88
100
  });
89
101
  }
90
- listMessagesPage(pageSettings_1) {
91
- return tslib_1.__asyncGenerator(this, arguments, function* listMessagesPage_1(pageSettings, options = {}) {
92
- if (!pageSettings.continuationToken) {
93
- const currentSetResponse = yield tslib_1.__await(this.client.chatThread.listChatMessages(this.threadId, options));
94
- pageSettings.continuationToken = currentSetResponse.nextLink;
95
- if (currentSetResponse.value) {
96
- yield yield tslib_1.__await(currentSetResponse.value.map(mappers_js_1.mapToChatMessageSdkModel, this));
97
- }
98
- }
99
- while (pageSettings.continuationToken) {
100
- const currentSetResponse = yield tslib_1.__await(this.client.chatThread.listChatMessagesNext(this.threadId, pageSettings.continuationToken, options));
101
- pageSettings.continuationToken = currentSetResponse.nextLink;
102
- if (currentSetResponse.value) {
103
- yield yield tslib_1.__await(currentSetResponse.value.map(mappers_js_1.mapToChatMessageSdkModel, this));
104
- }
105
- else {
106
- break;
107
- }
102
+ async *listMessagesPage(pageSettings, options = {}) {
103
+ if (!pageSettings.continuationToken) {
104
+ const currentSetResponse = await this.client.chatThread.listChatMessages(this.threadId, options);
105
+ pageSettings.continuationToken = currentSetResponse.nextLink;
106
+ if (currentSetResponse.value) {
107
+ yield currentSetResponse.value.map(mappers_js_1.mapToChatMessageSdkModel, this);
108
108
  }
109
- });
110
- }
111
- listMessagesAll(options) {
112
- return tslib_1.__asyncGenerator(this, arguments, function* listMessagesAll_1() {
113
- var _a, e_1, _b, _c;
114
- try {
115
- for (var _d = true, _e = tslib_1.__asyncValues(this.listMessagesPage({}, options)), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
116
- _c = _f.value;
117
- _d = false;
118
- const page = _c;
119
- yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(page)));
120
- }
109
+ }
110
+ while (pageSettings.continuationToken) {
111
+ const currentSetResponse = await this.client.chatThread.listChatMessagesNext(this.threadId, pageSettings.continuationToken, options);
112
+ pageSettings.continuationToken = currentSetResponse.nextLink;
113
+ if (currentSetResponse.value) {
114
+ yield currentSetResponse.value.map(mappers_js_1.mapToChatMessageSdkModel, this);
121
115
  }
122
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
123
- finally {
124
- try {
125
- if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
126
- }
127
- finally { if (e_1) throw e_1.error; }
116
+ else {
117
+ break;
128
118
  }
129
- });
119
+ }
120
+ }
121
+ async *listMessagesAll(options) {
122
+ for await (const page of this.listMessagesPage({}, options)) {
123
+ yield* page;
124
+ }
130
125
  }
131
126
  /**
132
127
  * Gets a list of message from a thread identified by threadId.
@@ -191,46 +186,29 @@ class ChatThreadClient {
191
186
  return result;
192
187
  });
193
188
  }
194
- listParticipantsPage(continuationState_1) {
195
- return tslib_1.__asyncGenerator(this, arguments, function* listParticipantsPage_1(continuationState, options = {}) {
196
- if (!continuationState.continuationToken) {
197
- const currentSetResponse = yield tslib_1.__await(this.client.chatThread.listChatParticipants(this.threadId, options));
198
- continuationState.continuationToken = currentSetResponse.nextLink;
199
- if (currentSetResponse.value) {
200
- yield yield tslib_1.__await(currentSetResponse.value.map(mappers_js_1.mapToChatParticipantSdkModel, this));
201
- }
189
+ async *listParticipantsPage(continuationState, options = {}) {
190
+ if (!continuationState.continuationToken) {
191
+ const currentSetResponse = await this.client.chatThread.listChatParticipants(this.threadId, options);
192
+ continuationState.continuationToken = currentSetResponse.nextLink;
193
+ if (currentSetResponse.value) {
194
+ yield currentSetResponse.value.map(mappers_js_1.mapToChatParticipantSdkModel, this);
202
195
  }
203
- while (continuationState.continuationToken) {
204
- const currentSetResponse = yield tslib_1.__await(this.client.chatThread.listChatParticipantsNext(this.threadId, continuationState.continuationToken, options));
205
- continuationState.continuationToken = currentSetResponse.nextLink;
206
- if (currentSetResponse.value) {
207
- yield yield tslib_1.__await(currentSetResponse.value.map(mappers_js_1.mapToChatParticipantSdkModel, this));
208
- }
209
- else {
210
- break;
211
- }
212
- }
213
- });
214
- }
215
- listParticipantsAll(options) {
216
- return tslib_1.__asyncGenerator(this, arguments, function* listParticipantsAll_1() {
217
- var _a, e_2, _b, _c;
218
- try {
219
- for (var _d = true, _e = tslib_1.__asyncValues(this.listParticipantsPage({}, options)), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
220
- _c = _f.value;
221
- _d = false;
222
- const page = _c;
223
- yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(page)));
224
- }
196
+ }
197
+ while (continuationState.continuationToken) {
198
+ const currentSetResponse = await this.client.chatThread.listChatParticipantsNext(this.threadId, continuationState.continuationToken, options);
199
+ continuationState.continuationToken = currentSetResponse.nextLink;
200
+ if (currentSetResponse.value) {
201
+ yield currentSetResponse.value.map(mappers_js_1.mapToChatParticipantSdkModel, this);
225
202
  }
226
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
227
- finally {
228
- try {
229
- if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
230
- }
231
- finally { if (e_2) throw e_2.error; }
203
+ else {
204
+ break;
232
205
  }
233
- });
206
+ }
207
+ }
208
+ async *listParticipantsAll(options) {
209
+ for await (const page of this.listParticipantsPage({}, options)) {
210
+ yield* page;
211
+ }
234
212
  }
235
213
  /**
236
214
  * Gets the participants of the thread identified by threadId.
@@ -283,10 +261,13 @@ class ChatThreadClient {
283
261
  async sendTypingNotification(options = {}) {
284
262
  return tracing_js_1.tracingClient.withSpan("ChatThreadClient-SendTypingNotification", options, async (updatedOptions) => {
285
263
  const dateNow = new Date();
286
- const { senderDisplayName } = updatedOptions, restOptions = tslib_1.__rest(updatedOptions, ["senderDisplayName"]);
264
+ const { senderDisplayName, ...restOptions } = updatedOptions;
287
265
  if (this.canPostTypingNotification(dateNow)) {
288
266
  this.timeOfLastTypingRequest = dateNow;
289
- await this.client.chatThread.sendTypingNotification(this.threadId, Object.assign({ sendTypingNotificationRequest: { senderDisplayName: senderDisplayName } }, restOptions));
267
+ await this.client.chatThread.sendTypingNotification(this.threadId, {
268
+ sendTypingNotificationRequest: { senderDisplayName: senderDisplayName },
269
+ ...restOptions,
270
+ });
290
271
  return true;
291
272
  }
292
273
  logger_js_1.logger.info(`Typing Notification NOT Send. [thread_id=${this.threadId}]`);
@@ -303,46 +284,29 @@ class ChatThreadClient {
303
284
  await this.client.chatThread.sendChatReadReceipt(this.threadId, request, updatedOptions);
304
285
  });
305
286
  }
306
- listReadReceiptsPage(continuationState_1) {
307
- return tslib_1.__asyncGenerator(this, arguments, function* listReadReceiptsPage_1(continuationState, options = {}) {
308
- if (!continuationState.continuationToken) {
309
- const currentSetResponse = yield tslib_1.__await(this.client.chatThread.listChatReadReceipts(this.threadId, options));
310
- continuationState.continuationToken = currentSetResponse.nextLink;
311
- if (currentSetResponse.value) {
312
- yield yield tslib_1.__await(currentSetResponse.value.map(mappers_js_1.mapToReadReceiptSdkModel, this));
313
- }
314
- }
315
- while (continuationState.continuationToken) {
316
- const currentSetResponse = yield tslib_1.__await(this.client.chatThread.listChatReadReceiptsNext(this.threadId, continuationState.continuationToken, options));
317
- continuationState.continuationToken = currentSetResponse.nextLink;
318
- if (currentSetResponse.value) {
319
- yield yield tslib_1.__await(currentSetResponse.value.map(mappers_js_1.mapToReadReceiptSdkModel, this));
320
- }
321
- else {
322
- break;
323
- }
287
+ async *listReadReceiptsPage(continuationState, options = {}) {
288
+ if (!continuationState.continuationToken) {
289
+ const currentSetResponse = await this.client.chatThread.listChatReadReceipts(this.threadId, options);
290
+ continuationState.continuationToken = currentSetResponse.nextLink;
291
+ if (currentSetResponse.value) {
292
+ yield currentSetResponse.value.map(mappers_js_1.mapToReadReceiptSdkModel, this);
324
293
  }
325
- });
326
- }
327
- listReadReceiptsAll(options) {
328
- return tslib_1.__asyncGenerator(this, arguments, function* listReadReceiptsAll_1() {
329
- var _a, e_3, _b, _c;
330
- try {
331
- for (var _d = true, _e = tslib_1.__asyncValues(this.listReadReceiptsPage({}, options)), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
332
- _c = _f.value;
333
- _d = false;
334
- const page = _c;
335
- yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(page)));
336
- }
294
+ }
295
+ while (continuationState.continuationToken) {
296
+ const currentSetResponse = await this.client.chatThread.listChatReadReceiptsNext(this.threadId, continuationState.continuationToken, options);
297
+ continuationState.continuationToken = currentSetResponse.nextLink;
298
+ if (currentSetResponse.value) {
299
+ yield currentSetResponse.value.map(mappers_js_1.mapToReadReceiptSdkModel, this);
337
300
  }
338
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
339
- finally {
340
- try {
341
- if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
342
- }
343
- finally { if (e_3) throw e_3.error; }
301
+ else {
302
+ break;
344
303
  }
345
- });
304
+ }
305
+ }
306
+ async *listReadReceiptsAll(options) {
307
+ for await (const page of this.listReadReceiptsPage({}, options)) {
308
+ yield* page;
309
+ }
346
310
  }
347
311
  /**
348
312
  * Gets a list of read receipt from a thread identified by threadId.