Compare commits

...

16 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
7 changed files with 118 additions and 53 deletions

View file

@ -1,25 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
---
**Describe the bug**
A clear and concise description of what the bug is.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View file

@ -1,17 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

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>
@ -58,6 +62,7 @@ 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
@ -89,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({
@ -122,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>

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,7 +1,7 @@
{
"name": "vue-socket.io",
"author": "Metin Seylan <metinsyln@gmail.com>",
"version": "3.0.7",
"version": "3.0.10",
"description": "socket.io implementation for Vue.js and Vuex",
"main": "dist/vue-socketio.js",
"scripts": {

View file

@ -28,8 +28,16 @@ export default class VueSocketIO {
*/
install(Vue){
Vue.prototype.$socket = this.io;
Vue.prototype.$vueSocketIo = this;
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');