Skip to content

Commit 95f7927

Browse files
authored
Fixed in code where using Splice inside foreach (#5869)
* fix splice * Change files * update
1 parent 0408cea commit 95f7927

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "patch",
3+
"area": "fix",
4+
"workstream": "Fixed in code where using splice inside foreach",
5+
"comment": "Fixed in code where using splice inside foreach",
6+
"packageName": "@azure/communication-react",
7+
"email": "96077406+carocao-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "patch",
3+
"area": "fix",
4+
"workstream": "Fixed in code where using splice inside foreach",
5+
"comment": "Fixed in code where using splice inside foreach",
6+
"packageName": "@azure/communication-react",
7+
"email": "96077406+carocao-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

packages/calling-stateful-client/src/CallContext.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,18 +1244,19 @@ export class CallContext {
12441244
// if inProgressRealTimeTexts is an array
12451245
if (inProgressRealTimeTexts && Array.isArray(inProgressRealTimeTexts)) {
12461246
// find the in progress real time text that has not been updated for 5 seconds
1247-
inProgressRealTimeTexts.forEach((realTimeText, index) => {
1248-
if (realTimeText.updatedTimestamp && Date.now() - realTimeText.updatedTimestamp.getTime() > 5000) {
1247+
for (let i = inProgressRealTimeTexts.length - 1; i >= 0; i--) {
1248+
const realTimeText = inProgressRealTimeTexts[i];
1249+
if (realTimeText?.updatedTimestamp && Date.now() - realTimeText?.updatedTimestamp.getTime() > 5000) {
12491250
// turn the in progress real time text to final
12501251
realTimeText.resultType = 'Final';
12511252
// move the in progress real time text to completed
12521253
completedRealTimeTexts.push(realTimeText);
12531254
// remove the in progress real time text from in progress
12541255
if (inProgressRealTimeTexts) {
1255-
(inProgressRealTimeTexts as RealTimeTextInfo[]).splice(index, 1);
1256+
inProgressRealTimeTexts.splice(i, 1);
12561257
}
12571258
}
1258-
});
1259+
}
12591260
} else {
12601261
// if inProgressRealTimeTexts is a single object
12611262
if (

packages/react-composites/src/composites/CallComposite/CallComposite.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,10 @@ const MainScreen = (props: MainScreenProps): JSX.Element => {
527527

528528
useEffect(() => {
529529
if (complianceNotification) {
530-
activeNotifications.forEach((notification, index) => {
530+
for (let i = activeNotifications.length - 1; i >= 0; i--) {
531+
const notification = activeNotifications[i];
531532
if (
533+
notification &&
532534
[
533535
'recordingStarted',
534536
'transcriptionStarted',
@@ -540,9 +542,9 @@ const MainScreen = (props: MainScreenProps): JSX.Element => {
540542
'transcriptionStoppedStillRecording'
541543
].includes(notification.type)
542544
) {
543-
activeNotifications.splice(index, 1);
545+
activeNotifications.splice(i, 1);
544546
}
545-
});
547+
}
546548
activeNotifications.push(complianceNotification);
547549
}
548550
setTrackedNotifications((prev) => updateTrackedNotificationsWithActiveNotifications(prev, activeNotifications));

0 commit comments

Comments
 (0)