@azure/communication-react
Version:
React library for building modern communication user experiences utilizing Azure Communication Services
368 lines • 20.7 kB
TypeScript
import { AudioDeviceInfo, Call, CallAgent, GroupCallLocator, PermissionConstraints, PropertyChangedEvent, TeamsMeetingLinkLocator, StartCallOptions, VideoDeviceInfo } from '@azure/communication-calling';
import { TeamsMeetingIdLocator } from '@azure/communication-calling';
import { Reaction } from '@azure/communication-calling';
import { AddPhoneNumberOptions, DeviceAccess } from '@azure/communication-calling';
import { BreakoutRoomsUpdatedListener } from '@azure/communication-calling';
import { DtmfTone } from '@azure/communication-calling';
import { CreateVideoStreamViewResult, VideoStreamOptions } from "../../../../../react-components/src";
import { TogetherModeStreamViewResult, TogetherModeStreamOptions } from "../../../../../react-components/src";
import { ParticipantsJoinedListener, ParticipantsLeftListener, IsMutedChangedListener, CallIdChangedListener, IsLocalScreenSharingActiveChangedListener, DisplayNameChangedListener, IsSpeakingChangedListener, CallAdapter, CallEndedListener } from '../../CallComposite';
import { MessageReceivedListener, MessageReadListener, ChatAdapter, ParticipantsRemovedListener, ParticipantsAddedListener, MessageEditedListener, MessageDeletedListener } from '../../ChatComposite';
import { ResourceDetails } from '../../ChatComposite';
import { CallWithChatAdapter, ChatInitializedListener } from './CallWithChatAdapter';
import { CallWithChatAdapterState } from '../state/CallWithChatAdapterState';
import { CommunicationTokenCredential, CommunicationUserIdentifier } from '@azure/communication-common';
import { CommunicationIdentifier, PhoneNumberIdentifier } from '@azure/communication-common';
import { AdapterError } from '../../common/adapters';
import { CallAdapterLocator } from '../../CallComposite/adapter/AzureCommunicationCallAdapter';
import { StatefulCallClient } from "../../../../../calling-stateful-client/src";
import { StatefulChatClient } from "../../../../../chat-stateful-client/src";
import { ChatThreadClient } from '@azure/communication-chat';
import { JoinCallOptions, StartCallIdentifier, StartCaptionsAdapterOptions, StopCaptionsAdapterOptions } from '../../CallComposite/adapter/CallAdapter';
import { AzureCommunicationCallAdapterOptions } from '../../CallComposite/adapter/AzureCommunicationCallAdapter';
import { IsCaptionsActiveChangedListener, CaptionsReceivedListener, IsCaptionLanguageChangedListener, IsSpokenLanguageChangedListener } from '../../CallComposite/adapter/CallAdapter';
import { RealTimeTextReceivedListener } from '../../CallComposite/adapter/CallAdapter';
import { CapabilitiesChangedListener } from '../../CallComposite/adapter/CallAdapter';
import { SpotlightChangedListener } from '../../CallComposite/adapter/CallAdapter';
import { VideoBackgroundImage, VideoBackgroundEffect } from '../../CallComposite';
import { CallSurvey, CallSurveyResponse } from '@azure/communication-calling';
/**
* CallWithChat adapter backed by Azure Communication Services.
* Created for easy use with the {@link CallWithChatComposite}.
*/
export declare class AzureCommunicationCallWithChatAdapter implements CallWithChatAdapter {
private callAdapter;
private chatAdapter;
private context;
private emitter;
private onChatStateChange;
private onCallStateChange;
private isAdapterDisposed;
private createChatAdapterCallback;
private originCallChatAdapter;
private breakoutRoomChatAdapter;
private chatEventListeners;
private storeChatEventListener;
private removeChatEventListener;
constructor(callAdapter: CallAdapter, chatAdapter?: ChatAdapter);
private breakoutRoomJoined;
private setBreakoutRoomChatAdapterToThread;
setChatAdapterPromise(chatAdapter: Promise<ChatAdapter>): void;
setCreateChatAdapterCallback(chatThreadCallBack: (threadId: string) => Promise<ChatAdapter>): void;
createNewChatAdapterForThread(threadId: string): Promise<ChatAdapter>;
private updateChatAdapter;
private updateChatEventListeners;
private bindPublicMethods;
/** Join existing Call. */
joinCall(options?: boolean | JoinCallOptions): Call | undefined;
/** Leave current Call. */
leaveCall(forEveryone?: boolean): Promise<void>;
/** Start a new Call. */
startCall(participants: string[], options?: StartCallOptions): Call | undefined;
/** Start a new Call. */
startCall(participants: StartCallIdentifier[], options?: StartCallOptions): Call | undefined;
/**
* Subscribe to state change events.
* @param handler - handler to be called when the state changes. This is passed the new state.
*/
onStateChange(handler: (state: CallWithChatAdapterState) => void): void;
/**
* Unsubscribe to state change events.
* @param handler - handler to be no longer called when state changes.
*/
offStateChange(handler: (state: CallWithChatAdapterState) => void): void;
/** Get current Call and Chat state. */
getState(): CallWithChatAdapterState;
/** Dispose of the current CallWithChatAdapter. */
dispose(): void;
/** Remove a participant from the Call only. */
removeParticipant(userId: string | CommunicationIdentifier): Promise<void>;
setCamera(device: VideoDeviceInfo, options?: VideoStreamOptions): Promise<void>;
/** Set the microphone to be used in the Call. */
setMicrophone(device: AudioDeviceInfo): Promise<void>;
/** Set the speaker to be used in the Call. */
setSpeaker(device: AudioDeviceInfo): Promise<void>;
askDevicePermission(constraints: PermissionConstraints): Promise<DeviceAccess>;
/** Query for available cameras. */
queryCameras(): Promise<VideoDeviceInfo[]>;
/** Query for available microphones. */
queryMicrophones(): Promise<AudioDeviceInfo[]>;
/** Query for available speakers. */
querySpeakers(): Promise<AudioDeviceInfo[]>;
/** Start the camera for the user in the Call. */
startCamera(options?: VideoStreamOptions): Promise<void>;
/** Stop the camera for the user in the Call. */
stopCamera(): Promise<void>;
/** Mute the user in the Call. */
mute(): Promise<void>;
/** Unmute the user in the Call. */
unmute(): Promise<void>;
/** Trigger the user to start screen share. */
startScreenShare(): Promise<void>;
/** Stop the current active screen share. */
stopScreenShare(): Promise<void>;
/** Raise hand for local user. */
raiseHand(): Promise<void>;
/** Lower hand for local user. */
lowerHand(): Promise<void>;
/** Reaction clicked by the local user. */
onReactionClick(reaction: Reaction): Promise<void>;
/** Create a stream view for a remote participants video feed. */
createStreamView(remoteUserId?: string, options?: VideoStreamOptions): Promise<void | CreateVideoStreamViewResult>;
/** Dispose of a created stream view of a remote participants video feed. */
disposeStreamView(remoteUserId?: string, options?: VideoStreamOptions): Promise<void>;
/** Dispose of a remote screen share */
disposeScreenShareStreamView(remoteUserId: string): Promise<void>;
/** Dispose of a remote video stream */
disposeRemoteVideoStreamView(remoteUserId: string): Promise<void>;
/** Dispose of the local video stream */
disposeLocalVideoStreamView(): Promise<void>;
/** Create a together mode stream view */
createTogetherModeStreamView(options?: TogetherModeStreamOptions): Promise<void | TogetherModeStreamViewResult>;
/** Start together mode for all participants */
startTogetherMode(): Promise<void>;
/** Set together mode scene size */
setTogetherModeSceneSize(width: number, height: number): void;
/** Dispose together mode video stream */
disposeTogetherModeStreamView(): Promise<void>;
/** Fetch initial Call and Chat data such as chat messages. */
fetchInitialData(): Promise<void>;
/** Send a chat message. */
sendMessage(content: string): Promise<void>;
/** Send a chat read receipt. */
sendReadReceipt(chatMessageId: string): Promise<void>;
/** Send an isTyping indicator. */
sendTypingIndicator(): Promise<void>;
/** Load previous Chat messages. */
loadPreviousChatMessages(messagesToLoad: number): Promise<boolean>;
/** Update an existing message. */
updateMessage(messageId: string, content: string, options?: Record<string, string>): Promise<void>;
/** Delete an existing message. */
deleteMessage(messageId: string): Promise<void>;
downloadResourceToCache(resourceDetails: ResourceDetails): Promise<void>;
removeResourceFromCache(resourceDetails: ResourceDetails): void;
holdCall(): Promise<void>;
resumeCall(): Promise<void>;
addParticipant(participant: PhoneNumberIdentifier, options?: AddPhoneNumberOptions): Promise<void>;
addParticipant(participant: CommunicationUserIdentifier): Promise<void>;
sendDtmfTone(dtmfTone: DtmfTone): Promise<void>;
startCaptions(options?: StartCaptionsAdapterOptions): Promise<void>;
stopCaptions(options?: StopCaptionsAdapterOptions): Promise<void>;
setCaptionLanguage(language: string): Promise<void>;
setSpokenLanguage(language: string): Promise<void>;
sendRealTimeText(text: string, isFinalized: boolean): Promise<void>;
startVideoBackgroundEffect(videoBackgroundEffect: VideoBackgroundEffect): Promise<void>;
stopVideoBackgroundEffects(): Promise<void>;
updateBackgroundPickerImages(backgroundImages: VideoBackgroundImage[]): void;
updateSelectedVideoBackgroundEffect(selectedVideoBackground: VideoBackgroundEffect): void;
startNoiseSuppressionEffect(): Promise<void>;
stopNoiseSuppressionEffect(): Promise<void>;
submitSurvey(survey: CallSurvey): Promise<CallSurveyResponse | undefined>;
startSpotlight(userIds?: string[]): Promise<void>;
stopSpotlight(userIds?: string[]): Promise<void>;
stopAllSpotlight(): Promise<void>;
muteParticipant(userId: string): Promise<void>;
muteAllRemoteParticipants(): Promise<void>;
returnFromBreakoutRoom(): Promise<void>;
forbidAudio(userIds: string[]): Promise<void>;
permitAudio(userIds: string[]): Promise<void>;
forbidOthersAudio(): Promise<void>;
permitOthersAudio(): Promise<void>;
forbidVideo(userIds: string[]): Promise<void>;
permitVideo(userIds: string[]): Promise<void>;
forbidOthersVideo(): Promise<void>;
permitOthersVideo(): Promise<void>;
on(event: 'callParticipantsJoined', listener: ParticipantsJoinedListener): void;
on(event: 'callParticipantsLeft', listener: ParticipantsLeftListener): void;
on(event: 'callEnded', listener: CallEndedListener): void;
on(event: 'callError', listener: (e: AdapterError) => void): void;
on(event: 'isMutedChanged', listener: IsMutedChangedListener): void;
on(event: 'callIdChanged', listener: CallIdChangedListener): void;
on(event: 'isLocalScreenSharingActiveChanged', listener: IsLocalScreenSharingActiveChangedListener): void;
on(event: 'displayNameChanged', listener: DisplayNameChangedListener): void;
on(event: 'isSpeakingChanged', listener: IsSpeakingChangedListener): void;
on(event: 'messageReceived', listener: MessageReceivedListener): void;
on(event: 'messageEdited', listener: MessageEditedListener): void;
on(event: 'messageDeleted', listener: MessageDeletedListener): void;
on(event: 'messageSent', listener: MessageReceivedListener): void;
on(event: 'messageRead', listener: MessageReadListener): void;
on(event: 'chatParticipantsAdded', listener: ParticipantsAddedListener): void;
on(event: 'chatParticipantsRemoved', listener: ParticipantsRemovedListener): void;
on(event: 'selectedMicrophoneChanged', listener: PropertyChangedEvent): void;
on(event: 'selectedSpeakerChanged', listener: PropertyChangedEvent): void;
on(event: 'chatError', listener: (e: AdapterError) => void): void;
on(event: 'captionsReceived', listener: CaptionsReceivedListener): void;
on(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
on(event: 'isCaptionLanguageChanged', listener: IsCaptionLanguageChangedListener): void;
on(event: 'isSpokenLanguageChanged', listener: IsSpokenLanguageChangedListener): void;
on(event: 'realTimeTextReceived', listener: RealTimeTextReceivedListener): void;
on(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
on(event: 'spotlightChanged', listener: SpotlightChangedListener): void;
on(event: 'breakoutRoomsUpdated', listener: BreakoutRoomsUpdatedListener): void;
on(event: 'chatInitialized', listener: ChatInitializedListener): void;
off(event: 'callParticipantsJoined', listener: ParticipantsJoinedListener): void;
off(event: 'callParticipantsLeft', listener: ParticipantsLeftListener): void;
off(event: 'callEnded', listener: CallEndedListener): void;
off(event: 'callError', listener: (e: AdapterError) => void): void;
off(event: 'isMutedChanged', listener: IsMutedChangedListener): void;
off(event: 'callIdChanged', listener: CallIdChangedListener): void;
off(event: 'isLocalScreenSharingActiveChanged', listener: IsLocalScreenSharingActiveChangedListener): void;
off(event: 'displayNameChanged', listener: DisplayNameChangedListener): void;
off(event: 'isSpeakingChanged', listener: IsSpeakingChangedListener): void;
off(event: 'selectedMicrophoneChanged', listener: PropertyChangedEvent): void;
off(event: 'selectedSpeakerChanged', listener: PropertyChangedEvent): void;
off(event: 'messageReceived', listener: MessageReceivedListener): void;
off(event: 'messageEdited', listener: MessageEditedListener): void;
off(event: 'messageDeleted', listener: MessageDeletedListener): void;
off(event: 'messageSent', listener: MessageReceivedListener): void;
off(event: 'messageRead', listener: MessageReadListener): void;
off(event: 'chatParticipantsAdded', listener: ParticipantsAddedListener): void;
off(event: 'chatParticipantsRemoved', listener: ParticipantsRemovedListener): void;
off(event: 'chatError', listener: (e: AdapterError) => void): void;
off(event: 'captionsReceived', listener: CaptionsReceivedListener): void;
off(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
off(event: 'isCaptionLanguageChanged', listener: IsCaptionLanguageChangedListener): void;
off(event: 'isSpokenLanguageChanged', listener: IsSpokenLanguageChangedListener): void;
off(event: 'realTimeTextReceived', listener: RealTimeTextReceivedListener): void;
off(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
off(event: 'spotlightChanged', listener: SpotlightChangedListener): void;
off(event: 'chatInitialized', listener: ChatInitializedListener): void;
off(event: 'breakoutRoomsUpdated', listener: BreakoutRoomsUpdatedListener): void;
private executeWithResolvedChatAdapter;
}
/**
* Provides a way to get the chat thread ID for a given locator.
*
* @private
*/
export interface ChatThreadProvider {
isCallInfoRequired(): boolean;
getChatThreadPromise(): Promise<string>;
getChatThread(): string;
}
/**
* Arguments for use in {@link createAzureCommunicationCallWithChatAdapter} to join a Group Call with an associated Chat thread.
* @private
*/
export declare class CallAndChatProvider implements ChatThreadProvider {
locator: CallAndChatLocator;
constructor(locator: CallAndChatLocator);
isCallInfoRequired(): boolean;
getChatThreadPromise(): Promise<string>;
getChatThread(): string;
}
/**
* Arguments for use in {@link createAzureCommunicationCallWithChatAdapter} to join a Teams meeting with an associated Chat thread.
*
* @private
*/
export declare class TeamsMeetingLinkProvider implements ChatThreadProvider {
locator: TeamsMeetingLinkLocator;
private callAdapterPromise;
private callAdapterSubscription?;
constructor(locator: TeamsMeetingLinkLocator, callAdapterPromise: Promise<CallAdapter>);
isCallInfoRequired(): boolean;
getChatThread(): string;
getChatThreadPromise(): Promise<string>;
}
/**
* Arguments for use in {@link createAzureCommunicationCallWithChatAdapter} to join a Teams meeting using meeting id.
*
* @private
*/
export declare class TeamsMeetingIdProvider implements ChatThreadProvider {
locator: TeamsMeetingIdLocator;
private callAdapter;
constructor(locator: TeamsMeetingIdLocator, callAdapter: Promise<CallAdapter>);
isCallInfoRequired(): boolean;
getChatThread(): string;
/**
* Wait call to be connected to get thread ID.
* @returns the chat thread ID for the given meeting ID.
*/
getChatThreadPromise(): Promise<string>;
}
/**
* Combination of available adapters for use in {@link createAzureCommunicationCallWithChatAdapter}.
* @public
*/
export type CommunicationAdapter = CallAndChatProvider | TeamsMeetingLinkProvider | TeamsMeetingIdProvider;
/**
* Arguments for use in {@link createAzureCommunicationCallWithChatAdapter} to join a Call with an associated Chat thread.
*
* @public
*/
export interface CallAndChatLocator {
/** Locator used by {@link createAzureCommunicationCallWithChatAdapter} to locate the call to join */
callLocator: GroupCallLocator;
/** Chat thread ID used by {@link createAzureCommunicationCallWithChatAdapter} to locate the chat thread to join */
chatThreadId: string;
}
/**
* Arguments for {@link createAzureCommunicationCallWithChatAdapter}
*
* @public
*/
export type AzureCommunicationCallWithChatAdapterArgs = {
endpoint: string;
userId: CommunicationUserIdentifier;
displayName: string;
credential: CommunicationTokenCredential;
locator: CallAndChatLocator | TeamsMeetingLinkLocator | TeamsMeetingIdLocator;
alternateCallerId?: string;
callAdapterOptions?: AzureCommunicationCallAdapterOptions;
};
/**
* Create a CallWithChatAdapter backed by Azure Communication services
* to plug into the {@link CallWithChatComposite}.
*
* @public
*/
export declare const createAzureCommunicationCallWithChatAdapter: ({ userId, displayName, credential, endpoint, locator, alternateCallerId, callAdapterOptions }: AzureCommunicationCallWithChatAdapterArgs) => Promise<CallWithChatAdapter>;
/**
* A custom React hook to simplify the creation of {@link CallWithChatAdapter}.
*
* Similar to {@link createAzureCommunicationCallWithChatAdapter}, but takes care of asynchronous
* creation of the adapter internally.
*
* Allows arguments to be undefined so that you can respect the rule-of-hooks and pass in arguments
* as they are created. The adapter is only created when all arguments are defined.
*
* Note that you must memoize the arguments to avoid recreating adapter on each render.
* See storybook for typical usage examples.
*
* @public
*/
export declare const useAzureCommunicationCallWithChatAdapter: (args: Partial<AzureCommunicationCallWithChatAdapterArgs>, afterCreate?: (adapter: CallWithChatAdapter) => Promise<CallWithChatAdapter>, beforeDispose?: (adapter: CallWithChatAdapter) => Promise<void>) => CallWithChatAdapter | undefined;
/**
* Arguments for {@link createAzureCommunicationCallWithChatAdapterFromClient}
*
* @public
*/
export type AzureCommunicationCallWithChatAdapterFromClientArgs = {
callLocator: CallAdapterLocator | TeamsMeetingLinkLocator;
callAgent: CallAgent;
callClient: StatefulCallClient;
chatClient: StatefulChatClient;
chatThreadClient: ChatThreadClient;
callAdapterOptions?: AzureCommunicationCallAdapterOptions;
};
/**
* Create a {@link CallWithChatAdapter} using the provided {@link StatefulChatClient} and {@link StatefulCallClient}.
*
* Useful if you want to keep a reference to {@link StatefulChatClient} and {@link StatefulCallClient}.
* Please note that chatThreadClient has to be created by StatefulChatClient via chatClient.getChatThreadClient(chatThreadId) API.
* Consider using {@link createAzureCommunicationCallWithChatAdapter} for a simpler API.
*
* @public
*/
export declare const createAzureCommunicationCallWithChatAdapterFromClients: ({ callClient, callAgent, callLocator, chatClient, chatThreadClient, callAdapterOptions }: AzureCommunicationCallWithChatAdapterFromClientArgs) => Promise<CallWithChatAdapter>;
/**
* Create a {@link CallWithChatAdapter} from the underlying adapters.
*
* This is an internal factory function used by browser tests to inject fake adapters for call and chat.
*
* @internal
*/
export declare const _createAzureCommunicationCallWithChatAdapterFromAdapters: (callAdapter: CallAdapter, chatAdapter: ChatAdapter) => CallWithChatAdapter;
//# sourceMappingURL=AzureCommunicationCallWithChatAdapter.d.ts.map