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
21
src/index.js
21
src/index.js
|
@ -13,10 +13,11 @@ export default class VueSocketIO {
|
||||||
* @param debug
|
* @param debug
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
constructor({connection, vuex, debug, options}){
|
constructor({connection, vuex, debug, options, useConnectionNamespace}){
|
||||||
|
|
||||||
Logger.debug = debug;
|
Logger.debug = debug;
|
||||||
this.io = this.connect(connection, options);
|
this.io = this.connect(connection, options);
|
||||||
|
this.useConnectionNamespace = useConnectionNamespace;
|
||||||
this.emitter = new Emitter(vuex);
|
this.emitter = new Emitter(vuex);
|
||||||
this.listener = new Listener(this.io, this.emitter);
|
this.listener = new Listener(this.io, this.emitter);
|
||||||
|
|
||||||
|
@ -28,7 +29,23 @@ export default class VueSocketIO {
|
||||||
*/
|
*/
|
||||||
install(Vue){
|
install(Vue){
|
||||||
|
|
||||||
Vue.prototype.$socket = this.io;
|
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.prototype.$vueSocketIo = this;
|
||||||
Vue.mixin(Mixin);
|
Vue.mixin(Mixin);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue