Skip to content

Fix listeners for chat events of AzureCommunicationCallWithChatAdapter when the threadId changes#5764

Merged
mgamis-msft merged 9 commits intomainfrom
mgamis/fix-chat-event-listening-in-call-with-chat-adapter
Apr 10, 2025
Merged

Fix listeners for chat events of AzureCommunicationCallWithChatAdapter when the threadId changes#5764
mgamis-msft merged 9 commits intomainfrom
mgamis/fix-chat-event-listening-in-call-with-chat-adapter

Conversation

@mgamis-msft
Copy link
Copy Markdown
Contributor

@mgamis-msft mgamis-msft commented Apr 7, 2025

What

Add map of listeners for chat events so that old chat adapter listeners can be propagated to newly created chat adapters. This will fix listeners for chat events when:

  • the thread Id is resolved late in callInfo when joining a Teams meeting link
  • the thread Id is changed when moving to and from breakout rooms

Why

Resolves one of the issue from #5755 regarding not being able chat event listeners not working when joining a breakout room

How Tested

Tested with code from reverted commit on this branch

Process & policy checklist

  • I have updated the project documentation to reflect my changes if necessary.
  • I have read the CONTRIBUTING documentation.

Is this a breaking change?

  • This change causes current functionality to break.

…hen the thread id is resolved late or is changed when moving to and from breakout rooms
This reverts commit 5e1c043.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2025

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2025

@azure/communication-react jest test coverage for stable.

Lines Statements Functions Branches
Base 28162 / 44748
62.93%
28162 / 44748
62.93%
788 / 1439
54.76%
2347 / 3725
63%
Current 28102 / 44748
62.8%
28102 / 44748
62.8%
788 / 1439
54.76%
2344 / 3720
63.01%
Diff -60 / 0
-0.13%
-60 / 0
-0.13%
0 / 0
0%
-3 / -5
0.01%

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2025

@azure/communication-react jest test coverage for beta.

Lines Statements Functions Branches
Base 58502 / 94727
61.75%
58502 / 94727
61.75%
1181 / 2703
43.69%
3542 / 5848
60.56%
Current 58553 / 94780
61.77%
58553 / 94780
61.77%
1182 / 2706
43.68%
3530 / 5848
60.36%
Diff 51 / 53
0.02%
51 / 53
0.02%
1 / 3
-0.01%
-12 / 0
-0.2%

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2025

private originCallChatAdapter: ChatAdapter | undefined;
private breakoutRoomChatAdapter: ChatAdapter | undefined;

private chatEventListeners: Map<string, Listener[]> = new Map();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a detailed comment here why the need to track and store all chat event listeners manually

private originCallChatAdapter: ChatAdapter | undefined;
private breakoutRoomChatAdapter: ChatAdapter | undefined;

private chatEventListeners: Map<string, Listener[]> = new Map();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a Set instead of array to ensure no duplicates and syntactically inform the reader that it is designed for uniqueness

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your add/remove functions won't then need to recreate the array, but can just use set.add and set.remove

}

private updateChatEventListeners(chatAdapter: ChatAdapter): void {
const messageReceivedListeners = this.getListeners('messageReceived');
Copy link
Copy Markdown
Member

@JamesBurnside JamesBurnside Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if someone adds a new event it will be easy to miss adding it here, can you instead more blindly iterate over the listeners?
e.g. (untested)

for (const [eventName, listeners] of this.chatEventListeners) {
  for (const listener of listeners) {
    this.chatAdapter?.off('eventName', listener);
    chatAdapter.on('eventName', listener);
  }
}

(might have to use as any to satisfy typescript

private originCallChatAdapter: ChatAdapter | undefined;
private breakoutRoomChatAdapter: ChatAdapter | undefined;

private chatEventListeners: Map<string, Listener[]> = new Map();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup (empty) this variable in the dispose function

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2025

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2025

@mgamis-msft mgamis-msft enabled auto-merge (squash) April 10, 2025 17:14
@github-actions
Copy link
Copy Markdown
Contributor

CallWithChat bundle size is not changed.

  • Current size: 12413510
  • Base size: 12413510
  • Diff size: 0

@github-actions
Copy link
Copy Markdown
Contributor

Calling bundle size is not changed.

  • Current size: 12413497
  • Base size: 12413497
  • Diff size: 0

@github-actions
Copy link
Copy Markdown
Contributor

Chat bundle size is not changed.

  • Current size: 1780243
  • Base size: 1780243
  • Diff size: 0

@github-actions
Copy link
Copy Markdown
Contributor

@mgamis-msft mgamis-msft merged commit 6237678 into main Apr 10, 2025
41 checks passed
@mgamis-msft mgamis-msft deleted the mgamis/fix-chat-event-listening-in-call-with-chat-adapter branch April 10, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants