Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support joining an existing call in the CallComposite & CallWithChatComposite #5148

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "minor",
"area": "feature",
"workstream": "",
"comment": "Support Composites joining existing calls by updating CallAdapter and CallWithChatAdapters to take an existing call as a contruction parameter instead of a locator.",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "minor",
"area": "feature",
"workstream": "",
"comment": "Support Composites joining existing calls by updating CallAdapter and CallWithChatAdapters to take an existing call as a contruction parameter instead of a locator.",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
13 changes: 11 additions & 2 deletions packages/calling-stateful-client/src/TypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { Call, CallAgent, TeamsCallAgent, IncomingCallCommon } from '@azure/communication-calling';
import { CallAgentCommon, CallCommon, TeamsCall } from './BetaToStableTypes';
import { CallState } from './CallClientState';

/**
* @internal
Expand Down Expand Up @@ -47,8 +48,16 @@ export const _isACSIncomingCall = (call: IncomingCallCommon): boolean => {
};

/**
* Heuristic to detect if a call is a Teams meeting call.
* `threadId` is only available when the call is connected.
* `InLobby` state is only available for Teams calls currently.
*
* @remarks
* This is a heuristic is not accurate when the call is in the connecting or earlymedia states.
* If ACS group calls or rooms calls support threadId or InLobby state, this heuristic will need to be updated.
*
* @internal
*/
export const _isTeamsMeeting = (call: CallCommon): boolean => {
return 'info' in call && !!call.info.threadId;
export const _isTeamsMeeting = (call: CallCommon | CallState): boolean => {
return ('info' in call && !!call.info?.threadId) || call.state === 'InLobby';
};
2 changes: 1 addition & 1 deletion packages/calling-stateful-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export * from './index-public';

export { _createStatefulCallClientInner } from './StatefulCallClient';

export { _isACSCall, _isACSCallAgent, _isTeamsCall, _isTeamsCallAgent } from './TypeGuards';
export { _isACSCall, _isACSCallAgent, _isTeamsCall, _isTeamsCallAgent, _isTeamsMeeting } from './TypeGuards';

export type { CallAgentCommon, CallCommon, TeamsCall } from './BetaToStableTypes';
Original file line number Diff line number Diff line change
Expand Up @@ -2630,11 +2630,24 @@ export function createAzureCommunicationCallAdapterFromClient(callClient: Statef
// @public
export function createAzureCommunicationCallAdapterFromClient(callClient: StatefulCallClient, callAgent: CallAgent, locator: CallAdapterLocator, options?: AzureCommunicationCallAdapterOptions): Promise<CallAdapter>;

// @public
export function createAzureCommunicationCallAdapterFromClient(callClient: StatefulCallClient, callAgent: CallAgent, call: Call, options?: AzureCommunicationCallAdapterOptions): Promise<CallAdapter>;

// @public
export const createAzureCommunicationCallWithChatAdapter: ({ userId, displayName, credential, endpoint, locator, alternateCallerId, callAdapterOptions }: AzureCommunicationCallWithChatAdapterArgs) => Promise<CallWithChatAdapter>;

// @public
export const createAzureCommunicationCallWithChatAdapterFromClients: ({ callClient, callAgent, callLocator, chatClient, chatThreadClient, callAdapterOptions }: AzureCommunicationCallWithChatAdapterFromClientArgs) => Promise<CallWithChatAdapter>;
export function createAzureCommunicationCallWithChatAdapterFromClients(args: AzureCommunicationCallWithChatAdapterFromClientArgs): Promise<CallWithChatAdapter>;

// @public
export function createAzureCommunicationCallWithChatAdapterFromClients(args: {
callClient: StatefulCallClient;
callAgent: CallAgent;
call: Call;
chatClient: StatefulChatClient;
chatThreadClient: ChatThreadClient;
callAdapterOptions?: AzureCommunicationCallAdapterOptions;
}): Promise<CallWithChatAdapter>;

// @public
export const createAzureCommunicationChatAdapter: ({ endpoint: endpointUrl, userId, displayName, credential, threadId }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2260,11 +2260,24 @@ export function createAzureCommunicationCallAdapterFromClient(callClient: Statef
// @public
export function createAzureCommunicationCallAdapterFromClient(callClient: StatefulCallClient, callAgent: CallAgent, locator: CallAdapterLocator, options?: AzureCommunicationCallAdapterOptions): Promise<CallAdapter>;

// @public
export function createAzureCommunicationCallAdapterFromClient(callClient: StatefulCallClient, callAgent: CallAgent, call: Call, options?: AzureCommunicationCallAdapterOptions): Promise<CallAdapter>;

// @public
export const createAzureCommunicationCallWithChatAdapter: ({ userId, displayName, credential, endpoint, locator, alternateCallerId, callAdapterOptions }: AzureCommunicationCallWithChatAdapterArgs) => Promise<CallWithChatAdapter>;

// @public
export const createAzureCommunicationCallWithChatAdapterFromClients: ({ callClient, callAgent, callLocator, chatClient, chatThreadClient, callAdapterOptions }: AzureCommunicationCallWithChatAdapterFromClientArgs) => Promise<CallWithChatAdapter>;
export function createAzureCommunicationCallWithChatAdapterFromClients(args: AzureCommunicationCallWithChatAdapterFromClientArgs): Promise<CallWithChatAdapter>;

// @public
export function createAzureCommunicationCallWithChatAdapterFromClients(args: {
callClient: StatefulCallClient;
callAgent: CallAgent;
call: Call;
chatClient: StatefulChatClient;
chatThreadClient: ChatThreadClient;
callAdapterOptions?: AzureCommunicationCallAdapterOptions;
}): Promise<CallWithChatAdapter>;

// @public
export const createAzureCommunicationChatAdapter: ({ endpoint: endpointUrl, userId, displayName, credential, threadId }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
StatefulCallClient,
StatefulDeviceManager,
TeamsCall,
_isACSCall,
_isTeamsCall
_isACSCall
} from '@internal/calling-stateful-client';
import { AcceptedTransfer } from '@internal/calling-stateful-client';
import { _isTeamsCallAgent } from '@internal/calling-stateful-client';
Expand Down Expand Up @@ -86,7 +85,16 @@ import {
VideoBackgroundReplacementEffect
} from './CallAdapter';
import { TeamsCallAdapter } from './CallAdapter';
import { getCallCompositePage, getLocatorOrTargetCallees, IsCallEndedPage, isCameraOn } from '../utils';
import {
getCallCompositePage,
isCall,
IsCallEndedPage,
isCameraOn,
isDetectedAsRoomsCall,
isDetectedAsTeamsCallKind,
isDetectedAsTeamsMeeting,
isTargetCallees
} from '../utils';
import { CreateVideoStreamViewResult, VideoStreamOptions } from '@internal/react-components';
import { toFlatCommunicationIdentifier, _toCommunicationIdentifier, _isValidIdentifier } from '@internal/acs-ui-common';
import {
Expand All @@ -96,8 +104,7 @@ import {
MicrosoftTeamsUserIdentifier,
isMicrosoftTeamsUserIdentifier,
MicrosoftTeamsAppIdentifier,
UnknownIdentifier,
isMicrosoftTeamsAppIdentifier
UnknownIdentifier
} from '@azure/communication-common';
import { isCommunicationUserIdentifier } from '@azure/communication-common';
import { isPhoneNumberIdentifier, PhoneNumberIdentifier } from '@azure/communication-common';
Expand Down Expand Up @@ -139,13 +146,12 @@ class CallContext {
private emitter: EventEmitter = new EventEmitter();
private state: CallContextState;
private callId: string | undefined;
private locator: CallAdapterLocator | undefined;
private displayNameModifier: AdapterStateModifier | undefined;

constructor(
clientState: CallClientState,
isTeamsCall: boolean,
isTeamsMeeting: boolean,
isRoomsCall: boolean,
locator: CallAdapterLocator | undefined,
options?: {
maxListeners?: number;
onFetchProfile?: OnFetchProfileCallback;
Expand All @@ -164,19 +170,20 @@ class CallContext {
},
targetCallees?: StartCallIdentifier[]
) {
this.locator = locator;
this.state = {
isLocalPreviewMicrophoneEnabled: false,
userId: clientState.userId,
displayName: clientState.callAgent?.displayName,
devices: clientState.deviceManager,
call: undefined,
isTeamsMeeting: isDetectedAsTeamsMeeting(locator, undefined),
isTeamsCall: isDetectedAsTeamsCallKind(targetCallees, undefined),
isRoomsCall: isDetectedAsRoomsCall(locator, undefined),
targetCallees: targetCallees as CommunicationIdentifier[],
page: 'configuration',
latestErrors: clientState.latestErrors,
/* @conditional-compile-remove(breakout-rooms) */ latestNotifications: clientState.latestNotifications,
isTeamsCall,
isTeamsMeeting,
isRoomsCall,
alternateCallerId: options?.alternateCallerId,
environmentInfo: clientState.environmentInfo,
/* @conditional-compile-remove(unsupported-browser) */ unsupportedBrowserVersionsAllowed: false,
Expand Down Expand Up @@ -269,6 +276,7 @@ class CallContext {
environmentInfo: this.state.environmentInfo,
unsupportedBrowserVersionOptedIn: this.state.unsupportedBrowserVersionsAllowed
};
const targetCallees = this.state.targetCallees;

const latestAcceptedTransfer = call?.transfer.acceptedTransfers
? findLatestAcceptedTransfer(call.transfer.acceptedTransfers)
Expand Down Expand Up @@ -313,7 +321,10 @@ class CallContext {
clientState.deviceManager.unparentedViews.find((s) => s.mediaStreamType === 'Video')
? 'On'
: 'Off',
acceptedTransferCallState: transferCall
acceptedTransferCallState: transferCall,
isTeamsMeeting: isDetectedAsTeamsMeeting(this.locator, call),
isTeamsCall: isDetectedAsTeamsCallKind(targetCallees, call),
isRoomsCall: isDetectedAsRoomsCall(this.locator, call)
});
}
}
Expand Down Expand Up @@ -420,44 +431,37 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
);
constructor(
callClient: StatefulCallClient,
locatorOrTargetCalless: CallAdapterLocator | StartCallIdentifier[],
call: Call,
callAgent: AgentType,
deviceManager: StatefulDeviceManager,
options?: AzureCommunicationCallAdapterOptions | TeamsAdapterOptions
);
constructor(
callClient: StatefulCallClient,
overloadedParam: CallAdapterLocator | StartCallIdentifier[] | Call,
callAgent: AgentType,
deviceManager: StatefulDeviceManager,
options?: AzureCommunicationCallAdapterOptions | TeamsAdapterOptions
) {
this.bindPublicMethods();
this.callClient = callClient;
this.callAgent = callAgent;
this.targetCallees =
getLocatorOrTargetCallees(locatorOrTargetCalless) === true
? (locatorOrTargetCalless as StartCallIdentifier[])
: undefined;
this.locator =
getLocatorOrTargetCallees(locatorOrTargetCalless) === false
? (locatorOrTargetCalless as CallAdapterLocator)
: undefined;
this.deviceManager = deviceManager;
const isTeamsMeeting = this.locator ? 'meetingLink' in this.locator || 'meetingId' in this.locator : false;
let isTeamsCall: boolean | undefined;
this.targetCallees?.forEach((callee) => {
if (isMicrosoftTeamsUserIdentifier(callee) || isMicrosoftTeamsAppIdentifier(callee)) {
isTeamsCall = true;
}
});

const isRoomsCall = this.locator ? 'roomId' in this.locator : false;
let overloadedParamAsCall: Call | undefined = undefined;
if (isTargetCallees(overloadedParam)) {
this.targetCallees = overloadedParam;
} else if (isCall(overloadedParam)) {
overloadedParamAsCall = overloadedParam;
} else {
this.locator = overloadedParam;
}

this.deviceManager = deviceManager;

this.onResolveVideoBackgroundEffectsDependency = options?.videoBackgroundOptions?.onResolveDependency;
this.onResolveDeepNoiseSuppressionDependency = options?.deepNoiseSuppressionOptions?.onResolveDependency;

this.context = new CallContext(
callClient.getState(),
!!isTeamsCall,
isTeamsMeeting,
isRoomsCall,
options,
this.targetCallees
);
this.context = new CallContext(callClient.getState(), this.locator, options, this.targetCallees);

this.context.onCallEnded((endCallData) => this.emitter.emit('callEnded', endCallData));

Expand Down Expand Up @@ -560,6 +564,10 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
};
(this.callAgent as TeamsCallAgent).on('callsUpdated', onTeamsCallsUpdated);
}

if (overloadedParamAsCall) {
this.processNewCall(overloadedParamAsCall);
}
}

// TODO: update this to include the 'selectedCameraChanged' when calling adds it to the device manager
Expand Down Expand Up @@ -2175,30 +2183,33 @@ export async function createAzureCommunicationCallAdapterFromClient(
export async function createAzureCommunicationCallAdapterFromClient(
callClient: StatefulCallClient,
callAgent: CallAgent,
locatorOrtargetCallees: CallAdapterLocator | StartCallIdentifier[],
call: Call,
options?: AzureCommunicationCallAdapterOptions
): Promise<CallAdapter>;
/**
* Implementation of overloads for {@link createAzureCommunicationCallAdapterFromClient}.
*
* @private
*/
export async function createAzureCommunicationCallAdapterFromClient(
callClient: StatefulCallClient,
callAgent: CallAgent,
overloadedParam: CallAdapterLocator | StartCallIdentifier[] | Call,
options?: AzureCommunicationCallAdapterOptions
): Promise<CallAdapter> {
const deviceManager = (await callClient.getDeviceManager()) as StatefulDeviceManager;
await Promise.all([deviceManager.getCameras(), deviceManager.getMicrophones()]);
if (deviceManager.isSpeakerSelectionAvailable) {
await deviceManager.getSpeakers();
}
if (getLocatorOrTargetCallees(locatorOrtargetCallees)) {
return new AzureCommunicationCallAdapter(
callClient,
locatorOrtargetCallees as StartCallIdentifier[],
callAgent,
deviceManager,
options
);
/* @conditional-compile-remove(unsupported-browser) */
await callClient.feature(Features.DebugInfo).getEnvironmentInfo();
if (isTargetCallees(overloadedParam)) {
return new AzureCommunicationCallAdapter(callClient, overloadedParam, callAgent, deviceManager, options);
} else if (isCall(overloadedParam)) {
return new AzureCommunicationCallAdapter(callClient, overloadedParam, callAgent, deviceManager, options);
} else {
return new AzureCommunicationCallAdapter(
callClient,
locatorOrtargetCallees as CallAdapterLocator,
callAgent,
deviceManager,
options
);
return new AzureCommunicationCallAdapter(callClient, overloadedParam, callAgent, deviceManager, options);
}
}

Expand Down
Loading
Loading