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

Mark adapter.dispose as async, Add dispose option to ignore disposing of the callAgent #5329

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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": "patch",
"area": "fix",
"workstream": "",
"comment": "Add option to callAdapter and callWithChatAdapter dispose methods to not dispose of the callAgent",
"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": "fix",
"workstream": "",
"comment": "Update callAdapter.dispose and callWithChatAdapter.dispose to be async to match underlying behavior",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "",
"comment": "Add option to callAdapter and callWithChatAdapter dispose methods to not dispose of the callAgent",
"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": "fix",
"workstream": "",
"comment": "Update callAdapter.dispose and callWithChatAdapter.dispose to be async to match underlying behavior",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,10 @@ export interface CallSurveyImprovementSuggestions {
}

// @public
export interface CallWithChatAdapter extends CallWithChatAdapterManagement, AdapterState<CallWithChatAdapterState>, Disposable_2, CallWithChatAdapterSubscriptions {
export interface CallWithChatAdapter extends CallWithChatAdapterManagement, AdapterState<CallWithChatAdapterState>, CallWithChatAdapterSubscriptions {
dispose(options?: {
doNotDisposeCallAgent?: boolean;
}): Promise<void>;
}

// @public
Expand Down Expand Up @@ -2087,7 +2090,10 @@ export type ClientState = CallClientState & ChatClientState;
export type Common<A, B> = Pick<A, CommonProperties<A, B>>;

// @public
export interface CommonCallAdapter extends AdapterState<CallAdapterState>, Disposable_2, CallAdapterCallOperations, CallAdapterDeviceManagement, CallAdapterSubscribers {
export interface CommonCallAdapter extends AdapterState<CallAdapterState>, CallAdapterCallOperations, CallAdapterDeviceManagement, CallAdapterSubscribers {
dispose(options?: {
doNotDisposeCallAgent?: boolean;
}): Promise<void>;
// @deprecated
joinCall(microphoneOn?: boolean): void;
joinCall(options?: JoinCallOptions): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,10 @@ export interface CallSurveyImprovementSuggestions {
}

// @public
export interface CallWithChatAdapter extends CallWithChatAdapterManagement, AdapterState<CallWithChatAdapterState>, Disposable_2, CallWithChatAdapterSubscriptions {
export interface CallWithChatAdapter extends CallWithChatAdapterManagement, AdapterState<CallWithChatAdapterState>, CallWithChatAdapterSubscriptions {
dispose(options?: {
doNotDisposeCallAgent?: boolean;
}): Promise<void>;
}

// @public
Expand Down Expand Up @@ -1805,7 +1808,10 @@ export type ClientState = CallClientState & ChatClientState;
export type Common<A, B> = Pick<A, CommonProperties<A, B>>;

// @public
export interface CommonCallAdapter extends AdapterState<CallAdapterState>, Disposable_2, CallAdapterCallOperations, CallAdapterDeviceManagement, CallAdapterSubscribers {
export interface CommonCallAdapter extends AdapterState<CallAdapterState>, CallAdapterCallOperations, CallAdapterDeviceManagement, CallAdapterSubscribers {
dispose(options?: {
doNotDisposeCallAgent?: boolean;
}): Promise<void>;
// @deprecated
joinCall(microphoneOn?: boolean): void;
joinCall(options?: JoinCallOptions): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class _MockCallAdapter implements CallAdapter {
getState(): CallAdapterState {
return this.state;
}
dispose(): void {
dispose(): Promise<void> {
throw Error('dispose not implemented');
}
joinCall(): Call | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,12 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
this.muteAllRemoteParticipants.bind(this);
}

public dispose(): void {
public async dispose(options?: { doNotDisposeCallAgent?: boolean }): Promise<void> {
this.resetDiagnosticsForwarder();
this.callClient.offStateChange(this.onClientStateChange);
this.callAgent.dispose();
if (!options?.doNotDisposeCallAgent) {
await this.callAgent.dispose();
}
}

public async queryCameras(): Promise<VideoDeviceInfo[]> {
Expand Down Expand Up @@ -1921,7 +1923,7 @@ function useAzureCommunicationCallAdapterGeneric<
if (beforeDisposeRef.current) {
await beforeDisposeRef.current(adapterRef.current);
}
adapterRef.current.dispose();
await adapterRef.current.dispose();
adapterRef.current = undefined;
}
let newAdapter: Adapter | undefined = undefined;
Expand Down Expand Up @@ -2015,7 +2017,7 @@ function useAzureCommunicationCallAdapterGeneric<
if (beforeDisposeRef.current) {
await beforeDisposeRef.current(adapterRef.current);
}
adapterRef.current.dispose();
await adapterRef.current.dispose();
adapterRef.current = undefined;
}
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { AddPhoneNumberOptions } from '@azure/communication-calling';
import { DtmfTone } from '@azure/communication-calling';
import { CommunicationIdentifier } from '@azure/communication-common';
import type { CommunicationUserIdentifier, PhoneNumberIdentifier } from '@azure/communication-common';
import type { AdapterState, Disposable, AdapterError, AdapterErrors } from '../../common/adapters';
import type { AdapterState, AdapterError, AdapterErrors } from '../../common/adapters';
/* @conditional-compile-remove(breakout-rooms) */
import type { AdapterNotifications } from '../../common/adapters';
import {
Expand Down Expand Up @@ -1106,10 +1106,13 @@ export interface CallAdapterCallManagement extends CallAdapterCallOperations {
*/
export interface CommonCallAdapter
extends AdapterState<CallAdapterState>,
Disposable,
CallAdapterCallOperations,
CallAdapterDeviceManagement,
CallAdapterSubscribers {
/**
* Dispose of the adapter. This performs cleanup of resources.
*/
dispose(options?: { doNotDisposeCallAgent?: boolean }): Promise<void>;
/**
* Join the call with microphone initially on/off.
* @deprecated Use joinCall(options?:JoinCallOptions) instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,14 @@ export class AzureCommunicationCallWithChatAdapter implements CallWithChatAdapte
return this.context.getState();
}
/** Dispose of the current CallWithChatAdapter. */
public dispose(): void {
public async dispose(options?: { doNotDisposeCallAgent?: boolean }): Promise<void> {
this.isAdapterDisposed = true;
if (this.chatAdapter) {
this.chatAdapter.offStateChange(this.onChatStateChange);
this.chatAdapter.dispose();
}
this.callAdapter.offStateChange(this.onCallStateChange);
this.callAdapter.dispose();
await this.callAdapter.dispose(options);
}
/** Remove a participant from the Call only. */
public async removeParticipant(userId: string | CommunicationIdentifier): Promise<void> {
Expand Down Expand Up @@ -1288,7 +1288,7 @@ export const useAzureCommunicationCallWithChatAdapter = (
if (beforeDisposeRef.current) {
await beforeDisposeRef.current(adapterRef.current);
}
adapterRef.current.dispose();
await adapterRef.current.dispose();
adapterRef.current = undefined;
}
if (creatingAdapterRef.current) {
Expand Down Expand Up @@ -1338,7 +1338,7 @@ export const useAzureCommunicationCallWithChatAdapter = (
if (beforeDisposeRef.current) {
await beforeDisposeRef.current(adapterRef.current);
}
adapterRef.current.dispose();
await adapterRef.current.dispose();
adapterRef.current = undefined;
}
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '../../ChatComposite';
import { ResourceDetails } from '../../ChatComposite';
import { CallWithChatAdapterState } from '../state/CallWithChatAdapterState';
import type { AdapterError, AdapterState, Disposable } from '../../common/adapters';
import type { AdapterError, AdapterState } from '../../common/adapters';
import {
AudioDeviceInfo,
Call,
Expand Down Expand Up @@ -595,8 +595,12 @@ export type ChatInitializedListener = (event: { adapter: CallWithChatAdapter })
export interface CallWithChatAdapter
extends CallWithChatAdapterManagement,
AdapterState<CallWithChatAdapterState>,
Disposable,
CallWithChatAdapterSubscriptions {}
CallWithChatAdapterSubscriptions {
/**
* Dispose of the adapter. This performs cleanup of resources.
*/
dispose(options?: { doNotDisposeCallAgent?: boolean }): Promise<void>;
}

/**
* Events fired off by the {@link CallWithChatAdapter}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export class CallWithChatBackedCallAdapter implements CallAdapter {
};
public getState = (): CallAdapterState =>
callAdapterStateFromCallWithChatAdapterState(this.callWithChatAdapter.getState());
public dispose = (): void => this.callWithChatAdapter.dispose();
public dispose = (options?: { doNotDisposeCallAgent?: boolean }): Promise<void> =>
this.callWithChatAdapter.dispose(options);
public joinCall = (options?: boolean | JoinCallOptions): Call | undefined => {
if (typeof options === 'boolean') {
return this.callWithChatAdapter.joinCall(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class CallWithChatBackedChatAdapter implements ChatAdapter {
await this.callWithChatAdapter.removeParticipant(userId);
public loadPreviousChatMessages = async (messagesToLoad: number): Promise<boolean> =>
await this.callWithChatAdapter.loadPreviousChatMessages(messagesToLoad);
public dispose = (): void => this.callWithChatAdapter.dispose();
public dispose = (): Promise<void> => this.callWithChatAdapter.dispose();

public onStateChange = (handler: (state: ChatAdapterState) => void): void => {
const convertedHandler = (state: CallWithChatAdapterState): void => {
Expand Down
4 changes: 3 additions & 1 deletion packages/react-composites/tests/app/call/LiveApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function LiveApp(props: { queryArgs: QueryArgs }): JSX.Element {
setCallAdapter(wrapAdapterForTests(await createCallAdapterWithCredentials(queryArgs)));
})();

return () => callAdapter && callAdapter.dispose();
return () => {
callAdapter && callAdapter.dispose();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [queryArgs]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class MockCallAdapter implements CallAdapter {
allowUnsupportedBrowserVersion(): void {
throw Error('allowWithUnsupportedBrowserVersion not implemented');
}
dispose(): void {
dispose(): Promise<void> {
throw Error('dispose not implemented');
}
joinCall(): Call | undefined {
Expand Down
2 changes: 1 addition & 1 deletion samples/CallWithChat/src/app/views/CallScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const CallScreen = (props: CallScreenProps): JSX.Element => {
// This ensures the service knows the user intentionally left the call if the user
// closed the browser tab during an active call.
useEffect(() => {
const disposeAdapter = (): void => adapter?.dispose();
const disposeAdapter = async (): Promise<void> => await adapter?.dispose();
window.addEventListener('beforeunload', disposeAdapter);
return () => window.removeEventListener('beforeunload', disposeAdapter);
}, [adapter]);
Expand Down
2 changes: 1 addition & 1 deletion samples/Calling/src/app/views/CallCompositeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const CallCompositeContainer = (props: CallCompositeContainerProps): JSX.
// This ensures the service knows the user intentionally left the call if the user
// closed the browser tab during an active call.
useEffect(() => {
const disposeAdapter = (): void => adapter?.dispose();
const disposeAdapter = async (): Promise<void> => await adapter?.dispose();
window.addEventListener('beforeunload', disposeAdapter);
return () => window.removeEventListener('beforeunload', disposeAdapter);
}, [adapter]);
Expand Down
Loading