Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/realtimeSessions/components/RealtimeSessionIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
this.activeSession = this.sessionService.getActiveTopicOrSession();
this.stopListening = this.sessionService.listen(this.onActiveSessionChange);

this.pollForSessions();
this.pollForSessions(true);
},
beforeUnmount() {
this.stopListening?.();
Expand All @@ -84,10 +84,10 @@ export default {
}
},
methods: {
pollForSessions() {
pollForSessions(resolveCachedDatasets = false ) {
if (!this.activeSession) {
this.sessionService
.getTopicsWithSessions()
.getTopicsWithSessions( resolveCachedDatasets )
.then(topics => {
this.hasTopics = topics.length > 0;
});
Expand Down
48 changes: 44 additions & 4 deletions src/services/session/SessionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,53 @@ class SessionService {
*
* @returns {Promise.<Topic[]>}
*/
async getTopicsWithSessions() {
async getTopicsWithSessions(resolveCachedDatasets = false) {
if (this.realtimeSessionConfig.disable) {
return Promise.resolve([]);
}

const datasets = Object.values(this.getDatasets());
const validUrls = datasets.map(dataset => dataset.options.sessionLADUrl).filter(url => url);
let datasets = [];
// Need to wait for MIOs to load for the cached datasets to return.
const cachedDatasets = new Promise((resolve) => {
// Check once a second
const pollInterval = 1000;
let currentLength = 0;
let maxIterations = 15;
let currentIteration = 0;
const checkDatasets = () => {
const result = Object.values(this.getDatasets());

// no datasets
if (result.length === 0) {
// maxed out iterations, give up and resolve with empty array
if (currentIteration > maxIterations) {
resolve([]);
return;
}
currentIteration++;
setTimeout(checkDatasets, pollInterval);
} else { // we have datasets
// first time we have datasets
if (currentLength === 0) {
currentLength = result.length;
setTimeout(checkDatasets, pollInterval);
} else { // we've already seen some datasets, check for stability
if (result.length === currentLength) { // we have stability, resolve
resolve(result);
} else { // datasets still loading, wait for stability
currentLength = result.length;
setTimeout(checkDatasets, pollInterval);
}
}
}
};
checkDatasets(); // Start polling
});
if (resolveCachedDatasets) {
datasets = await cachedDatasets;
} else {
datasets = Object.values(this.getDatasets());
}
const validUrls = datasets.map((dataset) => dataset.options.sessionLADUrl).filter(Boolean);
const sessionLADUrls = validUrls.reduce((uniqueUrls, url) => {
return uniqueUrls.includes(url) ? uniqueUrls : [...uniqueUrls, url];
}, []);
Expand Down