Skip to content

Commit

Permalink
Merge pull request #91 from prlanzarin/u26/exokind
Browse files Browse the repository at this point in the history
fix: guarantee cleanup of stale data in remote collections on re-subscriptions
  • Loading branch information
prlanzarin authored Dec 23, 2022
2 parents ce3dd18 + 2476460 commit 8a5f5cd
Show file tree
Hide file tree
Showing 31 changed files with 353 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/audio/audio-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const AudioControls = (props) => {
break;
}
case 'ListenOnly':
if (isListenOnly) {
if (AudioManager.isListenOnly) {
// TODO localization, programmatically dismissable Dialog that is reusable
Alert.alert(
'Microfone bloqueado',
Expand Down
12 changes: 6 additions & 6 deletions src/components/socket-connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ const setupModules = (ws) => {

// Mirrors for Meteor collections that area fully implemented
const modules = {
users: new UsersModule(messageSender),
meetings: new MeetingModule(messageSender),
voiceUsers: new VoiceUsersModule(messageSender),
polls: new PollsModule(messageSender),
voiceCallStates: new VoiceCallStatesModule(messageSender),
presentations: new PresentationsModule(messageSender),
slides: new SlidesModule(messageSender),
screenshare: new ScreenshareModule(messageSender),
polls: new PollsModule(messageSender),
'current-poll': new CurrentPollModule(messageSender),
'current-user': new CurrentUserModule(messageSender),
'group-chat': new GroupChatModule(messageSender),
'group-chat-msg': new GroupChatMsgModule(messageSender),
'video-streams': new VideoStreamsModule(messageSender),
voiceCallStates: new VoiceCallStatesModule(messageSender),
screenshare: new ScreenshareModule(messageSender),
meetings: new MeetingModule(messageSender),
'current-user': new CurrentUserModule(messageSender),
users: new UsersModule(messageSender),
};

/*
Expand Down
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/current-poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
editCurrentPoll,
removeCurrentPoll,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/current-poll';

const CURRENT_POLL_TOPIC = 'current-poll';
Expand Down Expand Up @@ -56,4 +57,9 @@ export class CurrentPollModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
editCurrentUser,
removeCurrentUser,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/current-user';

const CURRENT_USER_TOPIC = 'current-user';
Expand Down Expand Up @@ -49,4 +50,9 @@ export class CurrentUserModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeExternalVideoMeeting,
editExternalVideoMeeting,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/external-video-meetings';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class ExternalVideoMeetingsModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/group-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
editGroupChat,
removeGroupChat,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/group-chat';

const GROUP_CHAT_TOPIC = 'group-chat';
Expand Down Expand Up @@ -49,4 +50,9 @@ export class GroupChatModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/meeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeMeeting,
editMeeting,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/meeting';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class MeetingModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
37 changes: 31 additions & 6 deletions src/components/socket-connection/modules/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import MethodTransactionManager from '../method-transaction-manager';
import MethodTransaction from '../method-transaction';
import SubscribeTransaction from '../subscribe-transaction';

const STALE_DATA_DEBOUNCE = 1000;

export default class Module {
constructor(topics, messageSender) {
this.messageSender = messageSender;
Expand All @@ -12,7 +14,7 @@ export default class Module {
this.topics = topics;
}

// Map<String, String>
// Map<topic: String, subscriptionId: String>
this.subscriptions = new Map();

this._pendingTransactions = new MethodTransactionManager();
Expand All @@ -24,13 +26,14 @@ export default class Module {
const transaction = new SubscribeTransaction(topic, args);
this._pendingTransactions.addTransaction(transaction);
this.messageSender.sendMessage(transaction.payload);
this.subscriptions.set(topic, transaction.transactionId);
return transaction.promise.then(() => {
this.subscriptions.set(topic, transaction.transactionId);
this._ignoreDeletions = false;
this._subscriptionStateChanged(true);
this.subscriptionStateChanged(true);
}).catch(() => {
this._ignoreDeletions = false;
this._subscriptionStateChanged(false);
this.subscriptions.delete(topic);
this.subscriptionStateChanged(false);
});
}

Expand All @@ -42,7 +45,7 @@ export default class Module {
this._ignoreDeletions = true;
const topic = msgObj.collection;
this.subscriptions.delete(topic);
this._subscriptionStateChanged(false);
this.subscriptionStateChanged(false);
// Force a re-subscription of affected modules
this.onConnected();
}
Expand All @@ -57,7 +60,7 @@ export default class Module {
msg: 'unsub',
id,
});
this._subscriptionStateChanged(false);
this.subscriptionStateChanged(false);

return this.subscriptions.delete(topic);
}
Expand Down Expand Up @@ -141,6 +144,10 @@ export default class Module {
}

add(msgObj) {
const topic = msgObj?.collection;
// Annotate document with subscriptionId so that we can flush stale data
msgObj.fields = { ...msgObj.fields, subscriptionId: this.subscriptions.get(topic) };

return this._add(msgObj);
}

Expand Down Expand Up @@ -168,4 +175,22 @@ export default class Module {
// eslint-disable-next-line class-methods-use-this, no-unused-vars
_subscriptionStateChanged(newState) {
}

subscriptionStateChanged(newState) {
if (newState === true) this._checkForStaleData();
this._subscriptionStateChanged(newState);
}

// Must be implemented by inheritors
// eslint-disable-next-line class-methods-use-this, no-unused-vars
_cleanupStaleData() {
}

_checkForStaleData() {
setTimeout(() => {
this.subscriptions.forEach((subscriptionId) => {
this._cleanupStaleData(subscriptionId);
});
}, STALE_DATA_DEBOUNCE);
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/pads.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
removePad,
editPad,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/pads';

const PADS_TOPIC = 'pads';
Expand Down Expand Up @@ -49,4 +50,9 @@ export class PadsModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/polls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
removePoll,
editPoll,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/polls';
import { hideNotification, setProfile } from '../../../store/redux/slices/wide-app/notification-bar';

Expand Down Expand Up @@ -54,4 +55,9 @@ export class PollsModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/presentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
removePresentation,
editPresentation,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/presentations';

const PRESENTATION_TOPIC = 'presentations';
Expand Down Expand Up @@ -49,4 +50,9 @@ export class PresentationsModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/screenshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeScreenshare,
editScreenshare,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/screenshare';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class ScreenshareModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
12 changes: 12 additions & 0 deletions src/components/socket-connection/modules/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
addSlide,
removeSlide,
editSlide,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/slides';

const SLIDES_TOPIC = 'slides';
Expand Down Expand Up @@ -43,4 +45,14 @@ export class SlidesModule extends Module {
})
);
}

// eslint-disable-next-line class-methods-use-this
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeUser,
editUser,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/users';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class UsersModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/video-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeVideoStream,
editVideoStream,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/video-streams';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class VideoStreamsModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/voice-call-states.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeVoiceCallState,
editVoiceCallState,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/voice-call-states';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class VoiceCallStatesModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
6 changes: 6 additions & 0 deletions src/components/socket-connection/modules/voice-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeVoiceUser,
editVoiceUser,
readyStateChanged,
cleanupStaleData,
} from '../../../store/redux/slices/voice-users';
import { store } from '../../../store/redux/store';

Expand Down Expand Up @@ -49,4 +50,9 @@ export class VoiceUsersModule extends Module {
_subscriptionStateChanged(newState) {
return store.dispatch(readyStateChanged(newState));
}

// eslint-disable-next-line class-methods-use-this
_cleanupStaleData(subscriptionId) {
return store.dispatch(cleanupStaleData(subscriptionId));
}
}
Loading

0 comments on commit 8a5f5cd

Please sign in to comment.