From e7ec50c08fbfcced4697d47cf2acab422042bc00 Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 12 Dec 2019 12:03:14 +0200 Subject: [PATCH 1/2] Correct version of app --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index a270b36..d419761 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "orbit-web", - "version": "1.0.0-alpha-14", + "version": "1.0.0-alpha-15", "lockfileVersion": 1, "requires": true, "dependencies": { From 894194d1a0388c0d45e69b524a5b4b3690ef35bd Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 12 Dec 2019 12:03:40 +0200 Subject: [PATCH 2/2] Prevent joining a channel multiple times --- src/stores/NetworkStore.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/stores/NetworkStore.js b/src/stores/NetworkStore.js index 818d2aa..0999906 100644 --- a/src/stores/NetworkStore.js +++ b/src/stores/NetworkStore.js @@ -60,6 +60,10 @@ export default class NetworkStore { @observable channels = {} + // Keeps track of the channel join promises + // This helps us to prevent joining same channel multiple times in quick succession + _joiningChannelPromises = {} + @observable swarmPeers = [] @@ -174,10 +178,14 @@ export default class NetworkStore { async joinChannel (channelName) { if (typeof channelName !== 'string') return if (!this.isOnline) throw new Error('Network is not online') - if (!this.channelNames.includes(channelName)) { - await this.workerProxy.joinChannel(channelName) + if ( + !(channelName in this._joiningChannelPromises) && + !this.channelNames.includes(channelName)) { + this._joiningChannelPromises[channelName] = this.workerProxy.joinChannel(channelName) + .then(() => this._onJoinedChannel(channelName)) } - return this._onJoinedChannel(channelName) + + return this._joiningChannelPromises[channelName] } async leaveChannel (channelName) {