diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..8546d8f --- /dev/null +++ b/index.d.ts @@ -0,0 +1,59 @@ +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 { + (this: T, ...args: any[]): void +} + +interface Sockets { + [key: string]: socketHandler +} + +declare module 'vue/types/vue' { + interface Vue { + $socket: SocketIOClient.Socket, + sockets: { + subscribe(eventName: string, handler: socketHandler): void, + unsubscribe(eventName: string): void, + } + } +} + +declare module 'vue/types/options' { + interface ComponentOptions< + V extends Vue, + Data=DefaultData, + Methods=DefaultMethods, + Computed=DefaultComputed, + PropsDef=PropsDefinition, + Props=DefaultProps> { + sockets?: Sockets + } +} + +export interface VueSocketOptions { + debug?: boolean; + connection: string | SocketIOClient.Socket, + vuex?: { + store?: Store, + actionPrefix?: string, + mutationPrefix?: string, + options?: { + useConnectionNamespace?: boolean + } + } +} + +export default class VueSocketIO implements PluginObject { + constructor (options: VueSocketOptions); + install: PluginFunction +} diff --git a/package.json b/package.json index f486ca9..c0d0749 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "@babel/preset-env": "^7.1.0", "babel-loader": "^8.0.4", "cross-env": "^5.2.0", + "vue": "^2.6.10", + "vuex": "^3.1.1", "webpack": "^4.23.1", "webpack-cli": "^3.1.2" }