Fixed #287: duplicated websocket connexion on timeline

This commit is contained in:
Eliot Berriot 2018-06-11 22:47:00 +02:00
parent 4c81de9226
commit ef224e9fe9
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
2 changed files with 13 additions and 0 deletions

View File

@ -0,0 +1 @@
Fixed duplicated websocket connexion on timeline (#287)

View File

@ -34,6 +34,7 @@ export default {
data () {
return {
isLoading: false,
bridge: null,
components: {
'Like': Like,
'Listen': Listen
@ -44,6 +45,9 @@ export default {
this.openWebsocket()
this.fetchEvents()
},
destroyed () {
this.disconnect()
},
computed: {
...mapState({
events: state => state.instance.events
@ -58,14 +62,22 @@ export default {
self.$store.commit('instance/events', response.data.results)
})
},
disconnect () {
if (!this.bridge) {
return
}
this.bridge.socket.close(1000, 'goodbye', {keepClosed: true})
},
openWebsocket () {
if (!this.$store.state.auth.authenticated) {
return
}
this.disconnect()
let self = this
let token = this.$store.state.auth.token
// let token = 'test'
const bridge = new WebSocketBridge()
this.bridge = bridge
bridge.connect(
`/api/v1/instance/activity?token=${token}`,
null,