Skip to content

Commit 3c79665

Browse files
authored
fix: added call state update for handling case when call.ring event as not triggered (#2035)
### 💡 Overview The case: when creating a ring type call with `getOrCreate` method, ws `call.created` event triggers first (for some reason `call.ring` is not detected) –> it creates a call instance with `ringing` property set to false and registers it in the state store. After that we handle response in `getOrCreateMethod` which tries to register the call (at this point with `ringing` set to true) which is skipped as the call was already registered. So in this scenario `useCalls` doesn't return the ringing call. ### 📝 Implementation notes The fix adds register or update method, which will override call properties inside `get` and `getOrCreate` methods, which fixes behavior in the case described above. 🎫 Ticket: https://linear.app/stream/issue/RN-315/create-ring-type-call-issue
1 parent 1aa72c8 commit 3c79665

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/client/src/Call.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ export class Call {
757757

758758
if (this.streamClient._hasConnectionID()) {
759759
this.watching = true;
760-
this.clientStore.registerCall(this);
760+
this.clientStore.registerOrUpdateCall(this);
761761
}
762762

763763
await this.applyDeviceConfig(response.call.settings, false);
@@ -787,7 +787,7 @@ export class Call {
787787

788788
if (this.streamClient._hasConnectionID()) {
789789
this.watching = true;
790-
this.clientStore.registerCall(this);
790+
this.clientStore.registerOrUpdateCall(this);
791791
}
792792

793793
await this.applyDeviceConfig(response.call.settings, false);

packages/client/src/store/stateStore.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ export class StreamVideoWriteableStateStore {
8181
}
8282
};
8383

84+
/**
85+
* Registers a {@link Call} object if it doesn't exist, otherwise updates it.
86+
*
87+
* @param call the call to register or update.
88+
*/
89+
registerOrUpdateCall = (call: Call) => {
90+
if (this.calls.find((c) => c.cid === call.cid)) {
91+
return this.setCalls((calls) =>
92+
calls.map((c) => (c.cid === call.cid ? call : c)),
93+
);
94+
} else {
95+
return this.registerCall(call);
96+
}
97+
};
98+
8499
/**
85100
* Removes a {@link Call} object from the list of {@link Call} objects created/tracked by this client.
86101
*

0 commit comments

Comments
 (0)