Skip to content

Commit

Permalink
Fix member.updated event in case of missing entry in cache (#640)
Browse files Browse the repository at this point in the history
* add comment

* set member in cache for member.updated in case of missing entry

* changeset
  • Loading branch information
edolix authored Sep 5, 2022
1 parent 1ba9daa commit 0e7bffd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-houses-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/core': patch
---

Dispatch `member.updated` event in case of the local cache is empty.
14 changes: 12 additions & 2 deletions packages/core/src/memberPosition/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ export const memberPositionWorker: SDKWorker<any> =
const { swEventChannel } = channels
let memberList = initializeMemberList(initialState)

const addToMemberList = (payload: VideoMemberUpdatedEventParams) => {
/**
* Add to memberList for both `member.joined` and `member.updated`
* note: changes made for audience users.
*/
if (!memberList.has(payload.member.id)) {
memberList.set(payload.member.id, payload)
}
}

while (true) {
const action = yield sagaEffects.take(swEventChannel, (action: any) => {
const istargetEvent =
Expand All @@ -164,6 +174,7 @@ export const memberPositionWorker: SDKWorker<any> =

switch (action.type) {
case 'video.member.updated': {
addToMemberList(action.payload)
yield fork(memberUpdatedWorker, {
action,
channels,
Expand All @@ -173,8 +184,7 @@ export const memberPositionWorker: SDKWorker<any> =
break
}
case 'video.member.joined': {
const member = action.payload.member
memberList.set(member.id, action.payload)
addToMemberList(action.payload)
break
}
case 'video.member.left': {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/redux/features/session/sessionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function* sessionChannelWatcher({
}
case 'video.member.updated': {
/**
* @see memberUpdatedWorker in packages/core/src/memberPosition/workers.ts
* `video.member.updated` is handled by the
* layoutWorker so to avoid dispatching the event
* twice (or with incomplete data) we'll early
Expand Down

0 comments on commit 0e7bffd

Please sign in to comment.