Compare commits

...

28 commits

Author SHA1 Message Date
Aybüke ÇALIŞKAN
61614c865e
Update README.md (#327) 2022-01-09 23:53:06 +03:00
Metin Seylan
4f00019283
Update README.md 2021-06-08 19:55:18 +03:00
lju
3337d43298
Add basic Vue 3 compatibility (#289) 2021-02-19 21:26:27 +03:00
sambit sahoo
2f63eebb70
add type declarations for optional options (#285)
Add type declarations for optional options as it throws error.
2020-10-10 21:24:46 +03:00
Metin Seylan
c555cc72ef
Update README.md 2020-09-04 12:33:00 +03:00
IFA
0359c5dd59
Update README.md for making things clear (#277) 2020-09-04 11:58:53 +03:00
Даниил Пронин
d7ddfb23ef
Update README.md (#271) 2020-08-06 11:15:40 +03:00
MetinSeylan
35d8f66d44 revert changes & delete issues folder 2020-07-31 22:35:09 +03:00
Metin Seylan
640dfc044c reverse from 3.0.8 2020-05-08 12:29:11 +03:00
Metin Seylan
f770882eb5 Revert "version upgrade"
This reverts commit 3d04f310a3.
2020-05-08 12:28:33 +03:00
Metin Seylan
3d04f310a3 version upgrade 2020-04-30 22:32:03 +03:00
dailing
45860773e4
Update README.md (#241)
It seems that `import SocketIO from "socket.io-client"` is missing from the examples.
2020-03-16 17:19:25 +03:00
Mehmet Yılmaz
4fba4071f7 readme refactor (#232) 2019-12-10 16:15:22 +03:00
Nikita Umnov
caf4f56b10 add types definition (#218)
* add types definition
2019-08-15 13:20:38 +03:00
Leonardo E. Dominguez
8988085bef Handle more than one namespace (#207)
* add: handle more than one namespace

* Revert "[FIX] Adjusting SocketIO client lib import (#202)"

This reverts commit ee1e7ed1ee.

* add: handle more than one namespace

* change: move useConnectionNamespace inside options object

* update: readme

* add: support namespace listeners in components

* update build files

* add: namespace name property to options object

* update build files
2019-05-13 00:59:44 +03:00
Vinícius Feitosa da Silva
ee1e7ed1ee [FIX] Adjusting SocketIO client lib import (#202) 2019-03-23 11:18:36 +03:00
Metin Seylan
f77564b41e version upgrade 2019-03-07 04:40:01 +03:00
Michael Johansen
ad3d21ecb5 fixed typo on VueSocketIOListener (#200) 2019-03-07 04:37:54 +03:00
Arie Miller
5cbf41a399 Update listener.js (#199)
VueSocketIOListenler -> VueSocketIOListener
2019-03-07 04:37:20 +03:00
Metin Seylan
68d4e5570b upgrade version 2019-03-06 20:24:15 +03:00
Evan bechtol
381cb5fdd0 README.MD Example Usage Updates (#198)
* 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

* Update README.MD

- Add example of connecting using socket.io-client instance

* Update README.MD

- Add options example using connection string

* Update README.MD

- Add options example using connection string

* Remove unnecessary white space
2019-03-06 20:20:24 +03:00
Evan bechtol
f1e03525c0 Add options parameter to Constructor (#195)
* 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
2019-03-06 19:40:24 +03:00
Slava
207a0a13bd don't dispatch ping to store (#188) 2019-02-13 12:37:23 +03:00
Slava
6d5c7983d1 move string concatenation out of loop (#189) 2019-02-13 12:37:02 +03:00
Metin Seylan
60d38b78bc build 3.0.5 2019-01-25 09:23:32 +03:00
Nikita Umnov
4322054bfd FIX: receiving staticEvents messages (#181)
* FIX: receiving staticEvents messages
* return space :)
2019-01-25 09:20:17 +03:00
Metin Seylan
fb8e1f96c1
Update README.md 2019-01-03 23:41:01 +03:00
Metin Seylan
6c837e002f Update issue templates 2018-11-27 22:05:38 +03:00
7 changed files with 176 additions and 26 deletions

View file

@ -12,13 +12,17 @@
<a href="https://github.com/MetinSeylan/Vue-Socket.io/"><img src="https://img.shields.io/npm/l/vue-socket.io.svg"/></a>
<a href="https://github.com/MetinSeylan/Vue-Socket.io/"><img src="https://img.shields.io/github/stars/MetinSeylan/Vue-Socket.io.svg"/></a>
</p>
<p>Vue-Socket.io is a socket.io integration for Vuejs, easy to use, supporting Vuex and component level socket consumer managements<p>
<p align="center">
<a href="https://www.patreon.com/MetinSeylan">
<img alt="Patreon" src="https://c5.patreon.com/external/logo/become_a_patron_button.png" height="50" />
</a>
</p>
<p>Vue-Socket.io is a socket.io integration for Vuejs, easy to use, supporting Vuex and component level socket consumer managements.<p>
###### Demo
- <a href="http://metinseylan.com/vuesocketio/" target="_blank">Chat Application</a>
- <a href="http://metinseylan.com" target="_blank">Car Tracking Application</a>
<p>You can also check my other npm library <a href="https://github.com/MetinSeylan/Nestjs-OpenTelemetry">Nestjs OpenTelemetry</a></p>
<p>
are you looking for old documentation? <a href="https://github.com/MetinSeylan/Vue-Socket.io/blob/master/docs/OLD_README.md">it's here</a>
</p>
@ -27,7 +31,7 @@ are you looking for old documentation? <a href="https://github.com/MetinSeylan/V
``` bash
npm install vue-socket.io --save
```
##### Using Connection String
``` javascript
import Vue from 'vue'
import store from './store'
@ -41,7 +45,8 @@ Vue.use(new VueSocketIO({
store,
actionPrefix: 'SOCKET_',
mutationPrefix: 'SOCKET_'
}
},
options: { path: "/my-app/" } //Optional options
}))
new Vue({
@ -51,6 +56,34 @@ new Vue({
}).$mount('#app')
```
##### Using socket.io-client Instance
``` javascript
import Vue from 'vue'
import store from './store'
import App from './App.vue'
import VueSocketIO from 'vue-socket.io'
import SocketIO from 'socket.io-client'
const options = { path: '/my-app/' }; //Options object to pass into SocketIO
Vue.use(new VueSocketIO({
debug: true,
connection: SocketIO('http://metinseylan.com:1992', options), //options object is Optional
vuex: {
store,
actionPrefix: "SOCKET_",
mutationPrefix: "SOCKET_"
}
})
);
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
```
**Parameters**|**Type's**|**Default**|**Required**|**Description**
-----|-----|-----|-----|-----
debug|Boolean|`false`|Optional|Enable logging for debug
@ -61,7 +94,7 @@ vuex.mutationPrefix|String |`null`|Optional|Prefix for emitting server side vuex
#### 🌈 Component Level Usage
<p>If you want to listen socket events from component side, you need to add `sockets` object in Vue component, and every function will start to listen events, depends on object key</p>
<p>If you want to listen socket events from component side, you need to add `sockets` object in Vue component. After that every function will start to listen events, depends on object key</p>
``` javascript
new Vue({
@ -94,6 +127,35 @@ this.sockets.subscribe('EVENT_NAME', (data) => {
this.sockets.unsubscribe('EVENT_NAME');
```
##### Defining handlers for events with special characters
<p>If you want to handle 'kebab-case', or "event with space inside it" events, then you have to define it via the following way</p>
``` javascript
export default {
name: 'Test',
sockets: {
connect: function () {
console.log('socket to notification channel connected')
},
},
data () {
return {
something: [
// ... something here for the data if you need.
]
}
},
mounted () {
this.$socket.subscribe("kebab-case", function(data) {
console.log("This event was fired by eg. sio.emit('kebab-case')", data)
})
}
}
```
#### 🏆 Vuex Integration
<p>When you set store parameter in installation, `Vue-Socket.io` will start sending events to Vuex store. If you set both prefix for vuex, you can use `actions` and `mutations` at the same time. But, best way to use is just `actions`</p>
@ -118,6 +180,11 @@ export default new Vuex.Store({
})
```
## Stargazers over time
[![Stargazers over time](https://starcharts.herokuapp.com/MetinSeylan/Vue-Socket.io.svg)](https://starcharts.herokuapp.com/MetinSeylan/Vue-Socket.io)
<p align="center">
<a href="https://github.com/MetinSeylan/Vue-Socket.io" target="_blank">
<img src="https://media.giphy.com/media/11jlnltQgUi2mQ/giphy.gif">

10
dist/vue-socketio.js vendored

File diff suppressed because one or more lines are too long

63
index.d.ts vendored Normal file
View file

@ -0,0 +1,63 @@
import SocketIOClient from "socket.io-client";
import {
DefaultComputed,
DefaultData,
DefaultMethods,
DefaultProps,
PropsDefinition,
} from "vue/types/options";
import { Vue } from "vue/types/vue";
import { PluginFunction, PluginObject } from "vue";
import { Store } from "vuex";
interface socketHandler<T> {
(this: T, ...args: any[]): void
}
interface Sockets<V> {
[key: string]: socketHandler<V>
}
declare module 'vue/types/vue' {
interface Vue {
$socket: SocketIOClient.Socket,
sockets: {
subscribe(eventName: string, handler: socketHandler<Vue>): void,
unsubscribe(eventName: string): void,
}
}
}
declare module 'vue/types/options' {
interface ComponentOptions<
V extends Vue,
Data=DefaultData<V>,
Methods=DefaultMethods<V>,
Computed=DefaultComputed,
PropsDef=PropsDefinition<DefaultProps>,
Props=DefaultProps> {
sockets?: Sockets<V>
}
}
export interface VueSocketOptions {
debug?: boolean;
connection: string | SocketIOClient.Socket,
vuex?: {
store?: Store<any>,
actionPrefix?: string,
mutationPrefix?: string,
options?: {
useConnectionNamespace?: boolean
}
},
// type declarations for optional options
options?:{
path?: string;
}
}
export default class VueSocketIO<T> implements PluginObject<T> {
constructor (options: VueSocketOptions);
install: PluginFunction<T>
}

View file

@ -1,8 +1,8 @@
{
"name": "vue-socket.io",
"author": "Metin Seylan <metinsyln@gmail.com>",
"version": "3.0.4",
"description": "socket.io implemantation for vuejs and vuex",
"version": "3.0.10",
"description": "socket.io implementation for Vue.js and Vuex",
"main": "dist/vue-socketio.js",
"scripts": {
"build": "webpack --mode=production --progress --hide-modules"

View file

@ -77,7 +77,9 @@ export default class EventEmitter{
}
if(event !== 'ping' && event !== 'pong') {
this.dispatchStore(event, args);
}
}
@ -91,11 +93,13 @@ export default class EventEmitter{
if(this.store && this.store._actions){
let prefixed_event = this.actionPrefix + event;
for (let key in this.store._actions) {
let action = key.split('/').pop();
if(action === this.actionPrefix+event) {
if(action === prefixed_event) {
Logger.info(`Dispatching Action: ${key}, Data:`, args);
@ -107,11 +111,13 @@ export default class EventEmitter{
if(this.mutationPrefix) {
let prefixed_event = this.mutationPrefix + event;
for (let key in this.store._mutations) {
let mutation = key.split('/').pop();
if(mutation === this.mutationPrefix+event) {
if(mutation === prefixed_event) {
Logger.info(`Commiting Mutation: ${key}, Data:`, args);

View file

@ -1,6 +1,6 @@
import Mixin from './mixin';
import Logger from './logger';
import Listenler from './listenler';
import Listener from './listener';
import Emitter from './emitter';
import SocketIO from 'socket.io-client';
@ -11,24 +11,33 @@ export default class VueSocketIO {
* @param io
* @param vuex
* @param debug
* @param options
*/
constructor({connection, vuex, debug}){
constructor({connection, vuex, debug, options}){
Logger.debug = debug;
this.io = this.connect(connection);
this.io = this.connect(connection, options);
this.emitter = new Emitter(vuex);
this.listener = new Listenler(this.io, this.emitter);
this.listener = new Listener(this.io, this.emitter);
}
/**
* Vuejs entrypoint
* Vue.js entry point
* @param Vue
*/
install(Vue){
const version = Number(Vue.version.split('.')[0])
if (version >= 3) {
Vue.config.globalProperties.$socket = this.io;
Vue.config.globalProperties.$vueSocketIo = this;
} else {
Vue.prototype.$socket = this.io;
Vue.prototype.$vueSocketIo = this;
}
Vue.mixin(Mixin);
Logger.info('Vue-Socket.io plugin enabled');
@ -37,10 +46,11 @@ export default class VueSocketIO {
/**
* registering socketio instance
* registering SocketIO instance
* @param connection
* @param options
*/
connect(connection){
connect(connection, options){
if(connection && typeof connection === 'object'){
@ -52,7 +62,7 @@ export default class VueSocketIO {
Logger.info('Received connection string');
return this.io = SocketIO(connection);
return this.io = SocketIO(connection, options);
} else {

View file

@ -1,5 +1,5 @@
export default class VueSocketIOListenler {
export default class VueSocketIOListener {
/**
* socket.io-client reserved event keywords
@ -38,7 +38,7 @@ export default class VueSocketIOListenler {
this.onEvent(event, args)
};
VueSocketIOListenler.staticEvents.forEach(event => this.io.on(event, () => this.onEvent(event)))
VueSocketIOListener.staticEvents.forEach(event => this.io.on(event, args => this.onEvent(event, args)))
}
/**