mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00

* Fix Spelling - Rename `Listenler` to `Listener` * Add Options to Connection - Add options which can be passed to connection string for `SocketIO` * Build New Version * Fix spelling in Package.json - Change `implemantation` to `implementation` - Change `vuejs` to `Vue.js` - Change `vuex` to `VueX` * Updates to index.js - Add `options` to JSDocs for constructor - Fix spelling for JSDoc on `install` and `connect` methods
67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
import Mixin from './mixin';
|
|
import Logger from './logger';
|
|
import Listener from './listener';
|
|
import Emitter from './emitter';
|
|
import SocketIO from 'socket.io-client';
|
|
|
|
export default class VueSocketIO {
|
|
|
|
/**
|
|
* lets take all resource
|
|
* @param io
|
|
* @param vuex
|
|
* @param debug
|
|
* @param options
|
|
*/
|
|
constructor({connection, vuex, debug, options}){
|
|
|
|
Logger.debug = debug;
|
|
this.io = this.connect(connection, options);
|
|
this.emitter = new Emitter(vuex);
|
|
this.listener = new Listener(this.io, this.emitter);
|
|
|
|
}
|
|
|
|
/**
|
|
* Vue.js entry point
|
|
* @param Vue
|
|
*/
|
|
install(Vue){
|
|
|
|
Vue.prototype.$socket = this.io;
|
|
Vue.prototype.$vueSocketIo = this;
|
|
Vue.mixin(Mixin);
|
|
|
|
Logger.info('Vue-Socket.io plugin enabled');
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* registering SocketIO instance
|
|
* @param connection
|
|
* @param options
|
|
*/
|
|
connect(connection, options){
|
|
|
|
if(connection && typeof connection === 'object'){
|
|
|
|
Logger.info('Received socket.io-client instance');
|
|
|
|
return connection;
|
|
|
|
} else if(typeof connection === 'string'){
|
|
|
|
Logger.info('Received connection string');
|
|
|
|
return this.io = SocketIO(connection, options);
|
|
|
|
} else {
|
|
|
|
throw new Error('Unsupported connection type');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|