@azure/communication-signaling
Version:
Azure Communication Signaling Client
612 lines (567 loc) • 18.8 kB
TypeScript
import { AbortSignalLike } from '@azure/abort-controller';
import { AccessToken } from '@azure/core-auth';
import { AdditionalPolicyConfig } from '@azure/core-client';
import { AzureLogger } from '@azure/logger';
import { UserAgentPolicyOptions } from '@azure/core-rest-pipeline';
/**
* Base class for chat event
*/
export declare interface BaseChatEvent {
/**
* Thread Id of the event.
*/
threadId: string;
/**
* The Id of the event sender.
*/
sender: CommunicationIdentifierKind;
/**
* The display name of the event sender.
*/
senderDisplayName: string;
/**
* The Id of the event recipient.
*/
recipient: CommunicationIdentifierKind;
}
/**
* Event for chat message operations
*/
export declare interface BaseChatMessageEvent extends BaseChatEvent {
/**
* The Id of the message. This Id is server generated.
*/
id: string;
/**
* The timestamp when the message arrived at the server. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
createdOn: Date;
/**
* Version of the message. This version is an epoch time in a numeric unsigned Int64 format:
* `1593117207131`
*/
version: string;
/**
* Type of the chat message. Possible types are "Text" and "RichText/Html".
*/
type: string;
}
/**
* Event for chat thread operations
*/
export declare interface BaseChatThreadEvent {
/**
* Thread Id of the event.
*/
threadId: string;
/**
* Version of the thread. This version is an epoch time in a numeric unsigned Int64 format:
* `1593117207131`
*/
version: string;
}
/** An attachment in a chat message. */
export declare interface ChatAttachment {
/** Id of the attachment */
id: string;
/** The type of attachment. */
attachmentType: ChatAttachmentType;
/** The name of the attachment content. */
name?: string;
/** The URL where the attachment can be downloaded */
url?: string;
/** The URL where the preview of attachment can be downloaded */
previewUrl?: string;
}
/** Defines values for AttachmentType. */
export declare type ChatAttachmentType = "image" | "file" | "unknown";
/**
* Defines values for chat event.
*/
export declare type ChatEventId = "chatMessageReceived" | "chatMessageEdited" | "chatMessageDeleted" | "typingIndicatorReceived" | "readReceiptReceived" | "chatThreadCreated" | "chatThreadDeleted" | "chatThreadPropertiesUpdated" | "participantsAdded" | "participantsRemoved" | "streamingChatMessageStarted" | "streamingChatMessageChunkReceived";
/**
* Event for a deleted chat message.
* All chat participants receive this event, including the original sender
*/
export declare interface ChatMessageDeletedEvent extends BaseChatMessageEvent {
/**
* The timestamp when the message was deleted. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
deletedOn: Date;
}
/**
* Event for a edited chat message.
* All chat participants receive this event, including the original sender
*/
export declare interface ChatMessageEditedEvent extends ChatMessageReceivedEvent {
/**
* The timestamp when the message was edited. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
editedOn: Date;
/**
* Properties of policyViolation in a chat message.
*/
policyViolation?: PolicyViolation;
}
/**
* Event for a received chat message.
* All chat participants receive this event, including the original sender
*/
export declare interface ChatMessageReceivedEvent extends BaseChatMessageEvent {
/**
* Content of the message.
*/
message: string;
/**
* Metadata of the message.
*/
metadata: Record<string, string>;
/**
* Chat message attachments.
*/
attachments?: ChatAttachment[];
/**
* If a streaming message, details about the streaming message.
*/
streamingMetadata?: StreamingMessageMetadata;
}
/**
* An Azure Communication chat participant.
*/
export declare interface ChatParticipant {
/**
* The id of the chat participant.
*/
id: CommunicationIdentifierKind;
/**
* Display name for the chat participant.
*/
displayName: string;
/**
* Time from which the chat history is shared with the chat participant.
* The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.
*/
shareHistoryTime?: Date;
/**
* Metadata of the participant.
*/
metadata: Record<string, string>;
}
/**
* Event for a created chat thread.
* All chat participants receive this event, including the original sender
*/
export declare interface ChatThreadCreatedEvent extends BaseChatThreadEvent {
/**
* The timestamp when the thread was created. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
createdOn: Date;
/**
* The properties of the thread.
*/
properties: ChatThreadProperties;
/**
* The list of participants on the thread.
*/
participants: ChatParticipant[];
/**
* Id of the user that created the chat thread.
*/
createdBy: ChatParticipant;
}
/**
* Event for an updated chat thread.
* All chat participants receive this event, including the original sender
*/
export declare interface ChatThreadDeletedEvent extends BaseChatThreadEvent {
/**
* The timestamp when the thread was deleted. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
deletedOn: Date;
/**
* Id of the user that deleted the chat thread.
*/
deletedBy: ChatParticipant;
}
/**
* Properties of an Azure Communication chat thread.
*/
export declare interface ChatThreadProperties {
/**
* Thread topic.
*/
topic: string;
/**
* Metadata of the thread.
*/
metadata: Record<string, string>;
}
/**
* Event for an updated chat thread.
* All chat participants receive this event, including the original sender
*/
export declare interface ChatThreadPropertiesUpdatedEvent extends BaseChatThreadEvent {
/**
* The properties of the thread.
*/
properties: ChatThreadProperties;
/**
* The timestamp when the thread was updated. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
updatedOn: Date;
/**
* Id of the user that updated the chat thread.
*/
updatedBy: ChatParticipant;
}
/**
* Options for `CommunicationTokenCredential`'s `getToken` function.
*/
export declare interface CommunicationGetTokenOptions {
/**
* An implementation of `AbortSignalLike` to cancel the operation.
*/
abortSignal?: AbortSignalLike;
}
/**
* Identifies a communication participant.
*/
export declare type CommunicationIdentifier = CommunicationUserIdentifier | PhoneNumberIdentifier | MicrosoftTeamsUserIdentifier | MicrosoftTeamsAppIdentifier | UnknownIdentifier;
/**
* The CommunicationIdentifierKind is a discriminated union that adds a property `kind` to an Identifier.
*/
export declare type CommunicationIdentifierKind = CommunicationUserKind | PhoneNumberKind | MicrosoftTeamsUserKind | MicrosoftTeamsAppKind | UnknownIdentifierKind;
export declare class CommunicationSignalingClient implements SignalingClient {
private readonly credential;
private readonly logger;
private readonly options?;
private readonly trouter;
private config;
private stateChangedListener;
private tokenFetchRetries;
private resourceEndpoint;
private gatewayApiVersion;
constructor(credential: CommunicationTokenCredential, logger: AzureLogger, options?: SignalingClientOptions);
start(): Promise<void>;
stop(isTokenExpired?: boolean): Promise<void>;
on(event: "connectionChanged", listener: (state: ConnectionState) => void): void;
on(event: "chatMessageReceived", listener: (payload: ChatMessageReceivedEvent) => void): void;
on(event: "typingIndicatorReceived", listener: (payload: TypingIndicatorReceivedEvent) => void): void;
on(event: "readReceiptReceived", listener: (payload: ReadReceiptReceivedEvent) => void): void;
on(event: "chatMessageEdited", listener: (payload: ChatMessageEditedEvent) => void): void;
on(event: "chatMessageDeleted", listener: (payload: ChatMessageDeletedEvent) => void): void;
on(event: "chatThreadCreated", listener: (payload: ChatThreadCreatedEvent) => void): void;
on(event: "chatThreadPropertiesUpdated", listener: (payload: ChatThreadPropertiesUpdatedEvent) => void): void;
on(event: "chatThreadDeleted", listener: (payload: ChatThreadDeletedEvent) => void): void;
on(event: "participantsAdded", listener: (payload: ParticipantsAddedEvent) => void): void;
on(event: "participantsRemoved", listener: (payload: ParticipantsRemovedEvent) => void): void;
on(event: "streamingChatMessageStarted", listener: (payload: StreamingChatMessageStartEvent) => void): void;
on(event: "streamingChatMessageChunkReceived", listener: (payload: StreamingChatMessageChunkReceivedEvent) => void): void;
}
/**
* The Azure Communication Services token credential.
*/
export declare interface CommunicationTokenCredential {
/**
* Gets an `AccessToken` for the user. Throws if already disposed.
* @param options - Additional options.
*/
getToken(options?: CommunicationGetTokenOptions): Promise<AccessToken>;
}
/**
* An Azure Communication user.
*/
export declare interface CommunicationUserIdentifier {
/**
* Id of the CommunicationUser as returned from the Communication Service.
*/
communicationUserId: string;
}
/**
* IdentifierKind for a CommunicationUserIdentifier.
*/
export declare interface CommunicationUserKind extends CommunicationUserIdentifier {
/**
* The identifier kind.
*/
kind: "communicationUser";
}
export declare const enum ConnectionState {
Unknown = 0,
Connected = 2,
Disconnected = 3,
Switching = 9
}
/**
* A Microsoft Teams App.
*/
export declare interface MicrosoftTeamsAppIdentifier {
/**
* Optional raw id of the Microsoft Teams App.
*/
rawId?: string;
/**
* The unique Microsoft Teams app ID.
*/
teamsAppId: string;
/**
* The cloud that the Microsoft Temas App belongs to. If missing, the cloud is "public".
*/
cloud?: "public" | "dod" | "gcch";
}
/**
* IdentifierKind for a MicrosoftTeamsAppKind.
*/
export declare interface MicrosoftTeamsAppKind extends MicrosoftTeamsAppIdentifier {
/**
* The identifier kind.
*/
kind: "microsoftTeamsApp";
}
/**
* A Microsoft Teams user.
*/
export declare interface MicrosoftTeamsUserIdentifier {
/**
* Optional raw id of the Microsoft Teams user.
*/
rawId?: string;
/**
* Id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.
*/
microsoftTeamsUserId: string;
/**
* True if the user is anonymous, for example when joining a meeting with a share link. If missing, the user is not anonymous.
*/
isAnonymous?: boolean;
/**
* The cloud that the Microsoft Teams user belongs to. If missing, the cloud is "public".
*/
cloud?: "public" | "dod" | "gcch";
}
/**
* IdentifierKind for a MicrosoftTeamsUserIdentifier.
*/
export declare interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
/**
* The identifier kind.
*/
kind: "microsoftTeamsUser";
}
/**
* Event for participants added to a chat thread.
* All chat participants receive this event, including the original sender
*/
export declare interface ParticipantsAddedEvent extends BaseChatThreadEvent {
/**
* The timestamp when the member was added. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
addedOn: Date;
/**
* The participants added to the thread.
*/
participantsAdded: ChatParticipant[];
/**
* Id of the user that added the chat participants.
*/
addedBy: ChatParticipant;
}
/**
* Event for a participant added to a chat thread.
* All chat participants receive this event, including the original sender
*/
export declare interface ParticipantsRemovedEvent extends BaseChatThreadEvent {
/**
* The timestamp when the member was removed. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
removedOn: Date;
/**
* The participants removed from the thread.
*/
participantsRemoved: ChatParticipant[];
/**
* Id of the user that removed the chat participants.
*/
removedBy: ChatParticipant;
}
/**
* A phone number.
*/
export declare interface PhoneNumberIdentifier {
/**
* Optional raw id of the phone number.
*/
rawId?: string;
/**
* The phone number in E.164 format.
*/
phoneNumber: string;
}
/**
* IdentifierKind for a PhoneNumberIdentifier.
*/
export declare interface PhoneNumberKind extends PhoneNumberIdentifier {
/**
* The identifier kind.
*/
kind: "phoneNumber";
}
/**
* Properties of policyViolation in a chat message.
*/
export declare interface PolicyViolation {
/** Result of the PolicyViolation */
result: PolicyViolationMessageResult;
}
/** Defines values for PolicyViolationMessageResult. */
export declare type PolicyViolationMessageResult = "contentBlocked" | "warning";
/**
* Event for a received read receipt
*/
export declare interface ReadReceiptReceivedEvent extends BaseChatEvent {
/**
* The id of the last read chat message.
*/
chatMessageId: string;
/**
* The timestamp when the message was read. The timestamp is in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ
*/
readOn: Date;
}
export declare interface SignalingClient {
/**
* Start the realtime connection.
*/
start(): void;
/**
* Stop the realtime connection and unsubscribe all event handlers.
*/
stop(isTokenExpired?: boolean): void;
/**
* Listen to connectionChanged events.
*/
on(event: "connectionChanged", listener: (state: ConnectionState) => void): void;
/**
* Listen to chatMessageReceived events.
*/
on(event: "chatMessageReceived", listener: (payload: ChatMessageReceivedEvent) => void): void;
/**
* Listen to typingIndicatorReceived events.
*/
on(event: "typingIndicatorReceived", listener: (payload: TypingIndicatorReceivedEvent) => void): void;
/**
* Listen to readReceiptReceived events.
*/
on(event: "readReceiptReceived", listener: (payload: ReadReceiptReceivedEvent) => void): void;
/**
* Listen to chatMessageEdited events.
*/
on(event: "chatMessageEdited", listener: (payload: ChatMessageEditedEvent) => void): void;
/**
* Listen to chatMessageDeleted events.
*/
on(event: "chatMessageDeleted", listener: (payload: ChatMessageDeletedEvent) => void): void;
/**
* Listen to chatThreadCreated events.
*/
on(event: "chatThreadCreated", listener: (payload: ChatThreadCreatedEvent) => void): void;
/**
* Listen to chatThreadPropertiesUpdated events.
*/
on(event: "chatThreadPropertiesUpdated", listener: (payload: ChatThreadPropertiesUpdatedEvent) => void): void;
/**
* Listen to chatThreadDeleted events.
*/
on(event: "chatThreadDeleted", listener: (payload: ChatThreadDeletedEvent) => void): void;
/**
* Listen to participantsAdded events.
*/
on(event: "participantsAdded", listener: (payload: ParticipantsAddedEvent) => void): void;
/**
* Listen to participantsRemoved events.
*/
on(event: "participantsRemoved", listener: (payload: ParticipantsRemovedEvent) => void): void;
/**
* Listen to streamingChatMessageStarted events.
*/
on(event: "streamingChatMessageStarted", listener: (payload: StreamingChatMessageStartEvent) => void): void;
/**
* Listen to streamingChatMessageChunkReceived events.
*/
on(event: "streamingChatMessageChunkReceived", listener: (payload: StreamingChatMessageChunkReceivedEvent) => void): void;
}
export declare interface SignalingClientOptions {
registrationTimeInMs?: number;
resourceEndpoint?: string;
gatewayApiVersion?: string;
additionalPolicies?: AdditionalPolicyConfig[];
userAgentOptions?: UserAgentPolicyOptions;
}
/**
* Reason for the end of a streaming message
*/
export declare type StreamEndReason = "completed" | "expired" | "canceled";
/**
* Event for a received streaming chat message chunk.
*/
export declare interface StreamingChatMessageChunkReceivedEvent extends ChatMessageEditedEvent {
}
/**
* Event for a received streaming chat message start event.
*/
export declare interface StreamingChatMessageStartEvent extends ChatMessageReceivedEvent {
}
/**
* Type definition for information on a streaming message
*/
export declare interface StreamingMessageMetadata {
streamingMessageType?: StreamingMessageType;
streamingSequenceNumber?: number;
streamEndReason?: StreamEndReason;
}
/**
* Type of a streaming message
*/
export declare type StreamingMessageType = "start" | "informative" | "streaming" | "final";
/**
* Event for a received typing indicator when a chat participant is typing.
* All chat participants receive this event, including the original sender
*/
export declare interface TypingIndicatorReceivedEvent extends BaseChatEvent {
/**
* Version of the message.
*/
version: string;
/**
* The timestamp when the message arrived at the server. The timestamp is in RFC3339 format:
* `yyyy-MM-ddTHH:mm:ssZ`.
*/
receivedOn: Date;
}
/**
* An unknown identifier that doesn't fit any of the other identifier types.
*/
export declare interface UnknownIdentifier {
/**
* Id of the UnknownIdentifier.
*/
id: string;
}
/**
* IdentifierKind for UnkownIdentifer.
*/
export declare interface UnknownIdentifierKind extends UnknownIdentifier {
/**
* The identifier kind.
*/
kind: "unknown";
}
export { }