Skip to content

Commit

Permalink
Update mobile sync (#6967)
Browse files Browse the repository at this point in the history
* update mobile sync

* update lockfile
  • Loading branch information
Bruno Barbieri authored Aug 6, 2019
1 parent 3136dd3 commit 835d4fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"promise-filter": "^1.1.0",
"promise-to-callback": "^1.0.0",
"prop-types": "^15.6.1",
"pubnub": "^4.21.5",
"pubnub": "4.24.4",
"pump": "^3.0.0",
"qrcode-generator": "1.4.1",
"ramda": "^0.24.1",
Expand Down
11 changes: 8 additions & 3 deletions ui/app/pages/mobile-sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ 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,
cipherKey: this.cipherKey,
ssl: true,
})

this.pubnubListener = this.pubnub.addListener({
this.pubnubListener = {
message: (data) => {
const {channel, message} = data
// handle message
Expand All @@ -111,7 +114,9 @@ class MobileSyncPage extends Component {
this.setState({syncing: false, completed: true})
}
},
})
}

this.pubnub.addListener(this.pubnubListener)

this.pubnub.subscribe({
channels: [this.channelName],
Expand All @@ -122,7 +127,7 @@ class MobileSyncPage extends Component {

disconnectWebsockets () {
if (this.pubnub && this.pubnubListener) {
this.pubnub.disconnect(this.pubnubListener)
this.pubnub.removeListener(this.pubnubListener)
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17150,10 +17150,10 @@ public-encrypt@^4.0.0:
parse-asn1 "^5.0.0"
randombytes "^2.0.1"

pubnub@^4.21.5:
version "4.21.7"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-4.21.7.tgz#4daf999ead1aa9cf8e9af3d2fb2720c35085af6a"
integrity sha512-TZ96GuY+gZIu9rJaqcO2cZ6tl4JPLruoUcN01sljm1CcDgzIZbOfcDSZp4NcZas4ECSqAAwo/izMMiImRRS4Yg==
pubnub@4.24.4:
version "4.24.4"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-4.24.4.tgz#6874b1836539765a1c1ec8c264f6b233ed28192a"
integrity sha512-otRny/9au/Xf0uAfPUrVwUPdFIE7nZv6+7TLcG8+wiZESgi7EgiGZ9VXAoe6istBj6hfZe0vj3+XCbkZHLHklw==
dependencies:
agentkeepalive "^3.5.2"
lil-uuid "^0.1.1"
Expand Down

0 comments on commit 835d4fb

Please sign in to comment.