Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 154215e

Browse files
Expose API to subscribe to trouter status event (Azure#18894)
* expose API to subscribe to realTimeNotificationConnected and realTimeNotificationDisconnected event * generate apiview * update signaling package version * update changelog * redeclare chatEventId locally
1 parent 80a85a5 commit 154215e

File tree

6 files changed

+83
-37
lines changed

6 files changed

+83
-37
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/communication-chat/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- Prohibit sending the typing notification request within 8 seconds of the previous request.
88

9+
### Features Added
10+
11+
- Updated to @azure/communication-signaling@1.0.0-beta.12.
12+
- Added two new events realTimeNotificationConnected and realTimeNotificationDisconnected that allow the developer to know when the connection to the call server is active
13+
914
## 1.1.1 (2021-10-19)
1015

1116
### Features Added

sdk/communication/communication-chat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"dependencies": {
6565
"@azure/abort-controller": "^1.0.0",
6666
"@azure/communication-common": "^1.1.0",
67-
"@azure/communication-signaling": "1.0.0-beta.11",
67+
"@azure/communication-signaling": "1.0.0-beta.12",
6868
"@azure/core-auth": "^1.3.0",
6969
"@azure/core-client": "^1.0.0",
7070
"@azure/core-rest-pipeline": "^1.1.0",

sdk/communication/communication-chat/review/communication-chat.api.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
/// <reference lib="esnext.asynciterable" />
88

9-
import { ChatEventId } from '@azure/communication-signaling';
109
import { ChatMessageDeletedEvent } from '@azure/communication-signaling';
1110
import { ChatMessageEditedEvent } from '@azure/communication-signaling';
1211
import { ChatMessageReceivedEvent } from '@azure/communication-signaling';
@@ -65,6 +64,8 @@ export class ChatClient {
6564
on(event: "chatThreadPropertiesUpdated", listener: (e: ChatThreadPropertiesUpdatedEvent) => void): void;
6665
on(event: "participantsAdded", listener: (e: ParticipantsAddedEvent) => void): void;
6766
on(event: "participantsRemoved", listener: (e: ParticipantsRemovedEvent) => void): void;
67+
on(event: "realTimeNotificationConnected", listener: () => void): void;
68+
on(event: "realTimeNotificationDisconnected", listener: () => void): void;
6869
startRealtimeNotifications(): Promise<void>;
6970
stopRealtimeNotifications(): Promise<void>;
7071
}
@@ -82,7 +83,8 @@ export interface ChatError {
8283
readonly target?: string;
8384
}
8485

85-
export { ChatEventId }
86+
// @public (undocumented)
87+
export type ChatEventId = "chatMessageReceived" | "chatMessageEdited" | "chatMessageDeleted" | "typingIndicatorReceived" | "readReceiptReceived" | "chatThreadCreated" | "chatThreadDeleted" | "chatThreadPropertiesUpdated" | "participantsAdded" | "participantsRemoved" | "realTimeNotificationConnected" | "realTimeNotificationDisconnected";
8688

8789
// @public
8890
export interface ChatMessage {

sdk/communication/communication-chat/src/chatClient.ts

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,46 @@
22
// Licensed under the MIT license.
33
/// <reference lib="esnext.asynciterable" />
44

5-
import { logger } from "./models/logger";
6-
import { EventEmitter } from "events";
7-
import { CommunicationTokenCredential } from "@azure/communication-common";
8-
import { getSignalingClient } from "./signaling/signalingClient";
9-
import { PagedAsyncIterableIterator } from "@azure/core-paging";
10-
import { SpanStatusCode } from "@azure/core-tracing";
11-
import { createSpan } from "./tracing";
12-
import { ChatThreadClient } from "./chatThreadClient";
135
import {
146
ChatClientOptions,
157
CreateChatThreadOptions,
16-
ListChatThreadsOptions,
17-
DeleteChatThreadOptions
8+
DeleteChatThreadOptions,
9+
ListChatThreadsOptions
1810
} from "./models/options";
11+
import {
12+
ChatEventId,
13+
ChatMessageDeletedEvent,
14+
ChatMessageEditedEvent,
15+
ChatMessageReceivedEvent,
16+
ChatThreadCreatedEvent,
17+
ChatThreadDeletedEvent,
18+
ChatThreadPropertiesUpdatedEvent,
19+
ParticipantsAddedEvent,
20+
ParticipantsRemovedEvent,
21+
ReadReceiptReceivedEvent,
22+
TypingIndicatorReceivedEvent
23+
} from "./models/events";
24+
import { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from "./models/models";
25+
import { ConnectionState, SignalingClient } from "@azure/communication-signaling";
1926
import {
2027
mapToChatParticipantRestModel,
2128
mapToCreateChatThreadOptionsRestModel,
2229
mapToCreateChatThreadResultSdkModel
2330
} from "./models/mappers";
24-
import { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from "./models/models";
25-
import { InternalPipelineOptions } from "@azure/core-rest-pipeline";
31+
2632
import { ChatApiClient } from "./generated/src";
33+
import { ChatThreadClient } from "./chatThreadClient";
34+
import { CommunicationTokenCredential } from "@azure/communication-common";
2735
import { CreateChatThreadRequest } from "./models/requests";
36+
import { EventEmitter } from "events";
37+
import { InternalPipelineOptions } from "@azure/core-rest-pipeline";
38+
import { PagedAsyncIterableIterator } from "@azure/core-paging";
39+
import { SpanStatusCode } from "@azure/core-tracing";
2840
import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy";
41+
import { createSpan } from "./tracing";
2942
import { generateUuid } from "./models/uuid";
30-
import { SignalingClient } from "@azure/communication-signaling";
31-
import {
32-
ChatEventId,
33-
ChatMessageReceivedEvent,
34-
ChatMessageEditedEvent,
35-
ChatMessageDeletedEvent,
36-
ReadReceiptReceivedEvent,
37-
TypingIndicatorReceivedEvent,
38-
ChatThreadCreatedEvent,
39-
ChatThreadDeletedEvent,
40-
ChatThreadPropertiesUpdatedEvent,
41-
ParticipantsAddedEvent,
42-
ParticipantsRemovedEvent
43-
} from "./models/events";
43+
import { getSignalingClient } from "./signaling/signalingClient";
44+
import { logger } from "./models/logger";
4445

4546
/**
4647
* The client to do chat operations
@@ -341,12 +342,29 @@ export class ChatClient {
341342
*/
342343
public on(event: "participantsRemoved", listener: (e: ParticipantsRemovedEvent) => void): void;
343344

344-
public on(event: ChatEventId, listener: (e: any) => void): void {
345+
/**
346+
* Subscribe function for realTimeNotificationConnected.
347+
* @param event - The realTimeNotificationConnected Event
348+
* @param listener - The listener to handle the event.
349+
*/
350+
public on(event: "realTimeNotificationConnected", listener: () => void): void;
351+
352+
/**
353+
* Subscribe function for realTimeNotificationDisconnected.
354+
* @param event - The realTimeNotificationDisconnected Event
355+
* @param listener - The listener to handle the event.
356+
*/
357+
public on(event: "realTimeNotificationDisconnected", listener: () => void): void;
358+
359+
public on(event: ChatEventId, listener: (e?: any) => void): void {
345360
if (this.signalingClient === undefined) {
346361
throw new Error("Realtime notifications are only supported in the browser.");
347362
}
348-
349-
if (!this.isRealtimeNotificationsStarted) {
363+
if (
364+
!this.isRealtimeNotificationsStarted &&
365+
event !== "realTimeNotificationConnected" &&
366+
event !== "realTimeNotificationDisconnected"
367+
) {
350368
throw new Error(
351369
"You must call startRealtimeNotifications before you can subscribe to events."
352370
);
@@ -444,6 +462,14 @@ export class ChatClient {
444462
throw new Error("Realtime notifications are only supported in the browser.");
445463
}
446464

465+
this.signalingClient.on("connectionChanged", (payload) => {
466+
if (payload === ConnectionState.Connected) {
467+
this.emitter.emit("realTimeNotificationConnected");
468+
} else if (payload === ConnectionState.Disconnected) {
469+
this.emitter.emit("realTimeNotificationDisconnected");
470+
}
471+
});
472+
447473
this.signalingClient.on("chatMessageReceived", (payload) => {
448474
this.emitter.emit("chatMessageReceived", payload);
449475
});

sdk/communication/communication-chat/src/models/events.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33

44
import {
5-
ChatEventId,
65
ChatMessageReceivedEvent,
76
ChatMessageEditedEvent,
87
ChatMessageDeletedEvent,
@@ -15,6 +14,20 @@ import {
1514
ParticipantsRemovedEvent
1615
} from "@azure/communication-signaling";
1716

17+
type ChatEventId =
18+
| "chatMessageReceived"
19+
| "chatMessageEdited"
20+
| "chatMessageDeleted"
21+
| "typingIndicatorReceived"
22+
| "readReceiptReceived"
23+
| "chatThreadCreated"
24+
| "chatThreadDeleted"
25+
| "chatThreadPropertiesUpdated"
26+
| "participantsAdded"
27+
| "participantsRemoved"
28+
| "realTimeNotificationConnected"
29+
| "realTimeNotificationDisconnected";
30+
1831
export {
1932
ChatEventId,
2033
ChatMessageReceivedEvent,

0 commit comments

Comments
 (0)