diff options
Diffstat (limited to 'ui/app/pages/mobile-sync/index.js')
-rw-r--r-- | ui/app/pages/mobile-sync/index.js | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/ui/app/pages/mobile-sync/index.js b/ui/app/pages/mobile-sync/index.js index a8de4fce9..bd2385808 100644 --- a/ui/app/pages/mobile-sync/index.js +++ b/ui/app/pages/mobile-sync/index.js @@ -84,6 +84,9 @@ class MobileSyncPage extends Component { } initWebsockets () { + // Make sure there are no existing listeners + this.disconnectWebsockets() + this.pubnub = new PubNub({ subscribeKey: process.env.PUBNUB_SUB_KEY, publishKey: process.env.PUBNUB_PUB_KEY, @@ -91,7 +94,7 @@ class MobileSyncPage extends Component { ssl: true, }) - this.pubnubListener = this.pubnub.addListener({ + this.pubnubListener = { message: (data) => { const {channel, message} = data // handle message @@ -100,18 +103,20 @@ class MobileSyncPage extends Component { } if (message.event === 'start-sync') { - this.startSyncing() + this.startSyncing() } else if (message.event === 'connection-info') { - this.handle && clearTimeout(this.handle) - this.disconnectWebsockets() - this.initWithCipherKeyAndChannelName(message.cipher, message.channel) - this.initWebsockets() + this.handle && clearTimeout(this.handle) + this.disconnectWebsockets() + this.initWithCipherKeyAndChannelName(message.cipher, message.channel) + this.initWebsockets() } else if (message.event === 'end-sync') { - this.disconnectWebsockets() - this.setState({syncing: false, completed: true}) + this.disconnectWebsockets() + this.setState({syncing: false, completed: true}) } }, - }) + } + + this.pubnub.addListener(this.pubnubListener) this.pubnub.subscribe({ channels: [this.channelName], @@ -122,14 +127,14 @@ class MobileSyncPage extends Component { disconnectWebsockets () { if (this.pubnub && this.pubnubListener) { - this.pubnub.disconnect(this.pubnubListener) + this.pubnub.removeListener(this.pubnubListener) } } - // Calculating a PubNub Message Payload Size. + // Calculating a PubNub Message Payload Size. calculatePayloadSize (channel, message) { return encodeURIComponent( - channel + JSON.stringify(message) + channel + JSON.stringify(message) ).length + 100 } @@ -153,14 +158,14 @@ class MobileSyncPage extends Component { channel: this.channelName, sendByPost: false, // true to send via post storeInHistory: false, - }, - (status, response) => { - if (!status.error) { - resolve() - } else { - reject(response) - } - }) + }, + (status, response) => { + if (!status.error) { + resolve() + } else { + reject(response) + } + }) }) } @@ -199,16 +204,16 @@ class MobileSyncPage extends Component { sendMessage (data, pkg, count) { return new Promise((resolve, reject) => { this.pubnub.publish( - { - message: { - event: 'syncing-data', - data, - totalPkg: count, - currentPkg: pkg, - }, - channel: this.channelName, - sendByPost: false, // true to send via post - storeInHistory: false, + { + message: { + event: 'syncing-data', + data, + totalPkg: count, + currentPkg: pkg, + }, + channel: this.channelName, + sendByPost: false, // true to send via post + storeInHistory: false, }, (status, response) => { if (!status.error) { @@ -229,7 +234,7 @@ class MobileSyncPage extends Component { renderWarning (text) { return ( h('.page-container__warning-container', [ - h('.page-container__warning-message', [ + h('.page-container__warning-message', [ h('div', [text]), ]), ]) @@ -245,12 +250,12 @@ class MobileSyncPage extends Component { if (this.state.completed) { return h('div.reveal-seed__content', {}, - h('label.reveal-seed__label', { - style: { - width: '100%', - textAlign: 'center', - }, - }, t('syncWithMobileComplete')), + h('label.reveal-seed__label', { + style: { + width: '100%', + textAlign: 'center', + }, + }, t('syncWithMobileComplete')), ) } @@ -303,8 +308,8 @@ class MobileSyncPage extends Component { h('div', [ h('label.reveal-seed__label', { style: { - width: '100%', - textAlign: 'center', + width: '100%', + textAlign: 'center', }, }, t('syncWithMobileScanThisCode')), h('.div.qr-wrapper', { @@ -370,7 +375,7 @@ class MobileSyncPage extends Component { this.state.screen === PASSWORD_PROMPT_SCREEN ? h('.page-container__subtitle', this.context.t('syncWithMobileDescNewUsers')) : null, ]), h('.page-container__content', [ - this.renderContent(), + this.renderContent(), ]), this.renderFooter(), ]) |