mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
add: handle more than one namespace
This commit is contained in:
parent
ee1e7ed1ee
commit
a715ee1ae7
1 changed files with 19 additions and 2 deletions
19
src/index.js
19
src/index.js
|
@ -13,10 +13,11 @@ export default class VueSocketIO {
|
|||
* @param debug
|
||||
* @param options
|
||||
*/
|
||||
constructor({connection, vuex, debug, options}){
|
||||
constructor({connection, vuex, debug, options, useConnectionNamespace}){
|
||||
|
||||
Logger.debug = debug;
|
||||
this.io = this.connect(connection, options);
|
||||
this.useConnectionNamespace = useConnectionNamespace;
|
||||
this.emitter = new Emitter(vuex);
|
||||
this.listener = new Listener(this.io, this.emitter);
|
||||
|
||||
|
@ -28,7 +29,23 @@ export default class VueSocketIO {
|
|||
*/
|
||||
install(Vue){
|
||||
|
||||
const namespace = this.io.nsp.replace("/", "");
|
||||
|
||||
if (this.useConnectionNamespace) {
|
||||
if (typeof Vue.prototype.$socket === "object") {
|
||||
Vue.prototype.$socket = {
|
||||
...Vue.prototype.$socket,
|
||||
[namespace]: this.io
|
||||
};
|
||||
} else {
|
||||
Vue.prototype.$socket = {
|
||||
[namespace]: this.io
|
||||
};
|
||||
}
|
||||
} else {
|
||||
Vue.prototype.$socket = this.io;
|
||||
}
|
||||
|
||||
Vue.prototype.$vueSocketIo = this;
|
||||
Vue.mixin(Mixin);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue