Skip to content

Commit b64c087

Browse files
committed
Fixed unsubscribe and re-subscribe bug
1 parent 4771db4 commit b64c087

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

vue-echo.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020
}
2121

2222
Vue.mixin({
23-
created(){
23+
mounted() {
2424
let channel = this.$options['channel'];
2525

2626
if(channel)
@@ -46,16 +46,27 @@ export default {
4646
// Bind the VM as second parameter
4747
this.channel.listen(key, (payload) => {
4848
events[key](payload, this);
49-
});
49+
});
5050
}, this);
5151
}
5252
}
5353
},
5454
beforeDestroy(){
55-
if(this.$options['channel']){
56-
this.channel.unsubscribe();
55+
let channel = this.$options['channel'];
56+
57+
if(channel){
58+
if(channel.startsWith('private:'))
59+
{
60+
channel = channel.replace('private:', '');
61+
}
62+
else if(channel.startsWith('presence:'))
63+
{
64+
channel = channel.replace('presence:', '');
65+
}
66+
67+
this.$echo.leave(channel);
5768
}
5869
}
5970
})
6071
}
61-
}
72+
}

0 commit comments

Comments
 (0)