pull/15/head
Metin 8 years ago
parent e9536b6108
commit aac02ac050

@ -14,7 +14,11 @@
throw new Error("[Vue-Socket.io] cannot locate connection") throw new Error("[Vue-Socket.io] cannot locate connection")
} }
var socket = Socketio(connection); if (typeof connection === 'string') {
var socket = Socketio(connection);
} else if (typeof connection === 'object') {
var socket = connection;
}
/* /*
* Wildcard support * Wildcard support
@ -41,18 +45,18 @@
Vue.mixin({ Vue.mixin({
created: function () { created: function () {
var me = this; var self = this;
if (this.$options.hasOwnProperty("sockets")) { if (this.$options.hasOwnProperty("sockets")) {
socket.on("*", function (emit, data) { socket.on("*", function (emit, data) {
if (me.$options.sockets.hasOwnProperty(emit)) { if (self.$options.sockets.hasOwnProperty(emit)) {
me.$options.sockets[emit](data); self.$options.sockets[emit].call(self, data);
} }
}); });
methods.forEach(function (m) { methods.forEach(function (m) {
socket.on(m, function (data) { socket.on(m, function (data) {
if (me.$options.sockets.hasOwnProperty(m)) { if (self.$options.sockets.hasOwnProperty(m)) {
me.$options.sockets[m](data); self.$options.sockets[m].call(self, data);
} }
}); });
}); });

Loading…
Cancel
Save