Skip to content

Commit eca2be4

Browse files
author
Kerstens Maxim
authored
Add VM as second parameter to registered events
tweaked check when checking for Echo Instance
1 parent 41f5d0a commit eca2be4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

vue-echo.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
throw new Error("[Vue-Echo] cannot initiate options");
1111
}
1212

13-
if(typeof options == 'function')
13+
if(typeof options.socketId == 'function')
1414
{
1515
Vue.prototype.$echo = options;
1616
}
@@ -28,6 +28,7 @@ export default {
2828
if(channel.startsWith('private:'))
2929
{
3030
this.channel = this.$echo.private(channel.replace('private:', ''))
31+
console.log(this.channel);
3132
}
3233
else if(channel.startsWith('presence:'))
3334
{
@@ -43,7 +44,10 @@ export default {
4344
if(events)
4445
{
4546
Object.keys(events).forEach(function(key){
46-
this.channel.listen(key, events[key]);
47+
// Bind the VM as second parameter
48+
this.channel.listen(key, (payload) => {
49+
events[key](payload, this);
50+
});
4751
}, this);
4852
}
4953
}
@@ -55,4 +59,4 @@ export default {
5559
}
5660
})
5761
}
58-
}
62+
}

0 commit comments

Comments
 (0)